Class: LosantRest::Client

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

Overview

Losant API

User API for accessing Losant data

Built For Version 1.17.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



34
35
36
37
# File 'lib/losant_rest/client.rb', line 34

def initialize(options = {})
  self.auth_token = options.fetch(:auth_token, nil)
  self.url        = options.fetch(:url, "https://api.losant.com")
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



32
33
34
# File 'lib/losant_rest/client.rb', line 32

def auth_token
  @auth_token
end

#urlObject

Returns the value of attribute url.



32
33
34
# File 'lib/losant_rest/client.rb', line 32

def url
  @url
end

Instance Method Details

#applicationObject



39
40
41
# File 'lib/losant_rest/client.rb', line 39

def application
  @application ||= Application.new(self)
end

#application_api_tokenObject



43
44
45
# File 'lib/losant_rest/client.rb', line 43

def application_api_token
  @application_api_token ||= ApplicationApiToken.new(self)
end

#application_api_tokensObject



47
48
49
# File 'lib/losant_rest/client.rb', line 47

def application_api_tokens
  @application_api_tokens ||= ApplicationApiTokens.new(self)
end

#application_certificateObject



51
52
53
# File 'lib/losant_rest/client.rb', line 51

def application_certificate
  @application_certificate ||= ApplicationCertificate.new(self)
end

#application_certificate_authoritiesObject



55
56
57
# File 'lib/losant_rest/client.rb', line 55

def application_certificate_authorities
  @application_certificate_authorities ||= ApplicationCertificateAuthorities.new(self)
end

#application_certificate_authorityObject



59
60
61
# File 'lib/losant_rest/client.rb', line 59

def application_certificate_authority
  @application_certificate_authority ||= ApplicationCertificateAuthority.new(self)
end

#application_certificatesObject



63
64
65
# File 'lib/losant_rest/client.rb', line 63

def application_certificates
  @application_certificates ||= ApplicationCertificates.new(self)
end

#application_keyObject



67
68
69
# File 'lib/losant_rest/client.rb', line 67

def application_key
  @application_key ||= ApplicationKey.new(self)
end

#application_keysObject



71
72
73
# File 'lib/losant_rest/client.rb', line 71

def application_keys
  @application_keys ||= ApplicationKeys.new(self)
end

#application_templatesObject



75
76
77
# File 'lib/losant_rest/client.rb', line 75

def application_templates
  @application_templates ||= ApplicationTemplates.new(self)
end

#applicationsObject



79
80
81
# File 'lib/losant_rest/client.rb', line 79

def applications
  @applications ||= Applications.new(self)
end

#audit_logObject



83
84
85
# File 'lib/losant_rest/client.rb', line 83

def audit_log
  @audit_log ||= AuditLog.new(self)
end

#audit_logsObject



87
88
89
# File 'lib/losant_rest/client.rb', line 87

def audit_logs
  @audit_logs ||= AuditLogs.new(self)
end

#authObject



91
92
93
# File 'lib/losant_rest/client.rb', line 91

def auth
  @auth ||= Auth.new(self)
end

#dashboardObject



95
96
97
# File 'lib/losant_rest/client.rb', line 95

def dashboard
  @dashboard ||= Dashboard.new(self)
end

#dashboardsObject



99
100
101
# File 'lib/losant_rest/client.rb', line 99

def dashboards
  @dashboards ||= Dashboards.new(self)
end

#dataObject



103
104
105
# File 'lib/losant_rest/client.rb', line 103

def data
  @data ||= Data.new(self)
end

#data_tableObject



107
108
109
# File 'lib/losant_rest/client.rb', line 107

def data_table
  @data_table ||= DataTable.new(self)
end

#data_table_rowObject



111
112
113
# File 'lib/losant_rest/client.rb', line 111

def data_table_row
  @data_table_row ||= DataTableRow.new(self)
end

#data_table_rowsObject



115
116
117
# File 'lib/losant_rest/client.rb', line 115

def data_table_rows
  @data_table_rows ||= DataTableRows.new(self)
end

#data_tablesObject



119
120
121
# File 'lib/losant_rest/client.rb', line 119

def data_tables
  @data_tables ||= DataTables.new(self)
end

#deviceObject



123
124
125
# File 'lib/losant_rest/client.rb', line 123

def device
  @device ||= Device.new(self)
end

#device_recipeObject



127
128
129
# File 'lib/losant_rest/client.rb', line 127

def device_recipe
  @device_recipe ||= DeviceRecipe.new(self)
end

#device_recipesObject



131
132
133
# File 'lib/losant_rest/client.rb', line 131

def device_recipes
  @device_recipes ||= DeviceRecipes.new(self)
end

#devicesObject



135
136
137
# File 'lib/losant_rest/client.rb', line 135

def devices
  @devices ||= Devices.new(self)
end

#edge_deploymentsObject



139
140
141
# File 'lib/losant_rest/client.rb', line 139

def edge_deployments
  @edge_deployments ||= EdgeDeployments.new(self)
end

#eventObject



143
144
145
# File 'lib/losant_rest/client.rb', line 143

def event
  @event ||= Event.new(self)
end

#eventsObject



147
148
149
# File 'lib/losant_rest/client.rb', line 147

def events
  @events ||= Events.new(self)
end

#experienceObject



151
152
153
# File 'lib/losant_rest/client.rb', line 151

def experience
  @experience ||= Experience.new(self)
end

#experience_domainObject



155
156
157
# File 'lib/losant_rest/client.rb', line 155

