Class: Payabli::Import::Client
- Inherits:
-
Object
- Object
- Payabli::Import::Client
- Defined in:
- lib/payabli/import/client.rb
Instance Method Summary collapse
-
#import_bills(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of bills from a CSV file.
-
#import_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of customers from a CSV file.
-
#import_vendor(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of vendors from a CSV file.
- #initialize(client:) ⇒ void constructor
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/payabli/import/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#import_bills(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of bills from a CSV file. See the Import Guide for more help and an example file.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/payabli/import/client.rb', line 29 def import_bills(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) body = Internal::Multipart::FormData.new body.add_part(params[:file].to_form_data_part(name: "file")) if params[:file] headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::Multipart::Request.new( base_url: [:base_url], method: "POST", path: "Import/billsForm/#{URI.encode_uri_component(params[:entry].to_s)}", headers: headers, body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::PayabliApiResponseImport.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#import_customer(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of customers from a CSV file. See the Import Guide for more help and example files.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/payabli/import/client.rb', line 75 def import_customer(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) body = Internal::Multipart::FormData.new body.add_part(params[:file].to_form_data_part(name: "file")) if params[:file] headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::Multipart::Request.new( base_url: [:base_url], method: "POST", path: "Import/customersForm/#{URI.encode_uri_component(params[:entry].to_s)}", headers: headers, body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::PayabliApiResponseImport.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#import_vendor(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseImport
Import a list of vendors from a CSV file. See the Import Guide for more help and example files.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/payabli/import/client.rb', line 120 def import_vendor(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) body = Internal::Multipart::FormData.new body.add_part(params[:file].to_form_data_part(name: "file")) if params[:file] headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::Multipart::Request.new( base_url: [:base_url], method: "POST", path: "Import/vendorsForm/#{URI.encode_uri_component(params[:entry].to_s)}", headers: headers, body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::PayabliApiResponseImport.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |