lelylan-rb 0.0.1

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 (62) hide show
  1. data/.gitignore +26 -0
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile +7 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.md +1 -0
  6. data/README.md +218 -0
  7. data/Rakefile +21 -0
  8. data/lelylan_rb.gemspec +36 -0
  9. data/lib/faraday/response/raise_http_error.rb +35 -0
  10. data/lib/lelylan.rb +26 -0
  11. data/lib/lelylan/authentication.rb +11 -0
  12. data/lib/lelylan/client.rb +47 -0
  13. data/lib/lelylan/client/categories.rb +112 -0
  14. data/lib/lelylan/client/consumptions.rb +93 -0
  15. data/lib/lelylan/client/devices.rb +211 -0
  16. data/lib/lelylan/client/functions.rb +118 -0
  17. data/lib/lelylan/client/histories.rb +42 -0
  18. data/lib/lelylan/client/locations.rb +92 -0
  19. data/lib/lelylan/client/properties.rb +115 -0
  20. data/lib/lelylan/client/statuses.rb +110 -0
  21. data/lib/lelylan/client/types.rb +109 -0
  22. data/lib/lelylan/configuration.rb +65 -0
  23. data/lib/lelylan/connection.rb +33 -0
  24. data/lib/lelylan/error.rb +34 -0
  25. data/lib/lelylan/request.rb +70 -0
  26. data/lib/lelylan/version.rb +15 -0
  27. data/spec/faraday/response_spec.rb +37 -0
  28. data/spec/fixtures/categories.json +7 -0
  29. data/spec/fixtures/category.json +7 -0
  30. data/spec/fixtures/consumption.json +11 -0
  31. data/spec/fixtures/consumptions.json +11 -0
  32. data/spec/fixtures/device.json +25 -0
  33. data/spec/fixtures/devices.json +25 -0
  34. data/spec/fixtures/function.json +15 -0
  35. data/spec/fixtures/functions.json +15 -0
  36. data/spec/fixtures/histories.json +16 -0
  37. data/spec/fixtures/history.json +16 -0
  38. data/spec/fixtures/location.json +55 -0
  39. data/spec/fixtures/locations.json +18 -0
  40. data/spec/fixtures/oauth2/refresh.json +6 -0
  41. data/spec/fixtures/oauth2/token.json +6 -0
  42. data/spec/fixtures/pending.json +12 -0
  43. data/spec/fixtures/properties.json +9 -0
  44. data/spec/fixtures/property.json +9 -0
  45. data/spec/fixtures/status.json +24 -0
  46. data/spec/fixtures/statuses.json +24 -0
  47. data/spec/fixtures/type.json +94 -0
  48. data/spec/fixtures/types.json +88 -0
  49. data/spec/helper.rb +71 -0
  50. data/spec/lelylan/client/categories_spec.rb +178 -0
  51. data/spec/lelylan/client/consumptions_spec.rb +150 -0
  52. data/spec/lelylan/client/devices_spec.rb +342 -0
  53. data/spec/lelylan/client/functions_spec.rb +184 -0
  54. data/spec/lelylan/client/histories_spec.rb +64 -0
  55. data/spec/lelylan/client/locations_spec.rb +155 -0
  56. data/spec/lelylan/client/properties_spec.rb +184 -0
  57. data/spec/lelylan/client/statuses_spec.rb +184 -0
  58. data/spec/lelylan/client/types_spec.rb +184 -0
  59. data/spec/lelylan/client_spec.rb +32 -0
  60. data/spec/lelylan/oauth2_spec.rb +54 -0
  61. data/spec/lelylan_spec.rb +32 -0
  62. metadata +351 -0
