Class: JsonApiClient::Query::Requestor
- Inherits:
-
Object
- Object
- JsonApiClient::Query::Requestor
- Extended by:
- Forwardable
- Includes:
- Helpers::URI
- 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
Methods included from Helpers::URI
Constructor Details
#initialize(klass) ⇒ Requestor
Returns a new instance of Requestor.
7 8 9 |
# File 'lib/json_api_client/query/requestor.rb', line 7 def initialize(klass) @klass = klass end |
Instance Method Details
#create(record) ⇒ Object
expects a record
12 13 14 15 16 17 |
# File 'lib/json_api_client/query/requestor.rb', line 12 def create(record) request(:post, klass.path(record.path_attributes), { body: { data: record.as_json_api }, params: record.request_params.to_params }) end |
#custom(method_name, options, params) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/json_api_client/query/requestor.rb', line 40 def custom(method_name, , params) path = resource_path(params) params.delete(klass.primary_key) path = File.join(path, method_name.to_s) request_method = .fetch(:request_method, :get).to_sym query_params, body_params = [:get, :delete].include?(request_method) ? [params, nil] : [nil, params] request(request_method, path, params: query_params, body: body_params) end |
#destroy(record) ⇒ Object
32 33 34 |
# File 'lib/json_api_client/query/requestor.rb', line 32 def destroy(record) request(:delete, resource_path(record.path_attributes)) end |
#get(params = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/json_api_client/query/requestor.rb', line 26 def get(params = {}) path = resource_path(params) params.delete(klass.primary_key) request(:get, path, params: params) end |
#linked(path) ⇒ Object
36 37 38 |
# File 'lib/json_api_client/query/requestor.rb', line 36 def linked(path) request(:get, path) end |
#update(record) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/json_api_client/query/requestor.rb', line 19 def update(record) request(:patch, resource_path(record.path_attributes), { body: { data: record.as_json_api }, params: record.request_params.to_params }) end |