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.5.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
# File 'lib/losant_rest/client.rb', line 12

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.



10
11
12
# File 'lib/losant_rest/client.rb', line 10

def auth_token
  @auth_token
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/losant_rest/client.rb', line 10

def url
  @url
end

Instance Method Details

#access_tokenObject



17
18
19
# File 'lib/losant_rest/client.rb', line 17

def access_token
  @access_token ||= AccessToken.new(self)
end

#access_tokensObject



21
22
23
# File 'lib/losant_rest/client.rb', line 21

def access_tokens
  @access_tokens ||= AccessTokens.new(self)
end

#applicationObject



25
26
27
# File 'lib/losant_rest/client.rb', line 25

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

#application_keyObject



29
30
31
# File 'lib/losant_rest/client.rb', line 29

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

#application_keysObject



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

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

#applicationsObject



37
38
39
# File 'lib/losant_rest/client.rb', line 37

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

#authObject



41
42
43
# File 'lib/losant_rest/client.rb', line 41

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

#dashboardObject



45
46
47
# File 'lib/losant_rest/client.rb', line 45

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

#dashboardsObject



49
50
51
# File 'lib/losant_rest/client.rb', line 49

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

#dataObject



53
54
55
# File 'lib/losant_rest/client.rb', line 53

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

#deviceObject



57
58
59
# File 'lib/losant_rest/client.rb', line 57

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

#device_recipeObject



61
62
63
# File 'lib/losant_rest/client.rb', line 61

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

#device_recipesObject



65
66
67
# File 'lib/losant_rest/client.rb', line 65

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

#devicesObject



69
70
71
# File 'lib/losant_rest/client.rb', line 69

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

#eventObject



73
74
75
# File 'lib/losant_rest/client.rb', line 73

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

#eventsObject



77
78
79
# File 'lib/losant_rest/client.rb', line 77

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

#flowObject



81
82
83
# File 'lib/losant_rest/client.rb', line 81

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

#flowsObject



85
86
87
# File 'lib/losant_rest/client.rb', line 85

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

#meObject



89
90
91
# File 'lib/losant_rest/client.rb', line 89

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

#orgObject



93
94
95
# File 'lib/losant_rest/client.rb', line 93

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

#orgsObject



97
98
99
# File 'lib/losant_rest/client.rb', line 97

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

#request(options = {}) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/losant_rest/client.rb', line 125

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.5.1"
  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

#solutionObject



101
102
103
# File 'lib/losant_rest/client.rb', line 101

def solution
  @solution ||= Solution.new(self)
end

#solution_userObject



105
106
107
# File 'lib/losant_rest/client.rb', line 105

def solution_user
  @solution_user ||= SolutionUser.new(self)
end

#solution_usersObject



109
110
111
# File 'lib/losant_rest/client.rb', line 109

def solution_users
  @solution_users ||= SolutionUsers.new(self)
end

#solutionsObject



113
114
115
# File 'lib/losant_rest/client.rb', line 113

def solutions
  @solutions ||= Solutions.new(self)
end

#webhookObject



117
118
119
# File 'lib/losant_rest/client.rb', line 117

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

#webhooksObject



121
122
123
# File 'lib/losant_rest/client.rb', line 121

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