Class: JsonApiClient::Query::Requestor
- Inherits:
-
Object
- Object
- JsonApiClient::Query::Requestor
- Extended by:
- Forwardable
- Defined in:
- lib/json_api_client/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) ⇒ Requestor
constructor
A new instance of Requestor.
- #linked(path) ⇒ Object
- #update(record) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Requestor
Returns a new instance of Requestor.
6 7 8 |
# File 'lib/json_api_client/query/requestor.rb', line 6 def initialize(klass) @klass = klass end |
Instance Method Details
#create(record) ⇒ Object
expects a record
11 12 13 14 15 |
# File 'lib/json_api_client/query/requestor.rb', line 11 def create(record) request(:post, klass.path(record.attributes), { data: record.as_json_api }) end |
#custom(method_name, options, params) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/json_api_client/query/requestor.rb', line 37 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
29 30 31 |
# File 'lib/json_api_client/query/requestor.rb', line 29 def destroy(record) request(:delete, resource_path(record.attributes), {}) end |
#get(params = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/json_api_client/query/requestor.rb', line 23 def get(params = {}) path = resource_path(params) params.delete(klass.primary_key) request(:get, path, params) end |
#linked(path) ⇒ Object
33 34 35 |
# File 'lib/json_api_client/query/requestor.rb', line 33 def linked(path) request(:get, path, {}) end |
#update(record) ⇒ Object
17 18 19 20 21 |
# File 'lib/json_api_client/query/requestor.rb', line 17 def update(record) request(:patch, resource_path(record.attributes), { data: record.as_json_api }) end |