Class: AureEx::CrudResource

Inherits:
Object
  • Object
show all
Defined in:
lib/aure_ex/client.rb

Overview

Recurso CRUD genérico (list/create/get/update/delete).

Direct Known Subclasses

Conversions

Instance Method Summary collapse

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