def experience_domain
  @experience_domain ||= ExperienceDomain.new(self)
end

#experience_domainsObject



159
160
161
# File 'lib/losant_rest/client.rb', line 159

def experience_domains
  @experience_domains ||= ExperienceDomains.new(self)
end

#experience_endpointObject



163
164
165
# File 'lib/losant_rest/client.rb', line 163

def experience_endpoint
  @experience_endpoint ||= ExperienceEndpoint.new(self)
end

#experience_endpointsObject



167
168
169
# File 'lib/losant_rest/client.rb', line 167

def experience_endpoints
  @experience_endpoints ||= ExperienceEndpoints.new(self)
end

#experience_groupObject



171
172
173
# File 'lib/losant_rest/client.rb', line 171

def experience_group
  @experience_group ||= ExperienceGroup.new(self)
end

#experience_groupsObject



175
176
177
# File 'lib/losant_rest/client.rb', line 175

def experience_groups
  @experience_groups ||= ExperienceGroups.new(self)
end

#experience_slugObject



179
180
181
# File 'lib/losant_rest/client.rb', line 179

def experience_slug
  @experience_slug ||= ExperienceSlug.new(self)
end

#experience_slugsObject



183
184
185
# File 'lib/losant_rest/client.rb', line 183

def experience_slugs
  @experience_slugs ||= ExperienceSlugs.new(self)
end

#experience_userObject



187
188
189
# File 'lib/losant_rest/client.rb', line 187

def experience_user
  @experience_user ||= ExperienceUser.new(self)
end

#experience_usersObject



191
192
193
# File 'lib/losant_rest/client.rb', line 191

def experience_users
  @experience_users ||= ExperienceUsers.new(self)
end

#experience_versionObject



195
196
197
# File 'lib/losant_rest/client.rb', line 195

def experience_version
  @experience_version ||= ExperienceVersion.new(self)
end

#experience_versionsObject



199
200
201
# File 'lib/losant_rest/client.rb', line 199

def experience_versions
  @experience_versions ||= ExperienceVersions.new(self)
end

#experience_viewObject



203
204
205
# File 'lib/losant_rest/client.rb', line 203

def experience_view
  @experience_view ||= ExperienceView.new(self)
end

#experience_viewsObject



207
208
209
# File 'lib/losant_rest/client.rb', line 207

def experience_views
  @experience_views ||= ExperienceViews.new(self)
end

#fileObject



211
212
213
# File 'lib/losant_rest/client.rb', line 211

def file
  @file ||= File.new(self)
end

#filesObject



215
216
217
# File 'lib/losant_rest/client.rb', line 215

def files
  @files ||= Files.new(self)
end

#flowObject



219
220
221
# File 'lib/losant_rest/client.rb', line 219

def flow
  @flow ||= Flow.new(self)
end

#flow_versionObject



223
224
225
# File 'lib/losant_rest/client.rb', line 223

def flow_version
  @flow_version ||= FlowVersion.new(self)
end

#flow_versionsObject



227
228
229
# File 'lib/losant_rest/client.rb', line 227

def flow_versions
  @flow_versions ||= FlowVersions.new(self)
end

#flowsObject



231
232
233
# File 'lib/losant_rest/client.rb', line 231

def flows
  @flows ||= Flows.new(self)
end

#integrationObject



235
236
237
# File 'lib/losant_rest/client.rb', line 235

def integration
  @integration ||= Integration.new(self)
end

#integrationsObject



239
240
241
# File 'lib/losant_rest/client.rb', line 239

def integrations
  @integrations ||= Integrations.new(self)
end

#meObject



243
244
245
# File 'lib/losant_rest/client.rb', line 243

def me
  @me ||= Me.new(self)
end

#notebookObject



247
248
249
# File 'lib/losant_rest/client.rb', line 247

def notebook
  @notebook ||= Notebook.new(self)
end

#notebooksObject



251
252
253
# File 'lib/losant_rest/client.rb', line 251

def notebooks
  @notebooks ||= Notebooks.new(self)
end

#orgObject



255
256
257
# File 'lib/losant_rest/client.rb', line 255

def org
  @org ||= Org.new(self)
end

#org_invitesObject



259
260
261
# File 'lib/losant_rest/client.rb', line 259

def org_invites
  @org_invites ||= OrgInvites.new(self)
end

#orgsObject



263
264
265
# File 'lib/losant_rest/client.rb', line 263

def orgs
  @orgs ||= Orgs.new(self)
end

#request(options = {}) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/losant_rest/client.rb', line 275

def request(options = {})
  headers = options.fetch(:headers, {})
  method  = options.fetch(:method, :get)

  headers["Accept"]         = "application/json"
  headers["Content-Type"]   = "application/json"
  headers["Accept-Version"] = "^1.17.3"
  headers["Authorization"]  = "Bearer #{self.auth_token}" if self.auth_token
  path = self.url + options.fetch(:path, "")

  response = HTTParty.send(method, path,
    query: Utils.fix_query_arrays(options[:query]),
    body: options[:body] && options[:body].to_json(),
    headers: headers)

  result = response.parsed_response
  if response.code >= 400
    raise ResponseError.new(response.code, result)
  end

  result
end

#webhookObject



267
268
269
# File 'lib/losant_rest/client.rb', line 267

def webhook
  @webhook ||= Webhook.new(self)
end

#webhooksObject



271
272
273
# File 'lib/losant_rest/client.rb', line 271

def webhooks
  @webhooks ||= Webhooks.new(self)
end