Class: Paid::CustomersClient
- Inherits:
-
Object
- Object
- Paid::CustomersClient
- Defined in:
- lib/paid_ruby/customers/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create(name:, external_id: nil, phone: nil, employee_count: nil, annual_revenue: nil, tax_exempt_status: nil, creation_source: nil, website: nil, billing_address: nil, request_options: nil) ⇒ Object
api.customers.create(name: “Acme, Inc.”, external_id: “acme-inc”).
-
#delete(customer_id:, request_options: nil) ⇒ Object
api.customers.delete(customer_id: “customerId”).
-
#delete_by_external_id(external_id:, request_options: nil) ⇒ Object
api.customers.delete_by_external_id(external_id: “externalId”).
-
#get(customer_id:, request_options: nil) ⇒ Object
api.customers.get(customer_id: “customerId”).
-
#get_by_external_id(external_id:, request_options: nil) ⇒ Object
api.customers.get_by_external_id(external_id: “externalId”).
- #initialize(request_client:) ⇒ Paid::CustomersClient constructor
-
#list(request_options: nil) ⇒ Object
api.customers.list.
-
#update(customer_id:, request:, request_options: nil) ⇒ Object
api.customers.update(customer_id: “customerId”, request: { name: “Acme, Inc. (Updated)”, phone: “123-456-7890”, employee_count: 101, annual_revenue: 1000001 }).
-
#update_by_external_id(external_id:, request:, request_options: nil) ⇒ Object
api.customers.update_by_external_id(external_id: “externalId”, request: { }).
Constructor Details
#initialize(request_client:) ⇒ Paid::CustomersClient
27 28 29 |
# File 'lib/paid_ruby/customers/client.rb', line 27 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Paid::RequestClient (readonly)
22 23 24 |
# File 'lib/paid_ruby/customers/client.rb', line 22 def request_client @request_client end |
Instance Method Details
#create(name:, external_id: nil, phone: nil, employee_count: nil, annual_revenue: nil, tax_exempt_status: nil, creation_source: nil, website: nil, billing_address: nil, request_options: nil) ⇒ Object
api.customers.create(name: “Acme, Inc.”, external_id: “acme-inc”)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/paid_ruby/customers/client.rb', line 86 def create(name:, external_id: nil, phone: nil, employee_count: nil, annual_revenue: nil, tax_exempt_status: nil, creation_source: nil, website: nil, billing_address: nil, request_options: nil) response = @request_client.conn.post do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), name: name, externalId: external_id, phone: phone, employeeCount: employee_count, annualRevenue: annual_revenue, taxExemptStatus: tax_exempt_status, creationSource: creation_source, website: website, billingAddress: billing_address }.compact req.url "#{@request_client.get_url(request_options: request_options)}/customers" end Paid::Customer.from_json(json_object: response.body) end |
#delete(customer_id:, request_options: nil) ⇒ Object
api.customers.delete(customer_id: “customerId”)
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/paid_ruby/customers/client.rb', line 185 def delete(customer_id:, request_options: nil) response = @request_client.conn.delete do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: request_options)}/customers/#{customer_id}" end end |
#delete_by_external_id(external_id:, request_options: nil) ⇒ Object
api.customers.delete_by_external_id(external_id: “externalId”)
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/paid_ruby/customers/client.rb', line 285 def delete_by_external_id(external_id:, request_options: nil) response = @request_client.conn.delete do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: request_options)}/customers/external/#{external_id}" end end |
#get(customer_id:, request_options: nil) ⇒ Object
api.customers.get(customer_id: “customerId”)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/paid_ruby/customers/client.rb', line 113 def get(customer_id:, request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: request_options)}/customers/#{customer_id}" end Paid::Customer.from_json(json_object: response.body) end |
#get_by_external_id(external_id:, request_options: nil) ⇒ Object
api.customers.get_by_external_id(external_id: “externalId”)
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/paid_ruby/customers/client.rb', line 213 def get_by_external_id(external_id:, request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: request_options)}/customers/external/#{external_id}" end Paid::Customer.from_json(json_object: response.body) end |
#list(request_options: nil) ⇒ Object
api.customers.list
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/paid_ruby/customers/client.rb', line 39 def list(request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: request_options)}/customers" end parsed_json = JSON.parse(response.body) parsed_json&.map do | item | item = item.to_json Paid::Customer.from_json(json_object: item) end end |
#update(customer_id:, request:, request_options: nil) ⇒ Object
api.customers.update(customer_id: “customerId”, request: { name: “Acme, Inc. (Updated)”, phone: “123-456-7890”, employee_count: 101, annual_revenue: 1000001 })
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/paid_ruby/customers/client.rb', line 158 def update(customer_id:, request:, request_options: nil) response = @request_client.conn.put do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(request_options: request_options)}/customers/#{customer_id}" end Paid::Customer.from_json(json_object: response.body) end |
#update_by_external_id(external_id:, request:, request_options: nil) ⇒ Object
api.customers.update_by_external_id(external_id: “externalId”, request: { })
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/paid_ruby/customers/client.rb', line 258 def update_by_external_id(external_id:, request:, request_options: nil) response = @request_client.conn.put do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(request_options: request_options)}/customers/external/#{external_id}" end Paid::Customer.from_json(json_object: response.body) end |