Class: LosantRest::Client
- Inherits:
-
Object
- Object
- LosantRest::Client
- 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
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #access_token ⇒ Object
- #access_tokens ⇒ Object
- #application ⇒ Object
- #application_key ⇒ Object
- #application_keys ⇒ Object
- #applications ⇒ Object
- #auth ⇒ Object
- #dashboard ⇒ Object
- #dashboards ⇒ Object
- #data ⇒ Object
- #device ⇒ Object
- #device_recipe ⇒ Object
- #device_recipes ⇒ Object
- #devices ⇒ Object
- #event ⇒ Object
- #events ⇒ Object
- #flow ⇒ Object
- #flows ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #org ⇒ Object
- #orgs ⇒ Object
- #request(options = {}) ⇒ Object
- #solution ⇒ Object
- #solution_user ⇒ Object
- #solution_users ⇒ Object
- #solutions ⇒ Object
- #webhook ⇒ Object
- #webhooks ⇒ Object
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( = {}) self.auth_token = .fetch(:auth_token, nil) self.url = .fetch(:url, "https://api.losant.com") end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
10 11 12 |
# File 'lib/losant_rest/client.rb', line 10 def auth_token @auth_token end |
#url ⇒ Object
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_token ⇒ Object
17 18 19 |
# File 'lib/losant_rest/client.rb', line 17 def access_token @access_token ||= AccessToken.new(self) end |
#access_tokens ⇒ Object
21 22 23 |
# File 'lib/losant_rest/client.rb', line 21 def access_tokens @access_tokens ||= AccessTokens.new(self) end |
#application ⇒ Object
25 26 27 |
# File 'lib/losant_rest/client.rb', line 25 def application @application ||= Application.new(self) end |
#application_key ⇒ Object
29 30 31 |
# File 'lib/losant_rest/client.rb', line 29 def application_key @application_key ||= ApplicationKey.new(self) end |
#application_keys ⇒ Object
33 34 35 |
# File 'lib/losant_rest/client.rb', line 33 def application_keys @application_keys ||= ApplicationKeys.new(self) end |
#applications ⇒ Object
37 38 39 |
# File 'lib/losant_rest/client.rb', line 37 def applications @applications ||= Applications.new(self) end |
#auth ⇒ Object
41 42 43 |
# File 'lib/losant_rest/client.rb', line 41 def auth @auth ||= Auth.new(self) end |
#dashboard ⇒ Object
45 46 47 |
# File 'lib/losant_rest/client.rb', line 45 def dashboard @dashboard ||= Dashboard.new(self) end |
#dashboards ⇒ Object
49 50 51 |
# File 'lib/losant_rest/client.rb', line 49 def dashboards @dashboards ||= Dashboards.new(self) end |
#data ⇒ Object
53 54 55 |
# File 'lib/losant_rest/client.rb', line 53 def data @data ||= Data.new(self) end |
#device ⇒ Object
57 58 59 |
# File 'lib/losant_rest/client.rb', line 57 def device @device ||= Device.new(self) end |
#device_recipe ⇒ Object
61 62 63 |
# File 'lib/losant_rest/client.rb', line 61 def device_recipe @device_recipe ||= DeviceRecipe.new(self) end |
#device_recipes ⇒ Object
65 66 67 |
# File 'lib/losant_rest/client.rb', line 65 def device_recipes @device_recipes ||= DeviceRecipes.new(self) end |
#devices ⇒ Object
69 70 71 |
# File 'lib/losant_rest/client.rb', line 69 def devices @devices ||= Devices.new(self) end |
#event ⇒ Object
73 74 75 |
# File 'lib/losant_rest/client.rb', line 73 def event @event ||= Event.new(self) end |
#events ⇒ Object
77 78 79 |
# File 'lib/losant_rest/client.rb', line 77 def events @events ||= Events.new(self) end |
#flow ⇒ Object
81 82 83 |
# File 'lib/losant_rest/client.rb', line 81 def flow @flow ||= Flow.new(self) end |
#flows ⇒ Object
85 86 87 |
# File 'lib/losant_rest/client.rb', line 85 def flows @flows ||= Flows.new(self) end |
#org ⇒ Object
93 94 95 |
# File 'lib/losant_rest/client.rb', line 93 def org @org ||= Org.new(self) end |
#orgs ⇒ Object
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( = {}) headers = .fetch(:headers, {}) method = .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 + .fetch(:path, "") response = HTTParty.send(method, path, query: Utils.fix_query_arrays([:query]), body: [:body] && [:body].to_json(), headers: headers) result = response.parsed_response if response.code >= 400 raise ResponseError.new(response.code, result) end result end |
#solution ⇒ Object
101 102 103 |
# File 'lib/losant_rest/client.rb', line 101 def solution @solution ||= Solution.new(self) end |
#solution_user ⇒ Object
105 106 107 |
# File 'lib/losant_rest/client.rb', line 105 def solution_user @solution_user ||= SolutionUser.new(self) end |
#solution_users ⇒ Object
109 110 111 |
# File 'lib/losant_rest/client.rb', line 109 def solution_users @solution_users ||= SolutionUsers.new(self) end |
#solutions ⇒ Object
113 114 115 |
# File 'lib/losant_rest/client.rb', line 113 def solutions @solutions ||= Solutions.new(self) end |