lelylan-rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,184 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Functions do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+
10
+ describe '.function' do
11
+
12
+ let(:path) do
13
+ '/functions/4dcb9e23d033a9088900000a'
14
+ end
15
+
16
+ let(:uri) do
17
+ "http://api.lelylan.com/#{path}"
18
+ end
19
+
20
+ before do
21
+ stub_get(path).to_return(body: fixture('function.json'))
22
+ end
23
+
24
+ let!(:function) do
25
+ client.function(uri)
26
+ end
27
+
28
+ it 'returns the function' do
29
+ function.uri.should_not be_nil
30
+ end
31
+
32
+ it 'sends the request' do
33
+ a_get(path).should have_been_made
34
+ end
35
+ end
36
+
37
+
38
+ describe '.public_functions' do
39
+
40
+ let(:path) do
41
+ '/functions/public'
42
+ end
43
+
44
+ before do
45
+ client.user = nil
46
+ client.password = nil
47
+ end
48
+
49
+ before do
50
+ stub_get(path).to_return(body: fixture('functions.json'))
51
+ end
52
+
53
+ let!(:functions) do
54
+ client.public_functions
55
+ end
56
+
57
+ it 'returns a list of functions' do
58
+ functions.should have(1).item
59
+ end
60
+
61
+ it 'sends the request' do
62
+ a_get('http://api.lelylan.com/functions/public').should have_been_made
63
+ end
64
+ end
65
+
66
+
67
+ describe '.functions' do
68
+
69
+ let(:path) do
70
+ '/functions'
71
+ end
72
+
73
+ before do
74
+ stub_get('/functions').to_return(body: fixture('functions.json'))
75
+ end
76
+
77
+ let!(:functions) do
78
+ client.functions
79
+ end
80
+
81
+ it 'returns a list of functions' do
82
+ functions.should have(1).item
83
+ end
84
+
85
+ it 'sends the request' do
86
+ a_get(path).should have_been_made
87
+ end
88
+
89
+ context 'with params' do
90
+
91
+ before do
92
+ stub_get(path).with(query: {per: '25'}).to_return(body: fixture('function.json'))
93
+ end
94
+
95
+ before do
96
+ client.functions(per: 25)
97
+ end
98
+
99
+ it 'sends the params' do
100
+ a_get(path).with(query: {per: '25'}).should have_been_made
101
+ end
102
+ end
103
+ end
104
+
105
+
106
+ describe '.create_function' do
107
+
108
+ let(:path) do
109
+ '/functions'
110
+ end
111
+
112
+ before do
113
+ stub_post(path).with(body: {name: 'Set intensity'}).to_return(body: fixture('function.json'))
114
+ end
115
+
116
+ let!(:function) do
117
+ client.create_function(name: 'Set intensity')
118
+ end
119
+
120
+ it 'returns the function' do
121
+ function.uri.should_not be_nil
122
+ end
123
+
124
+ it 'sends the request' do
125
+ a_post(path).with(body: {name: 'Set intensity'}).should have_been_made
126
+ end
127
+ end
128
+
129
+
130
+ describe '.update_function' do
131
+
132
+ let(:path) do
133
+ '/functions/4dcb9e23d033a9088900000a'
134
+ end
135
+
136
+ let(:uri) do
137
+ "http://api.lelylan.com/#{path}"
138
+ end
139
+
140
+ before do
141
+ stub_put(path).with(body: {name: 'Set intensity'}).to_return(body: fixture('function.json'))
142
+ end
143
+
144
+ let!(:function) do
145
+ client.update_function(uri, name: 'Set intensity')
146
+ end
147
+
148
+ it 'returns the function' do
149
+ function.uri.should_not be_nil
150
+ end
151
+
152
+ it 'sends the request' do
153
+ a_put(path).with(body: {name: 'Set intensity'}).should have_been_made
154
+ end
155
+ end
156
+
157
+
158
+ describe '.delete_function' do
159
+
160
+ let(:path) do
161
+ '/functions/4dcb9e23d033a9088900000a'
162
+ end
163
+
164
+ let(:uri) do
165
+ "http://api.lelylan.com/#{path}"
166
+ end
167
+
168
+ before do
169
+ stub_delete(path).to_return(body: fixture('function.json'))
170
+ end
171
+
172
+ let!(:function) do
173
+ client.delete_function(uri)
174
+ end
175
+
176
+ it 'returns the function' do
177
+ function.uri.should_not be_nil
178
+ end
179
+
180
+ it 'sends the request' do
181
+ a_delete(path).should have_been_made
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Histories do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+
10
+ describe '.history' do
11
+
12
+ let(:path) do
13
+ '/histories/4dcb9e23d033a9088900000e'
14
+ end
15
+
16
+ let(:uri) do
17
+ "http://api.lelylan.com/#{path}"
18
+ end
19
+
20
+ before do
21
+ stub_get(path).to_return(body: fixture('history.json'))
22
+ end
23
+
24
+ let!(:history) do
25
+ client.history(uri)
26
+ end
27
+
28
+ it 'returns the history' do
29
+ history.uri.should_not be_nil
30
+ end
31
+
32
+ it 'sends the request' do
33
+ a_get(path).should have_been_made
34
+ end
35
+ end
36
+
37
+
38
+ describe '.histories' do
39
+
40
+ let(:path) do
41
+ '/devices/4dcb9e23d033a9088900000a'
42
+ end
43
+
44
+ let(:uri) do
45
+ "http://api.lelylan.com/#{path}"
46
+ end
47
+
48
+ before do
49
+ stub_get("#{path}/histories").with(query: {per: 10}).to_return(body: fixture('histories.json'))
50
+ end
51
+
52
+ let!(:histories) do
53
+ client.histories(uri, per: 10)
54
+ end
55
+
56
+ it 'returns the histories' do
57
+ histories.first.uri.should_not be_nil
58
+ end
59
+
60
+ it 'sends the request' do
61
+ a_get("#{path}/histories").with(query: {per: 10}).should have_been_made
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,155 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Locations do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+
10
+ describe '.location' do
11
+
12
+ let(:path) do
13
+ '/locations/4dcb9e23d033a9088900000a'
14
+ end
15
+
16
+ let(:uri) do
17
+ "http://api.lelylan.com/#{path}"
18
+ end
19
+
20
+ before do
21
+ stub_get(path).to_return(body: fixture('location.json'))
22
+ end
23
+
24
+ let!(:location) do
25
+ client.location(uri)
26
+ end
27
+
28
+ it 'returns the location' do
29
+ location.uri.should_not be_nil
30
+ end
31
+
32
+ it 'sends the request' do
33
+ a_get(path).should have_been_made
34
+ end
35
+ end
36
+
37
+
38
+ describe '.locations' do
39
+
40
+ let(:path) do
41
+ '/locations'
42
+ end
43
+
44
+ before do
45
+ stub_get('/locations').to_return(body: fixture('locations.json'))
46
+ end
47
+
48
+ let!(:locations) do
49
+ client.locations
50
+ end
51
+
52
+ it 'returns a list of locations' do
53
+ locations.should have(1).item
54
+ end
55
+
56
+ it 'sends the request' do
57
+ a_get(path).should have_been_made
58
+ end
59
+
60
+ context 'with params' do
61
+
62
+ before do
63
+ stub_get(path).with(query: {per: '25'}).to_return(body: fixture('location.json'))
64
+ end
65
+
66
+ before do
67
+ client.locations(per: 25)
68
+ end
69
+
70
+ it 'sends the params' do
71
+ a_get(path).with(query: {per: '25'}).should have_been_made
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ describe '.create_location' do
78
+
79
+ let(:path) do
80
+ '/locations'
81
+ end
82
+
83
+ before do
84
+ stub_post(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('location.json'))
85
+ end
86
+
87
+ let!(:location) do
88
+ client.create_location(name: 'Dimmer')
89
+ end
90
+
91
+ it 'returns the location' do
92
+ location.uri.should_not be_nil
93
+ end
94
+
95
+ it 'sends the request' do
96
+ a_post(path).with(body: {name: 'Dimmer'}).should have_been_made
97
+ end
98
+ end
99
+
100
+
101
+ describe '.update_location' do
102
+
103
+ let(:path) do
104
+ '/locations/4dcb9e23d033a9088900000a'
105
+ end
106
+
107
+ let(:uri) do
108
+ "http://api.lelylan.com/#{path}"
109
+ end
110
+
111
+ before do
112
+ stub_put(path).with(body: {name: 'Dimmer'}).to_return(body: fixture('location.json'))
113
+ end
114
+
115
+ let!(:location) do
116
+ client.update_location(uri, name: 'Dimmer')
117
+ end
118
+
119
+ it 'returns the location' do
120
+ location.uri.should_not be_nil
121
+ end
122
+
123
+ it 'sends the request' do
124
+ a_put(path).with(body: {name: 'Dimmer'}).should have_been_made
125
+ end
126
+ end
127
+
128
+
129
+ describe '.delete_location' do
130
+
131
+ let(:path) do
132
+ '/locations/4dcb9e23d033a9088900000a'
133
+ end
134
+
135
+ let(:uri) do
136
+ "http://api.lelylan.com/#{path}"
137
+ end
138
+
139
+ before do
140
+ stub_delete(path).to_return(body: fixture('location.json'))
141
+ end
142
+
143
+ let!(:location) do
144
+ client.delete_location(uri)
145
+ end
146
+
147
+ it 'returns the location' do
148
+ location.uri.should_not be_nil
149
+ end
150
+
151
+ it 'sends the request' do
152
+ a_delete(path).should have_been_made
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,184 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Properties do
4
+
5
+ let(:client) do
6
+ a_client
7
+ end
8
+
9
+
10
+ describe '.property' do
11
+
12
+ let(:path) do
13
+ '/properties/4dcb9e23d033a9088900000a'
14
+ end
15
+
16
+ let(:uri) do
17
+ "http://api.lelylan.com/#{path}"
18
+ end
19
+
20
+ before do
21
+ stub_get(path).to_return(body: fixture('property.json'))
22
+ end
23
+
24
+ let!(:property) do
25
+ client.property(uri)
26
+ end
27
+
28
+ it 'returns the property' do
29
+ property.uri.should_not be_nil
30
+ end
31
+
32
+ it 'sends the request' do
33
+ a_get(path).should have_been_made
34
+ end
35
+ end
36
+
37
+
38
+ describe '.properties' do
39
+
40
+ let(:path) do
41
+ '/properties'
42
+ end
43
+
44
+ before do
45
+ stub_get('/properties').to_return(body: fixture('properties.json'))
46
+ end
47
+
48
+ let!(:properties) do
49
+ client.properties
50
+ end
51
+
52
+ it 'returns a list of properties' do
53
+ properties.should have(1).item
54
+ end
55
+
56
+ it 'sends the request' do
57
+ a_get(path).should have_been_made
58
+ end
59
+
60
+ context 'with params' do
61
+
62
+ before do
63
+ stub_get(path).with(query: {per: '25'}).to_return(body: fixture('property.json'))
64
+ end
65
+
66
+ before do
67
+ client.properties(per: 25)
68
+ end
69
+
70
+ it 'sends the params' do
71
+ a_get(path).with(query: {per: '25'}).should have_been_made
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ describe '.public_properties' do
78
+
79
+ let(:path) do
80
+ '/properties/public'
81
+ end
82
+
83
+ before do
84
+ client.user = nil
85
+ client.password = nil
86
+ end
87
+
88
+ before do
89
+ stub_get(path).to_return(body: fixture('properties.json'))
90
+ end
91
+
92
+ let!(:properties) do
93
+ client.public_properties
94
+ end
95
+
96
+ it 'returns a list of properties' do
97
+ properties.should have(1).item
98
+ end
99
+
100
+ it 'sends the request' do
101
+ a_get('http://api.lelylan.com/properties/public').should have_been_made
102
+ end
103
+ end
104
+
105
+
106
+ describe '.create_property' do
107
+
108
+ let(:path) do
109
+ '/properties'
110
+ end
111
+
112
+ before do
113
+ stub_post(path).with(body: {name: 'Status'}).to_return(body: fixture('property.json'))
114
+ end
115
+
116
+ let!(:property) do
117
+ client.create_property(name: 'Status')
118
+ end
119
+
120
+ it 'returns the property' do
121
+ property.uri.should_not be_nil
122
+ end
123
+
124
+ it 'sends the request' do
125
+ a_post(path).with(body: {name: 'Status'}).should have_been_made
126
+ end
127
+ end
128
+
129
+
130
+ describe '.update_property' do
131
+
132
+ let(:path) do
133
+ '/properties/4dcb9e23d033a9088900000a'
134
+ end
135
+
136
+ let(:uri) do
137
+ "http://api.lelylan.com/#{path}"
138
+ end
139
+
140
+ before do
141
+ stub_put(path).with(body: {name: 'Status'}).to_return(body: fixture('property.json'))
142
+ end
143
+
144
+ let!(:property) do
145
+ client.update_property(uri, name: 'Status')
146
+ end
147
+
148
+ it 'returns the property' do
149
+ property.uri.should_not be_nil
150
+ end
151
+
152
+ it 'sends the request' do
153
+ a_put(path).with(body: {name: 'Status'}).should have_been_made
154
+ end
155
+ end
156
+
157
+
158
+ describe '.delete_property' do
159
+
160
+ let(:path) do
161
+ '/properties/4dcb9e23d033a9088900000a'
162
+ end
163
+
164
+ let(:uri) do
165
+ "http://api.lelylan.com/#{path}"
166
+ end
167
+
168
+ before do
169
+ stub_delete(path).to_return(body: fixture('property.json'))
170
+ end
171
+
172
+ let!(:property) do
173
+ client.delete_property(uri)
174
+ end
175
+
176
+ it 'returns the property' do
177
+ property.uri.should_not be_nil
178
+ end
179
+
180
+ it 'sends the request' do
181
+ a_delete(path).should have_been_made
182
+ end
183
+ end
184
+ end