@@ -0,0 +1,150 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Consumptions do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+ describe '.consumption' do
10
+
11
+ let(:path) do
12
+ '/consumptions/4dcb9e23d033a9088900000a'
13
+ end
14
+
15
+ let(:uri) do
16
+ "http://api.lelylan.com/#{path}"
17
+ end
18
+
19
+ before do
20
+ stub_get(path).to_return(body: fixture('consumption.json'))
21
+ end
22
+
23
+ let!(:consumption) do
24
+ client.consumption(uri)
25
+ end
26
+
27
+ it 'returns the consumption' do
28
+ consumption.uri.should_not be_nil
29
+ end
30
+
31
+ it 'sends the request' do
32
+ a_get(path).should have_been_made
33
+ end
34
+ end
35
+
36
+ describe '.consumptions' do
37
+
38
+ let(:path) do
39
+ '/consumptions'
40
+ end
41
+
42
+ before do
43
+ stub_get('/consumptions').to_return(body: fixture('consumptions.json'))
44
+ end
45
+
46
+ let!(:consumptions) do
47
+ client.consumptions
48
+ end
49
+
50
+ it 'returns a list of consumptions' do
51
+ consumptions.should have(1).item
52
+ end
53
+
54
+ it 'sends the request' do
55
+ a_get(path).should have_been_made
56
+ end
57
+
58
+ context 'with params' do
59
+
60
+ before do
61
+ stub_get(path).with(query: {per: '25'}).to_return(body: fixture('consumption.json'))
62
+ end
63
+
64
+ before do
65
+ client.consumptions(per: 25)
66
+ end
67
+
68
+ it 'sends the params' do
69
+ a_get(path).with(query: {per: '25'}).should have_been_made
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '.create_consumption' do
75
+
76
+ let(:path) do
77
+ '/consumptions'
78
+ end
79
+
80
+ before do
81
+ stub_post(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('consumption.json'))
82
+ end
83
+
84
+ let!(:consumption) do
85
+ client.create_consumption(name: 'Dimmer')
86
+ end
87
+
88
+ it 'returns the consumption' do
89
+ consumption.uri.should_not be_nil
90
+ end
91
+
92
+ it 'sends the request' do
93
+ a_post(path).with(body: {name: 'Dimmer'}).should have_been_made
94
+ end
95
+ end
96
+
97
+ describe '.update_consumption' do
98
+
99
+ let(:path) do
100
+ '/consumptions/4dcb9e23d033a9088900000a'
101
+ end
102
+
103
+ let(:uri) do
104
+ "http://api.lelylan.com/#{path}"
105
+ end
106
+
107
+ before do
108
+ stub_put(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('consumption.json'))
109
+ end
110
+
111
+ let!(:consumption) do
112
+ client.update_consumption(uri, name: 'Dimmer')
113
+ end
114
+
115
+ it 'returns the consumption' do
116
+ consumption.uri.should_not be_nil
117
+ end
118
+
119
+ it 'sends the request' do
120
+ a_put(path).with(body: {name: 'Dimmer'}).should have_been_made
121
+ end
122
+ end
123
+
124
+ describe '.delete_consumption' do
125
+
126
+ let(:path) do
127
+ '/consumptions/4dcb9e23d033a9088900000a'
128
+ end
129
+
130
+ let(:uri) do
131
+ "http://api.lelylan.com/#{path}"
132
+ end
133
+
134
+ before do
135
+ stub_delete(path).to_return(body: fixture('consumption.json'))
136
+ end
137
+
138
+ let!(:consumption) do
139
+ client.delete_consumption(uri)
140
+ end
141
+
142
+ it 'returns the consumption' do
143
+ consumption.uri.should_not be_nil
144
+ end
145
+
146
+ it 'sends the request' do
147
+ a_delete(path).should have_been_made
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,342 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Devices do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+ describe '.device' do
10
+
11
+ let(:path) do
12
+ '/devices/4dcb9e23d033a9088900000a'
13
+ end
14
+
15
+ let(:uri) do
16
+ "http://api.lelylan.com/#{path}"
17
+ end
18
+
19
+ before do
20
+ stub_get(path).to_return(body: fixture('device.json'))
21
+ end
22
+
23
+ let!(:device) do
24
+ client.device(uri)
25
+ end
26
+
27
+ it 'returns the device' do
28
+ device.uri.should_not be_nil
29
+ end
30
+
31
+ it 'sends the request' do
32
+ a_get(path).should have_been_made
33
+ end
34
+ end
35
+
36
+
37
+ describe '.devices' do
38
+
39
+ let(:path) do
40
+ '/devices'
41
+ end
42
+
43
+ before do
44
+ stub_get('/devices').to_return(body: fixture('devices.json'))
45
+ end
46
+
47
+ let!(:devices) do
48
+ client.devices
49
+ end
50
+
51
+ it 'returns a list of devices' do
52
+ devices.should have(1).item
53
+ end
54
+
55
+ it 'sends the request' do
56
+ a_get(path).should have_been_made
57
+ end
58
+
59
+ context 'with params' do
60
+
61
+ before do
62
+ stub_get(path).with(query: {per: '25'}).to_return(body: fixture('device.json'))
63
+ end
64
+
65
+ before do
66
+ client.devices(per: 25)
67
+ end
68
+
69
+ it 'sends the params' do
70
+ a_get(path).with(query: {per: '25'}).should have_been_made
71
+ end
72
+ end
73
+ end
74
+
75
+
76
+ describe '.create_device' do
77
+
78
+ let(:path) do
79
+ '/devices'
80
+ end
81
+
82
+ before do
83
+ stub_post(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('device.json'))
84
+ end
85
+
86
+ let!(:device) do
87
+ client.create_device(name: 'Dimmer')
88
+ end
89
+
90
+ it 'returns the device' do
91
+ device.uri.should_not be_nil
92
+ end
93
+
94
+ it 'sends the request' do
95
+ a_post(path).with(body: {name: 'Dimmer'}).should have_been_made
96
+ end
97
+ end
98
+
99
+
100
+ describe '.update_device' do
101
+
102
+ let(:path) do
103
+ '/devices/4dcb9e23d033a9088900000a'
104
+ end
105
+
106
+ let(:uri) do
107
+ "http://api.lelylan.com/#{path}"
108
+ end
109
+
110
+ before do
111
+ stub_put(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('device.json'))
112
+ end
113
+
114
+ let!(:device) do
115
+ client.update_device(uri, name: 'Dimmer')
116
+ end
117
+
118
+ it 'returns the device' do
119
+ device.uri.should_not be_nil
120
+ end
121
+
122
+ it 'sends the request' do
123
+ a_put(path).with(body: {name: 'Dimmer'}).should have_been_made
124
+ end
125
+ end
126
+
127
+
128
+ describe '.delete_device' do
129
+
130
+ let(:path) do
131
+ '/devices/4dcb9e23d033a9088900000a'
132
+ end
133
+
134
+ let(:uri) do
135
+ "http://api.lelylan.com/#{path}"
136
+ end
137
+
138
+ before do
139
+ stub_delete(path).to_return(body: fixture('device.json'))
140
+ end
141
+
142
+ let!(:device) do
143
+ client.delete_device(uri)
144
+ end
145
+
146
+ it 'returns the device' do
147
+ device.uri.should_not be_nil
148
+ end
149
+
150
+ it 'sends the request' do
151
+ a_delete(path).should have_been_made
152
+ end
153
+ end
154
+
155
+
156
+ describe '.execute' do
157
+
158
+ let(:path) do
159
+ '/devices/4dcb9e23d033a9088900000a'
160
+ end
161
+
162
+ let(:function) do
163
+ 'http://api.lelylan.com/functions/4dcb9e23d033a9088900020a'
164
+ end
165
+
166
+ let(:properties) do
167
+ [{uri: 'http://api.lelylan.com/properties/4dcb9e23d033a9088900020a', value: '50'}]
168
+ end
169
+
170
+ let(:uri) do
171
+ "http://api.lelylan.com/#{path}"
172
+ end
173
+
174
+ before do
175
+ stub_put("#{path}/functions").with(query: {uri: function}).with(body: {properties: properties}).to_return(body: fixture('device.json'))
176
+ end
177
+
178
+ let!(:device) do
179
+ client.execute(uri, function, properties: properties)
180
+ end
181
+
182
+ it 'returns the updated device' do
183
+ device.uri.should_not be_nil
184
+ end
185
+
186
+ it 'sends the request' do
187
+ a_put("#{path}/functions").with(query: {uri: function}).with(body: {properties: properties}).should have_been_made
188
+ end
189
+ end
190
+
191
+
192
+ describe '.update_properties' do
193
+
194
+ let(:path) do
195
+ '/devices/4dcb9e23d033a9088900000a'
196
+ end
197
+
198
+ let(:properties) do
199
+ [{uri: 'http://api.lelylan.com/properties/4dcb9e23d033a9088900020a', value: '50'}]
200
+ end
201
+
202
+ let(:uri) do
203
+ "http://api.lelylan.com/#{path}"
204
+ end
205
+
206
+ before do
207
+ stub_put("#{path}/properties").with(body: {properties: properties}).to_return(body: fixture('device.json'))
208
+ end
209
+
210
+ let!(:device) do
211
+ client.update_properties(uri, properties: properties)
212
+ end
213
+
214
+ it 'returns the updated device' do
215
+ device.uri.should_not be_nil
216
+ end
217
+
218
+ it 'sends the request' do
219
+ a_put("#{path}/properties").with(body: {properties: properties}).should have_been_made
220
+ end
221
+ end
222
+
223
+
224
+ describe '.connect_physical' do
225
+
226
+ let(:path) do
227
+ '/devices/4dcb9e23d033a9088900000a'
228
+ end
229
+
230
+ let(:physical) do
231
+ 'http://api.lelylan.com/properties/4dcb9e23d033a9088900020a'
232
+ end
233
+
234
+ let(:uri) do
235
+ "http://api.lelylan.com/#{path}"
236
+ end
237
+
238
+ before do
239
+ stub_put("#{path}/physical").with(body: {uri: physical}).to_return(body: fixture('device.json'))
240
+ end
241
+
242
+ let!(:device) do
243
+ client.connect_physical(uri, uri: physical)
244
+ end
245
+
246
+ it 'returns the updated device' do
247
+ device.uri.should_not be_nil
248
+ end
249
+
250
+ it 'sends the request' do
251
+ a_put("#{path}/physical").with(body: {uri: physical}).should have_been_made
252
+ end
253
+ end
254
+
255
+
256
+ describe '.disconnect_physical' do
257
+
258
+ let(:path) do
259
+ '/devices/4dcb9e23d033a9088900000a'
260
+ end
261
+
262
+ let(:uri) do
263
+ "http://api.lelylan.com/#{path}"
264
+ end
265
+
266
+ before do
267
+ stub_delete("#{path}/physical").to_return(body: fixture('device.json'))
268
+ end
269
+
270
+ let!(:device) do
271
+ client.disconnect_physical(uri)
272
+ end
273
+
274
+ it 'returns the updated device' do
275
+ device.uri.should_not be_nil
276
+ end
277
+
278
+ it 'sends the request' do
279
+ a_delete("#{path}/physical").should have_been_made
280
+ end
281
+ end
282
+
283
+
284
+ describe '.pending' do
285
+
286
+ let(:path) do
287
+ '/devices/4dcb9e23d033a9088900000a'
288
+ end
289
+
290
+ let(:uri) do
291
+ "http://api.lelylan.com/#{path}"
292
+ end
293
+
294
+ before do
295
+ stub_get("#{path}/pending").to_return(body: fixture('pending.json'))
296
+ end
297
+
298
+ let!(:device) do
299
+ client.pending(uri)
300
+ end
301
+
302
+ it 'returns the pending resource' do
303
+ device.uri.should_not be_nil
304
+ end
305
+
306
+ it 'sends the request' do
307
+ a_get("#{path}/pending").should have_been_made
308
+ end
309
+ end
310
+
311
+
312
+ describe '.update_pending' do
313
+
314
+ let(:path) do
315
+ '/devices/4dcb9e23d033a9088900000a'
316
+ end
317
+
318
+ let(:properties) do
319
+ [{uri: 'http://api.lelylan.com/properties/4dcb9e23d033a9088900020a', value: '50'}]
320
+ end
321
+
322
+ let(:uri) do
323
+ "http://api.lelylan.com/#{path}"
324
+ end
325
+
326
+ before do
327
+ stub_put("#{path}/pending").with(body: {properties: properties}).to_return(body: fixture('pending.json'))
328
+ end
329
+
330
+ let!(:device) do
331
+ client.update_pending(uri, properties: properties)
332
+ end
333
+
334
+ it 'returns the updated device' do
335
+ device.uri.should_not be_nil
336
+ end
337
+
338
+ it 'sends the request' do
339
+ a_put("#{path}/pending").with(body: {properties: properties}).should have_been_made
340
+ end
341
+ end
342
+ end