Class: Samsara::AsyncContactsClient
- Inherits:
-
Object
- Object
- Samsara::AsyncContactsClient
- Defined in:
- lib/samsara_api/contacts/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create(email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) ⇒ Object
api.contacts.create.
-
#delete(id:, request_options: nil) ⇒ Object
api.contacts.delete(id: “id”).
-
#get(id:, request_options: nil) ⇒ Object
api.contacts.get(id: “id”).
- #initialize(request_client:) ⇒ Samsara::AsyncContactsClient constructor
-
#list(limit: nil, after: nil, request_options: nil) ⇒ Object
api.contacts.list.
-
#update(id:, email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) ⇒ Object
api.contacts.update(id: “id”).
Constructor Details
#initialize(request_client:) ⇒ Samsara::AsyncContactsClient
243 244 245 |
# File 'lib/samsara_api/contacts/client.rb', line 243 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Samsara::AsyncRequestClient (readonly)
238 239 240 |
# File 'lib/samsara_api/contacts/client.rb', line 238 def request_client @request_client end |
Instance Method Details
#create(email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) ⇒ Object
api.contacts.create
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/samsara_api/contacts/client.rb', line 316 def create(email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) Async do 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 || {}), email: email, firstName: first_name, lastName: last_name, phone: phone }.compact req.url "#{@request_client.get_url(request_options: )}/contacts" end Samsara::Types::ContactResponse.from_json(json_object: response.body) end end |
#delete(id:, request_options: nil) ⇒ Object
api.contacts.delete(id: “id”)
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/samsara_api/contacts/client.rb', line 400 def delete(id:, request_options: nil) Async do 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: )}/contacts/#{id}" end parsed_json = JSON.parse(response.body) parsed_json end end |
#get(id:, request_options: nil) ⇒ Object
api.contacts.get(id: “id”)
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/samsara_api/contacts/client.rb', line 357 def get(id:, request_options: nil) Async do 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: )}/contacts/#{id}" end Samsara::Types::ContactResponse.from_json(json_object: response.body) end end |
#list(limit: nil, after: nil, request_options: nil) ⇒ Object
api.contacts.list
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/samsara_api/contacts/client.rb', line 272 def list(limit: nil, after: nil, request_options: nil) Async do 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 req.params = { **(&.additional_query_parameters || {}), "limit": limit, "after": after }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts" end Samsara::Types::ListContactsResponse.from_json(json_object: response.body) end end |
#update(id:, email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) ⇒ Object
api.contacts.update(id: “id”)
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/samsara_api/contacts/client.rb', line 448 def update(id:, email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) Async do response = @request_client.conn.patch 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 || {}), email: email, firstName: first_name, lastName: last_name, phone: phone }.compact req.url "#{@request_client.get_url(request_options: )}/contacts/#{id}" end Samsara::Types::ContactResponse.from_json(json_object: response.body) end end |