Class: Recruitee::APIResource
- Inherits:
-
Object
- Object
- Recruitee::APIResource
show all
- Defined in:
- lib/recruitee/api_resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, resource_klass) ⇒ APIResource
Returns a new instance of APIResource.
7
8
9
10
11
12
13
14
|
# File 'lib/recruitee/api_resource.rb', line 7
def initialize(client, resource_klass)
if client.nil? || resource_klass.nil?
raise ArgumentError, 'client & resource class must be provided'
end
@client = client
@resource_klass = resource_klass
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5
6
7
|
# File 'lib/recruitee/api_resource.rb', line 5
def client
@client
end
|
#resource_klass ⇒ Object
Returns the value of attribute resource_klass.
5
6
7
|
# File 'lib/recruitee/api_resource.rb', line 5
def resource_klass
@resource_klass
end
|
Instance Method Details
#create(data = {}) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/recruitee/api_resource.rb', line 16
def create(data = {})
body = namespaced_body(data)
payload = request(:post, resource_url, body: body)
initialize_from(payload[resource_name])
end
|
#destroy(id, params = {}) ⇒ Object
23
24
25
26
27
|
# File 'lib/recruitee/api_resource.rb', line 23
def destroy(id, params = {})
payload = request(:delete, "#{resource_url}/#{id}", params: params)
initialize_from(payload[resource_name])
end
|
#find(id, params = {}) ⇒ Object
29
30
31
32
33
|
# File 'lib/recruitee/api_resource.rb', line 29
def find(id, params = {})
payload = request(:get, "#{resource_url}/#{id}", params: params)
initialize_from(payload[resource_name])
end
|
#list(params = {}) ⇒ Object
35
36
37
38
39
|
# File 'lib/recruitee/api_resource.rb', line 35
def list(params = {})
payload = request(:get, resource_url, params: params)
payload["#{resource_name}s"].map { |props| initialize_from(props) }
end
|
#resource_name ⇒ Object
48
49
50
|
# File 'lib/recruitee/api_resource.rb', line 48
def resource_name
Util.underscore(resource_klass.name.split('::').last)
end
|
#resource_url ⇒ Object
52
53
54
|
# File 'lib/recruitee/api_resource.rb', line 52
def resource_url
"/#{resource_name}s"
end
|
#update(id, data = {}) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/recruitee/api_resource.rb', line 41
def update(id, data = {})
body = namespaced_body(data)
payload = request(:patch, "#{resource_url}/#{id}", body: body)
initialize_from(payload[resource_name])
end
|