Class: AureEx::CrudResource
- Inherits:
-
Object
- Object
- AureEx::CrudResource
- Defined in:
- lib/aure_ex/client.rb
Overview
Recurso CRUD genérico (list/create/get/update/delete).
Direct Known Subclasses
Instance Method Summary collapse
- #create(payload, idempotency_key: nil) ⇒ Object
- #delete(id) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(http, base_path) ⇒ CrudResource
constructor
A new instance of CrudResource.
- #list(query = {}) ⇒ Object
- #update(id, payload) ⇒ Object
Constructor Details
#initialize(http, base_path) ⇒ CrudResource
Returns a new instance of CrudResource.
86 87 88 89 |
# File 'lib/aure_ex/client.rb', line 86 def initialize(http, base_path) @http = http @base_path = base_path end |
Instance Method Details
#create(payload, idempotency_key: nil) ⇒ Object
99 100 101 102 |
# File 'lib/aure_ex/client.rb', line 99 def create(payload, idempotency_key: nil) headers = idempotency_key ? { 'Idempotency-Key' => idempotency_key } : {} @http.request('Post', @base_path, body: payload, extra_headers: headers) end |
#delete(id) ⇒ Object
112 113 114 |
# File 'lib/aure_ex/client.rb', line 112 def delete(id) @http.request('Delete', "#{@base_path}/#{URI.encode_www_form_component(id)}") end |
#get(id) ⇒ Object
104 105 106 |
# File 'lib/aure_ex/client.rb', line 104 def get(id) @http.request('Get', "#{@base_path}/#{URI.encode_www_form_component(id)}") end |
#list(query = {}) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/aure_ex/client.rb', line 91 def list(query = {}) path = @base_path unless query.nil? || query.empty? path = "#{path}?#{URI.encode_www_form(query)}" end @http.request('Get', path) end |
#update(id, payload) ⇒ Object
108 109 110 |
# File 'lib/aure_ex/client.rb', line 108 def update(id, payload) @http.request('Put', "#{@base_path}/#{URI.encode_www_form_component(id)}", body: payload) end |