losant_rest 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rbenv-version +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE +21 -0
  7. data/README.md +237 -0
  8. data/Rakefile +12 -0
  9. data/docs/_schemas.md +6348 -0
  10. data/docs/accessToken.md +107 -0
  11. data/docs/accessTokens.md +68 -0
  12. data/docs/application.md +107 -0
  13. data/docs/applicationKey.md +115 -0
  14. data/docs/applicationKeys.md +81 -0
  15. data/docs/applications.md +76 -0
  16. data/docs/auth.md +104 -0
  17. data/docs/dashboard.md +107 -0
  18. data/docs/dashboards.md +76 -0
  19. data/docs/data.md +78 -0
  20. data/docs/device.md +300 -0
  21. data/docs/deviceRecipe.md +152 -0
  22. data/docs/deviceRecipes.md +81 -0
  23. data/docs/devices.md +117 -0
  24. data/docs/event.md +115 -0
  25. data/docs/events.md +153 -0
  26. data/docs/flow.md +261 -0
  27. data/docs/flows.md +81 -0
  28. data/docs/me.md +312 -0
  29. data/docs/org.md +279 -0
  30. data/docs/orgs.md +75 -0
  31. data/docs/webhook.md +115 -0
  32. data/docs/webhooks.md +81 -0
  33. data/examples/auth.rb +32 -0
  34. data/examples/list_devices.rb +45 -0
  35. data/lib/losant_rest/access_token.rb +122 -0
  36. data/lib/losant_rest/access_tokens.rb +80 -0
  37. data/lib/losant_rest/application.rb +122 -0
  38. data/lib/losant_rest/application_key.rb +128 -0
  39. data/lib/losant_rest/application_keys.rb +98 -0
  40. data/lib/losant_rest/applications.rb +94 -0
  41. data/lib/losant_rest/auth.rb +122 -0
  42. data/lib/losant_rest/client.rb +132 -0
  43. data/lib/losant_rest/dashboard.rb +122 -0
  44. data/lib/losant_rest/dashboards.rb +94 -0
  45. data/lib/losant_rest/data.rb +89 -0
  46. data/lib/losant_rest/device.rb +336 -0
  47. data/lib/losant_rest/device_recipe.rb +169 -0
  48. data/lib/losant_rest/device_recipes.rb +98 -0
  49. data/lib/losant_rest/devices.rb +139 -0
  50. data/lib/losant_rest/error.rb +12 -0
  51. data/lib/losant_rest/event.rb +128 -0
  52. data/lib/losant_rest/events.rb +183 -0
  53. data/lib/losant_rest/flow.rb +290 -0
  54. data/lib/losant_rest/flows.rb +98 -0
  55. data/lib/losant_rest/me.rb +362 -0
  56. data/lib/losant_rest/org.rb +314 -0
  57. data/lib/losant_rest/orgs.rb +92 -0
  58. data/lib/losant_rest/utils.rb +22 -0
  59. data/lib/losant_rest/version.rb +3 -0
  60. data/lib/losant_rest/webhook.rb +128 -0
  61. data/lib/losant_rest/webhooks.rb +98 -0
  62. data/lib/losant_rest.rb +43 -0
  63. data/losant_rest.gemspec +25 -0
  64. data/schemas/accessToken.json +52 -0
  65. data/schemas/accessTokenPatch.json +19 -0
  66. data/schemas/accessTokenPost.json +32 -0
  67. data/schemas/accessTokens.json +65 -0
  68. data/schemas/application.json +65 -0
  69. data/schemas/applicationKey.json +68 -0
  70. data/schemas/applicationKeyPatch.json +18 -0
  71. data/schemas/applicationKeyPost.json +36 -0
  72. data/schemas/applicationKeys.json +110 -0
  73. data/schemas/applicationPatch.json +16 -0
  74. data/schemas/applicationPost.json +23 -0
  75. data/schemas/applications.json +103 -0
  76. data/schemas/authedDevice.json +34 -0
  77. data/schemas/authedUser.json +18 -0
  78. data/schemas/dashboard.json +95 -0
  79. data/schemas/dashboardPatch.json +69 -0
  80. data/schemas/dashboardPost.json +76 -0
  81. data/schemas/dashboards.json +133 -0
  82. data/schemas/device.json +113 -0
  83. data/schemas/deviceCommand.json +20 -0
  84. data/schemas/deviceCommands.json +25 -0
  85. data/schemas/deviceCredentials.json +22 -0
  86. data/schemas/deviceLog.json +28 -0
  87. data/schemas/devicePatch.json +78 -0
  88. data/schemas/devicePost.json +81 -0
  89. data/schemas/deviceRecipe.json +106 -0
  90. data/schemas/deviceRecipeBulkCreate.json +15 -0
  91. data/schemas/deviceRecipeBulkCreatePost.json +19 -0
  92. data/schemas/deviceRecipePatch.json +87 -0
  93. data/schemas/deviceRecipePost.json +90 -0
  94. data/schemas/deviceRecipes.json +148 -0
  95. data/schemas/deviceState.json +30 -0
  96. data/schemas/deviceStates.json +35 -0
  97. data/schemas/deviceTagFilter.json +19 -0
  98. data/schemas/devices.json +155 -0
  99. data/schemas/disableTwoFactorAuth.json +20 -0
  100. data/schemas/enableTwoFactorAuth.json +21 -0
  101. data/schemas/error.json +12 -0
  102. data/schemas/event.json +115 -0
  103. data/schemas/eventPatch.json +20 -0
  104. data/schemas/eventPost.json +39 -0
  105. data/schemas/events.json +165 -0
  106. data/schemas/flow.json +137 -0
  107. data/schemas/flowLog.json +46 -0
  108. data/schemas/flowPatch.json +107 -0
  109. data/schemas/flowPost.json +110 -0
  110. data/schemas/flowStorageEntries.json +7 -0
  111. data/schemas/flowStorageEntry.json +16 -0
  112. data/schemas/flows.json +179 -0
  113. data/schemas/githubLogin.json +14 -0
  114. data/schemas/lastValueData.json +34 -0
  115. data/schemas/lastValueQuery.json +36 -0
  116. data/schemas/me.json +173 -0
  117. data/schemas/mePatch.json +43 -0
  118. data/schemas/multiDeviceCommand.json +45 -0
  119. data/schemas/org.json +81 -0
  120. data/schemas/orgInvitePost.json +24 -0
  121. data/schemas/orgInvites.json +36 -0
  122. data/schemas/orgMemberPatch.json +23 -0
  123. data/schemas/orgPatch.json +16 -0
  124. data/schemas/orgPost.json +19 -0
  125. data/schemas/orgs.json +119 -0
  126. data/schemas/recentItem.json +27 -0
  127. data/schemas/recentItemList.json +36 -0
  128. data/schemas/success.json +12 -0
  129. data/schemas/timeSeriesData.json +89 -0
  130. data/schemas/timeSeriesQuery.json +64 -0
  131. data/schemas/userCredentials.json +25 -0
  132. data/schemas/virtualButtonPress.json +14 -0
  133. data/schemas/webhook.json +52 -0
  134. data/schemas/webhookPatch.json +29 -0
  135. data/schemas/webhookPost.json +32 -0
  136. data/schemas/webhooks.json +94 -0
  137. data/test/basic_test.rb +67 -0
  138. data/test/test_helper.rb +14 -0
  139. metadata +239 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c00f2713b0820ca3b059e735ecfacdbbf3587f80
