Class: JSONAPI::Consumer::Query::Requestor
- Inherits:
-
Object
- Object
- JSONAPI::Consumer::Query::Requestor
- Extended by:
- Forwardable
- Includes:
- Helpers::URI
- Defined in:
- lib/jsonapi/consumer/query/requestor.rb
Instance Method Summary collapse
-
#create(record) ⇒ Object
expects a record.
- #custom(method_name, options, params) ⇒ Object
- #destroy(record) ⇒ Object
- #get(params = {}) ⇒ Object
-
#initialize(klass, path = nil) ⇒ Requestor
constructor
A new instance of Requestor.
- #linked(path) ⇒ Object
- #update(record) ⇒ Object
Methods included from Helpers::URI
Constructor Details
#initialize(klass, path = nil) ⇒ Requestor
Returns a new instance of Requestor.
7 8 9 10 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 7 def initialize(klass, path = nil) @klass = klass @path = path end |
Instance Method Details
#create(record) ⇒ Object
expects a record
13 14 15 16 17 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 13 def create(record) request(:post, klass.path(record.attributes), { data: record.as_json_api }) end |
#custom(method_name, options, params) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 39 def custom(method_name, , params) path = resource_path(params) params.delete(klass.primary_key) path = File.join(path, method_name.to_s) request(.fetch(:request_method, :get), path, params) end |
#destroy(record) ⇒ Object
31 32 33 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 31 def destroy(record) request(:delete, resource_path(record.attributes), {}) end |
#get(params = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 25 def get(params = {}) path = resource_path(params) params.delete(klass.primary_key) request(:get, path, params) end |
#linked(path) ⇒ Object
35 36 37 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 35 def linked(path) request(:get, path, {}) end |
#update(record) ⇒ Object
19 20 21 22 23 |
# File 'lib/jsonapi/consumer/query/requestor.rb', line 19 def update(record) request(:patch, resource_path(record.attributes), { data: record.as_json_api }) end |