class EasybillRestClient::GenericApi
Attributes
api_client[R]
Public Class Methods
new(api_client)
click to toggle source
# File lib/easybill_rest_client/generic_api.rb, line 5 def initialize(api_client) @api_client = api_client end
Public Instance Methods
build(params)
click to toggle source
# File lib/easybill_rest_client/generic_api.rb, line 33 def build(params) resource_class.new(params) end
create(entity)
click to toggle source
# 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)
click to toggle source
# File lib/easybill_rest_client/generic_api.rb, line 29 def delete(id) api_client.request(:delete, "/#{resource_name}/#{id}") end
find(id)
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# File lib/easybill_rest_client/generic_api.rb, line 17 def save(entity) entity.id ? update(entity) : create(entity) end
update(entity)
click to toggle source
# 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