Class: Payabli::Import::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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.

Examples:

client.import.import_bills(entry: "8cfec329267")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :entry (String)

Returns:



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: request_options[:base_url],
    method: "POST",
    path: "Import/billsForm/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    body: body,
    request_options: 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.

Examples:

client.import.import_customer(entry: "8cfec329267")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



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: request_options[:base_url],
    method: "POST",
    path: "Import/customersForm/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    body: body,
    request_options: 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.

Examples:

client.import.import_vendor(entry: "8cfec329267")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



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: request_options[:base_url],
    method: "POST",
    path: "Import/vendorsForm/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    body: body,
    request_options: 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