Class: Samsara::ContactsClient
- Inherits:
-
Object
- Object
- Samsara::ContactsClient
- 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::ContactsClient 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::ContactsClient
21 22 23 |
# File 'lib/samsara_api/contacts/client.rb', line 21 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Samsara::RequestClient (readonly)
16 17 18 |
# File 'lib/samsara_api/contacts/client.rb', line 16 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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/samsara_api/contacts/client.rb', line 92 def create(email: nil, first_name: nil, last_name: nil, phone: 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 || {}), 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 |
#delete(id:, request_options: nil) ⇒ Object
api.contacts.delete(id: “id”)
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/samsara_api/contacts/client.rb', line 172 def delete(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: )}/contacts/#{id}" end parsed_json = JSON.parse(response.body) parsed_json end |
#get(id:, request_options: nil) ⇒ Object
api.contacts.get(id: “id”)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/samsara_api/contacts/client.rb', line 131 def get(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: )}/contacts/#{id}" end Samsara::Types::ContactResponse.from_json(json_object: response.body) end |
#list(limit: nil, after: nil, request_options: nil) ⇒ Object
api.contacts.list
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/samsara_api/contacts/client.rb', line 50 def list(limit: nil, after: nil, 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 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 |
#update(id:, email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) ⇒ Object
api.contacts.update(id: “id”)
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/samsara_api/contacts/client.rb', line 218 def update(id:, email: nil, first_name: nil, last_name: nil, phone: nil, request_options: nil) 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 |