Class: EasybillRestClient::GenericApi
- Inherits:
-
Object
- Object
- EasybillRestClient::GenericApi
show all
- Defined in:
- lib/easybill_rest_client/generic_api.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_client) ⇒ GenericApi
Returns a new instance of GenericApi.
5
6
7
|
# File 'lib/easybill_rest_client/generic_api.rb', line 5
def initialize(api_client)
@api_client = api_client
end
|
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
37
38
39
|
# File 'lib/easybill_rest_client/generic_api.rb', line 37
def api_client
@api_client
end
|
Instance Method Details
#build(params) ⇒ Object
33
34
35
|
# File 'lib/easybill_rest_client/generic_api.rb', line 33
def build(params)
resource_class.new(params)
end
|
#create(entity) ⇒ Object
21
22
23
|
# File 'lib/easybill_rest_client/generic_api.rb', line 21
def create(entity)
build(api_client.request(:post, "/#{resource_name}", entity.attributes))
end
|
#delete(id) ⇒ Object
29
30
31
|
# File 'lib/easybill_rest_client/generic_api.rb', line 29
def delete(id)
api_client.request(:delete, "/#{resource_name}/#{id}")
end
|
#find(id) ⇒ Object
9
10
11
|
# File 'lib/easybill_rest_client/generic_api.rb', line 9
def find(id)
build(api_client.request(:get, "/#{resource_name}/#{id}"))
end
|
#find_all(params = {}) ⇒ Object
13
14
15
|
# File 'lib/easybill_rest_client/generic_api.rb', line 13
def find_all(params = {})
api_client.request_collection(:get, "/#{resource_name}", params).map { |d| build(d) }
end
|
#save(entity) ⇒ Object
17
18
19
|
# File 'lib/easybill_rest_client/generic_api.rb', line 17
def save(entity)
entity.id ? update(entity) : create(entity)
end
|
#update(entity) ⇒ Object
25
26
27
|
# File 'lib/easybill_rest_client/generic_api.rb', line 25
def update(entity)
build(api_client.request(:put, "/#{resource_name}/#{entity.id}", entity.attributes))
end
|