Class: Wajub::CrudResource
Instance Attribute Summary
Attributes inherited from BaseClient
#api_key, #base_url, #idempotency_key_prefix, #last_request, #transport
Instance Method Summary
collapse
-
#create(params, options = nil) ⇒ Object
-
#delete(id, options = nil) ⇒ Object
-
#initialize(api_key, base_url, path, singular, plural, idempotency_key_prefix = 'wajub', transport: nil) ⇒ CrudResource
constructor
A new instance of CrudResource.
-
#list(params = nil) ⇒ Object
-
#retrieve(id) ⇒ Object
-
#update(id, params, options = nil) ⇒ Object
Methods inherited from BaseClient
#get, #post, #put, #request
Constructor Details
#initialize(api_key, base_url, path, singular, plural, idempotency_key_prefix = 'wajub', transport: nil) ⇒ CrudResource
Returns a new instance of CrudResource.
11
12
13
14
15
16
|
# File 'lib/wajub/resources.rb', line 11
def initialize(api_key, base_url, path, singular, plural, idempotency_key_prefix = 'wajub', transport: nil)
super(api_key, base_url, idempotency_key_prefix, transport: transport)
@path = path
@singular = singular
@plural = plural
end
|
Instance Method Details
#create(params, options = nil) ⇒ Object
18
19
20
|
# File 'lib/wajub/resources.rb', line 18
def create(params, options = nil)
HttpUtils.pick_resource(post("/#{@path}", params, options), @singular)
end
|
#delete(id, options = nil) ⇒ Object
34
35
36
|
# File 'lib/wajub/resources.rb', line 34
def delete(id, options = nil)
request('DELETE', "/#{@path}/#{URI.encode_www_form_component(id)}", options: options)
end
|
#list(params = nil) ⇒ Object
26
27
28
|
# File 'lib/wajub/resources.rb', line 26
def list(params = nil)
PagedResult.create(self, "/#{@path}", @plural, params)
end
|
#retrieve(id) ⇒ Object
22
23
24
|
# File 'lib/wajub/resources.rb', line 22
def retrieve(id)
HttpUtils.pick_resource(get("/#{@path}/#{URI.encode_www_form_component(id)}"), @singular)
end
|
#update(id, params, options = nil) ⇒ Object
30
31
32
|
# File 'lib/wajub/resources.rb', line 30
def update(id, params, options = nil)
HttpUtils.pick_resource(put("/#{@path}/#{URI.encode_www_form_component(id)}", params, options), @singular)
end
|