4
+ data.tar.gz: 368a50fbd34057937155bcbfbcd0b93374dc948f
5
+ SHA512:
6
+ metadata.gz: c9f795186f951323494463a3034016ceaf27431e7471f0b712bcf7f9305a673ac3cc7d61d1562a905fe81d695d64fe8287e7faf78b039c760e3916a1e1bcaad7
7
+ data.tar.gz: 7ccb33ee4592955cde6d094e01a2a7bba6aa50b32b36a65bd22be538d66d6491f7aaac0b48e38b13300949f208408c85b88f1983f36fdb4d0960c67cd8bcb18d
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *~
2
+ \#*
3
+ .\#*
4
+ .DS_Store
5
+ *_flymake.*
6
+ *.LCK
7
+ .bundle
8
+ vendor/bundle
9
+ bin
10
+ *.gem
11
+ *.rbc
12
+ .bundle
13
+ .config
14
+ .yardoc
15
+ _yardoc
16
+ coverage
17
+ pkg
18
+ rdoc
19
+ spec/reports
20
+ test/tmp
21
+ test/version_tmp
22
+ tmp
23
+ Gemfile.lock
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - 2.1.10
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Losant IoT, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # Losant Ruby REST API Client
2
+
3
+ [![Build Status](https://travis-ci.org/Losant/losant-rest-ruby.svg?branch=master)](https://travis-ci.org/Losant/losant-rest-ruby)
4
+
5
+ The [Losant](https://www.losant.com>) REST API client provides a simple way to
6
+ use the comprehensive Losant API. You can authenticate either as a Losant
7
+ device or with your user account, and have access to all the functionality
8
+ of the Losant platform.
9
+
10
+ This client works with Ruby 2.1 and higher. It uses
11
+ [HTTParty](https://github.com/jnunemaker/httparty) under the
12
+ covers for the actual HTTP communication.
13
+
14
+ <br/>
15
+
16
+ ## Installation
17
+
18
+ The latest stable version is available in RubyGems and can be installed using
19
+
20
+ ```bash
21
+ gem install losant_rest
22
+ ```
23
+
24
+ <br/>
25
+
26
+ ## Example
27
+
28
+ Below is a high-level example of using the Losant Ruby REST API client to
29
+ authenticate against the Losant Platform and report state for a device.
30
+
31
+ ```ruby
32
+ require "losant_rest"
33
+
34
+ response = LosantRest.auth.authenticate_device(credentials: {
35
+ deviceId: "my-device-id",
36
+ key: "my-app-access-key",
37
+ secret: "my-app-access-secret"
38
+ })
39
+
40
+ LosantRest.auth_token = response["token"]
41
+ app_id = response["applicationId"]
42
+
43
+ state = { data: { temperature: AnalogSensor.read } }
44
+ response = LosantRest.device.send_state(deviceId: "my-device-id",
45
+ applicationId: app_id, deviceState: state)
46
+
47
+ puts response
48
+ # { "success" => true }
49
+ ```
50
+
51
+ <br/>
52
+
53
+ ## API Documentation
54
+
55
+ ### LosantRest
56
+
57
+ LosantRest is the wrapping module, but it also acts as a singleton [Client](#losantrestclient)
58
+ instance. So if you only need a single client instance, you do not need to
59
+ instantiate one yourself - the LosantRest module will act exactly like an
60
+ instance of LosantRest::Client.
61
+
62
+ <br/>
63
+
64
+ ### LosantRest::Client
65
+
66
+ A client is a single api instance. By default, it is unauthenticated, but can
67
+ be given an access token to perform authenticated requests.
68
+
69
+ #### Initializer
70
+
71
+ ```ruby
72
+ LosantRest::Client.new(auth_token: nil, url: "https://api.losant.com")
73
+ ```
74
+
75
+ The ``Client()`` initializer takes the following arguments:
76
+
77
+ * auth_token
78
+ The access token to be used for authentication - by default there is no
79
+ access token. An access token can be acquired through either of the
80
+ [Auth](docs/auth.md) methods.
81
+
82
+ * url
83
+ The url of the Losant API - by default <https://api.losant.com>.
84
+
85
+ #### Accessors
86
+
87
+ * auth_token
88
+ The auth token can be accessed or changed after Client creation
89
+ through this accessor.
90
+
91
+ * url
92
+ The api base url can be accessed or changed after Client creation
93
+ through this accessor.
94
+
95
+ #### Resources
96
+
97
+ Each of the following is a method on the client object, and returns a wrapper
98
+ for the actions against that particular resource. See each resource
99
+ documentation file for more information.
100
+
101
+ * [application_key](docs/applicationKey.md)
102
+ Contains all the actions that can be performed against a single
103
+ [Application Key](https://docs.losant.com/applications/access-keys/) -
104
+ for instance, getting info on a single key or revoking a key.
105
+
106
+ * [application_keys](docs/applicationKeys.md)
107
+ Contains all of the actions that can be performed against the collection of
108
+ [Application Keys](https://docs.losant.com/applications/access-keys/) belonging
109
+ to an Application - such as listing all keys or creating a new key.
110
+
111
+ * [application](docs/application.md)
112
+ Contains all of the actions that can be performed against a single
113
+ [Application](https://docs.losant.com/applications/overview/),
114
+ which include things like getting info on an application or
115
+ modifying an application.
116
+
117
+ * [applications](docs/applications.md)
118
+ Contains all of the actions that can be performed against the set of
119
+ [Applications](https://docs.losant.com/applications/overview/) that the
120
+ currently authenticated user has access to - such as
121
+ listing the applications or creating a new application.
122
+
123
+ * [auth](docs/auth.md)
124
+ Contains the actions used for authenticating against the api, either as a
125
+ user or as a device. The result of authentication calls contain the auth_token
126
+ needed for authenticated calls - see the examples for more details.
127
+
128
+ * [dashboard](docs/dashboard.md)
129
+ Contains all of the actions that can be performed against a single
130
+ [Dashboard](https://docs.losant.com/dashboards/overview/),
131
+ which include things like getting info on a dashboard or
132
+ modifying a dashboard.
133
+
134
+ * [dashboards](docs/dashboards.md)
135
+ Contains all of the actions that can be performed against the set of
136
+ [Dashboards](https://docs.losant.com/dashboards/overview/) that the
137
+ currently authenticated user has access to - such as
138
+ listing the dashboards or creating a new dashboard.
139
+
140
+ * [data](docs/data.md)
141
+ Contains the actions for querying against historical Device
142
+ data across an Application.
143
+
144
+ * [device](docs/device.md)
145
+ Contains all the actions that can be performed against a single
146
+ [Device](https://docs.losant.com/devices/overview/) -
147
+ for instance, getting info on a single device or reporting the current
148
+ state of a device.
149
+
150
+ * [devices](docs/devices.md)
151
+ Contains all of the actions that can be performed against the collection of
152
+ [Devices](https://docs.losant.com/devices/overview/) belonging
153
+ to an Application - such as listing all devices or sending a command to a set
154
+ of devices.
155
+
156
+ * [device_recipe](docs/deviceRecipe.md)
157
+ Contains all the actions that can be performed against a single
158
+ [Device Recipe](https://docs.losant.com/devices/device-recipes/), which
159
+ include things like removing a device recipe or creating a device
160
+ from a device recipe.
161
+
162
+ * [device_recipes](docs/deviceRecipes.md)
163
+ Contains all the actions that can be performed against the collection of
164
+ [Device Recipes](https://docs.losant.com/devices/device-recipes/) belonging
165
+ to an Application - such as listing recipes or creating a new recipe.
166
+
167
+ * [event](docs/event.md)
168
+ Contains all the actions that can be performed against a single
169
+ [Event](https://docs.losant.com/events/overview/), such as commenting on
170
+ or changing the state of an event.
171
+
172
+ * [events](docs/events.md)
173
+ Contains all the actions that can be performed against the collection of
174
+ [Events](https://docs.losant.com/events/overview/) belonging
175
+ to an Application - such as listing open events or creating a new event.
176
+
177
+ * [flow](docs/flow.md)
178
+ Contains all the actions that can be performed against a single
179
+ [Workflow](https://docs.losant.com/workflows/overview/), such as enabling or
180
+ disabling a workflow, or triggering a virtual button in the workflow.
181
+
182
+ * [flows](docs/flows.md)
183
+ Contains all the actions that can be performed against the collection of
184
+ [Workflows](https://docs.losant.com/workflows/overview/) belonging
185
+ to an Application - such as listing the workflows or creating a new workflow.
186
+
187
+ * [me](docs/me.md)
188
+ Contains the actions for operating against the currently authenticated
189
+ [User](https://docs.losant.com/user-accounts/overview/) such as changing
190
+ the password or linking against external services.
191
+
192
+ * [org](docs/org.md)
193
+ Contains all the actions that can be performed against a single
194
+ [Organization](https://docs.losant.com/organizations/overview/), things like
195
+ inviting a user to the organization, or modifying the organization.
196
+
197
+ * [orgs](docs/orgs.md)
198
+ Contains all of the actions that can be performed against the set of
199
+ [Organizations](https://docs.losant.com/organizations/overview/) that the
200
+ currently authenticated user has access to - such as
201
+ listing the organizations or creating a new organization.
202
+
203
+ * [webhook](docs/webhook.md)
204
+ Contains all the actions that can be performed against a single
205
+ [Webhook](https://docs.losant.com/applications/webhooks/), for instance
206
+ modifying the verification settings or removing the webhook.
207
+
208
+ * [webhooks](docs/webhooks.md)
209
+ Contains all the actions that can be performed against the collection of
210
+ [Webhooks](https://docs.losant.com/applications/webhooks/) belonging
211
+ to an Application - such as listing the webhooks or creating a new webhook.
212
+
213
+ <br/>
214
+
215
+ ### LosantRest::ResponseError
216
+
217
+ When the Losant API returns a unsuccessful response, an instance of
218
+ ResponseError is thrown.
219
+
220
+ #### Accessors
221
+
222
+ * code
223
+ The status code returned from the Losant API.
224
+
225
+ * type
226
+ The type of error that occured, such as "Validation" or "Authorization".
227
+
228
+ * message
229
+ A more detailed message about the particulars of the error.
230
+
231
+ <br/>
232
+
233
+ *****
234
+
235
+ Copyright (c) 2016 Losant IoT, Inc
236
+
237
+ <https://www.losant.com>
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ desc "Default: run unit tests."
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ end