Class: Xhash::General
Class Method Summary collapse
- .get_customer(customer_id:) ⇒ Object
- .store_data(*user_body) ⇒ Object
- .store_file(customer_id:, document_type:, document:) ⇒ Object
Methods inherited from ApiClient
api_base, api_base=, api_key, api_key=, config, timeout, timeout=
Methods included from JsonApi
Class Method Details
.get_customer(customer_id:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xhash/general.rb', line 21 def self.get_customer(customer_id:) url = "get-customer/#{customer_id}" response = api_get(url: url) payload = response[:payload] if payload.nil? raise Xhash::MissingRequiredFieldError.new( { message: Xhash::Formatters.(response), response: response } ) end Xhash::Customer.new(*payload.values_at(*Xhash::Customer.members)) end |
.store_data(*user_body) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/xhash/general.rb', line 3 def self.store_data(*user_body) url = 'store-data' body = Hash[*user_body] response = api_post(url: url, body: body) unless response[:id] raise Xhash::MissingRequiredFieldError.new( { message: Xhash::Formatters.(response), response: response } ) end Xhash::Customer.new(*response.values_at(*Xhash::Customer.members)) end |
.store_file(customer_id:, document_type:, document:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xhash/general.rb', line 39 def self.store_file(customer_id:, document_type:, document:) url = 'store-file' headers = { 'boundary' => '---011000010111000001101001' } body = { 'customer_id' => customer_id, 'document_type' => document_type, 'document' => document } response = api_post_multipart(url: url, body: body, headers: headers) unless response == 'Image stored' error = JSON.parse(response, symbolize_names: true) raise Xhash::MissingRequiredFieldError.new( { message: Xhash::Formatters.(error), response: error } ) end response end |