Module: JsonApiClient::Helpers::CustomEndpoints::ClassMethods
- Defined in:
- lib/json_api_client/helpers/custom_endpoints.rb
Instance Method Summary collapse
- #collection_endpoint(name, options = {}) ⇒ Object
- #custom_endpoint(name, options = {}) ⇒ Object
- #member_endpoint(name, options = {}) ⇒ Object
Instance Method Details
#collection_endpoint(name, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/json_api_client/helpers/custom_endpoints.rb', line 15 def collection_endpoint(name, = {}) = class << self self end .instance_eval do define_method(name) do |*params| input = { name: name, params: request_params = params.first || {} }.merge() run_request(Query::Custom.new(self, input)) end end end |
#custom_endpoint(name, options = {}) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/json_api_client/helpers/custom_endpoints.rb', line 7 def custom_endpoint(name, = {}) if :collection == .delete(:on) collection_endpoint(name, ) else member_endpoint(name, ) end end |
#member_endpoint(name, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/json_api_client/helpers/custom_endpoints.rb', line 30 def member_endpoint(name, = {}) define_method name do |*params| request_params = params.first || {} request_params[self.class.primary_key] = attributes.fetch(primary_key) input = { name: name, params: request_params }.merge() run_request(Query::Custom.new(self.class, input)) end end |