Class: JsonApiClient::Query::Requestor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::URI
Defined in:
lib/json_api_client/query/requestor.rb

Instance Method Summary collapse

Methods included from Helpers::URI

#encode_part

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
# File 'lib/json_api_client/query/requestor.rb', line 12

def create(record)
  request(:post, klass.path(record.attributes), {
    data: record.as_json_api
  })
end

#custom(method_name, options, params) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/json_api_client/query/requestor.rb', line 38

def custom(method_name, options, params)
  path = resource_path(params)
  params.delete(klass.primary_key)
  path = File.join(path, method_name.to_s)

  request(options.fetch(:request_method, :get), path, params)
end

#destroy(record) ⇒ Object



30
31
32
# File 'lib/json_api_client/query/requestor.rb', line 30

def destroy(record)
  request(:delete, resource_path(record.attributes), {})
end

#get(params = {}) ⇒ Object



24
25
26
27
28
# File 'lib/json_api_client/query/requestor.rb', line 24

def get(params = {})
  path = resource_path(params)
  params.delete(klass.primary_key)
  request(:get, path, params)
end

#linked(path) ⇒ Object



34
35
36
# File 'lib/json_api_client/query/requestor.rb', line 34

def linked(path)
  request(:get, path, {})
end

#update(record) ⇒ Object



18
19
20
21
22
# File 'lib/json_api_client/query/requestor.rb', line 18

def update(record)
  request(:patch, resource_path(record.attributes), {
    data: record.as_json_api
  })
end