lelylan-rb 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +6 -2
  3. data/Gemfile +1 -3
  4. data/Guardfile +1 -1
  5. data/README.md +155 -84
  6. data/Rakefile +2 -15
  7. data/images/bg_hr.png +0 -0
  8. data/images/blacktocat.png +0 -0
  9. data/images/icon_download.png +0 -0
  10. data/images/sprite_download.png +0 -0
  11. data/index.html +74 -0
  12. data/javascripts/main.js +1 -0
  13. data/lelylan_rb.gemspec +12 -13
  14. data/lib/lelylan/client.rb +20 -23
  15. data/lib/lelylan/client/device.rb +121 -0
  16. data/lib/lelylan/client/function.rb +73 -0
  17. data/lib/lelylan/client/history.rb +28 -0
  18. data/lib/lelylan/client/location.rb +62 -0
  19. data/lib/lelylan/client/physical.rb +34 -0
  20. data/lib/lelylan/client/profile.rb +17 -0
  21. data/lib/lelylan/client/property.rb +75 -0
  22. data/lib/lelylan/client/status.rb +74 -0
  23. data/lib/lelylan/client/subscription.rb +62 -0
  24. data/lib/lelylan/client/type.rb +73 -0
  25. data/lib/lelylan/configuration.rb +4 -4
  26. data/lib/lelylan/connection.rb +9 -2
  27. data/lib/lelylan/request.rb +2 -16
  28. data/lib/lelylan/version.rb +1 -1
  29. data/spec/fixtures/profile.json +8 -0
  30. data/spec/fixtures/subscription.json +10 -0
  31. data/spec/fixtures/subscriptions.json +10 -0
  32. data/spec/lelylan/client/device_spec.rb +234 -0
  33. data/spec/lelylan/client/function_spec.rb +158 -0
  34. data/spec/lelylan/client/history_spec.rb +48 -0
  35. data/spec/lelylan/client/location_spec.rb +122 -0
  36. data/spec/lelylan/client/physical_spec.rb +27 -0
  37. data/spec/lelylan/client/profile_spec.rb +27 -0
  38. data/spec/lelylan/client/property_spec.rb +159 -0
  39. data/spec/lelylan/client/status_spec.rb +158 -0
  40. data/spec/lelylan/client/subscription_spec.rb +144 -0
  41. data/spec/lelylan/client/type_spec.rb +158 -0
  42. data/spec/lelylan/oauth2_spec.rb +13 -19
  43. data/stylesheets/pygment_trac.css +70 -0
  44. data/stylesheets/stylesheet.css +431 -0
  45. metadata +75 -114
  46. data/lib/lelylan/client/categories.rb +0 -112
  47. data/lib/lelylan/client/consumptions.rb +0 -93
  48. data/lib/lelylan/client/devices.rb +0 -211
  49. data/lib/lelylan/client/functions.rb +0 -118
  50. data/lib/lelylan/client/histories.rb +0 -42
  51. data/lib/lelylan/client/locations.rb +0 -92
  52. data/lib/lelylan/client/properties.rb +0 -115
  53. data/lib/lelylan/client/statuses.rb +0 -110
  54. data/lib/lelylan/client/types.rb +0 -109
  55. data/spec/lelylan/client/categories_spec.rb +0 -178
  56. data/spec/lelylan/client/consumptions_spec.rb +0 -150
  57. data/spec/lelylan/client/devices_spec.rb +0 -342
  58. data/spec/lelylan/client/functions_spec.rb +0 -184
  59. data/spec/lelylan/client/histories_spec.rb +0 -64
  60. data/spec/lelylan/client/locations_spec.rb +0 -155
  61. data/spec/lelylan/client/properties_spec.rb +0 -184
  62. data/spec/lelylan/client/statuses_spec.rb +0 -184
  63. data/spec/lelylan/client/types_spec.rb +0 -184
@@ -0,0 +1,158 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Function do
4
+
5
+ let(:lelylan) do
6
+ a_client
7
+ end
8
+
9
+ describe '#type' do
10
+
11
+ before do
12
+ stub_get('/types/1').to_return(body: fixture('type.json'))
13
+ end
14
+
15
+ let!(:type) do
16
+ lelylan.type('1')
17
+ end
18
+
19
+ it 'returns the type' do
20
+ type.id.should_not be_nil
21
+ end
22
+
23
+ it 'sends the request' do
24
+ a_get('/types/1').should have_been_made
25
+ end
26
+ end
27
+
28
+
29
+ describe '#types' do
30
+
31
+ before do
32
+ stub_get('/types').to_return(body: fixture('types.json'))
33
+ end
34
+
35
+ let!(:types) do
36
+ lelylan.types
37
+ end
38
+
39
+ it 'returns a list of types' do
40
+ types.should have(1).item
41
+ end
42
+
43
+ it 'sends the request' do
44
+ a_get('/types').should have_been_made
45
+ end
46
+
47
+ context 'with params' do
48
+
49
+ before do
50
+ stub_get('/types').with(query: { per: '25' }).to_return(body: fixture('type.json'))
51
+ end
52
+
53
+ before do
54
+ lelylan.types(per: 25)
55
+ end
56
+
57
+ it 'sends the params' do
58
+ a_get('/types').with(query: { per: '25' }).should have_been_made
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+
65
+ describe '#public_types' do
66
+
67
+ before do
68
+ stub_get('/types/public').to_return(body: fixture('types.json'))
69
+ end
70
+
71
+ let!(:types) do
72
+ lelylan.public_types
73
+ end
74
+
75
+ it 'returns a list of types' do
76
+ types.should have(1).item
77
+ end
78
+
79
+ it 'sends the request' do
80
+ a_get('/types/public').should have_been_made
81
+ end
82
+
83
+ context 'with params' do
84
+
85
+ before do
86
+ stub_get('/types/public').with(query: { per: '25' }).to_return(body: fixture('type.json'))
87
+ end
88
+
89
+ before do
90
+ lelylan.public_types(per: 25)
91
+ end
92
+
93
+ it 'sends the params' do
94
+ a_get('/types/public').with(query: { per: '25' }).should have_been_made
95
+ end
96
+ end
97
+ end
98
+
99
+
100
+ describe '#create_type' do
101
+
102
+ before do
103
+ stub_post('/types').with(body: { name: 'Set Intensity' }).to_return(body: fixture('type.json'))
104
+ end
105
+
106
+ let!(:type) do
107
+ lelylan.create_type(name: 'Set Intensity')
108
+ end
109
+
110
+ it 'returns the type' do
111
+ type.id.should_not be_nil
112
+ end
113
+
114
+ it 'sends the request' do
115
+ a_post('/types').with(body: { name: 'Set Intensity' }).should have_been_made
116
+ end
117
+ end
118
+
119
+
120
+ describe '#update_type' do
121
+
122
+ before do
123
+ stub_put('/types/1').with(body: { name: 'Set Intensity' }).to_return(body: fixture('type.json'))
124
+ end
125
+
126
+ let!(:type) do
127
+ lelylan.update_type('1', name: 'Set Intensity')
128
+ end
129
+
130
+ it 'returns the type' do
131
+ type.id.should_not be_nil
132
+ end
133
+
134
+ it 'sends the request' do
135
+ a_put('/types/1').with(body: { name: 'Set Intensity' }).should have_been_made
136
+ end
137
+ end
138
+
139
+
140
+ describe '#delete_type' do
141
+
142
+ before do
143
+ stub_delete('/types/1').to_return(body: fixture('type.json'))
144
+ end
145
+
146
+ let!(:type) do
147
+ lelylan.delete_type('1')
148
+ end
149
+
150
+ it 'returns the type' do
151
+ type.id.should_not be_nil
152
+ end
153
+
154
+ it 'sends the request' do
155
+ a_delete('/types/1').should have_been_made
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,48 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::History do
4
+
5
+ let(:lelylan) do
6
+ a_client
7
+ end
8
+
9
+
10
+ describe '#find_history' do
11
+
12
+ before do
13
+ stub_get('/histories/1').to_return(body: fixture('history.json'))
14
+ end
15
+
16
+ let!(:history) do
17
+ lelylan.find_history('1')
18
+ end
19
+
20
+ it 'returns the history' do
21
+ history.id.should_not be_nil
22
+ end
23
+
24
+ it 'sends the request' do
25
+ a_get('/histories/1').should have_been_made
26
+ end
27
+ end
28
+
29
+
30
+ describe '#all_histories' do
31
+
32
+ before do
33
+ stub_get('/histories').with(query: {per: 10}).to_return(body: fixture('histories.json'))
34
+ end
35
+
36
+ let!(:histories) do
37
+ lelylan.all_histories(per: 10)
38
+ end
39
+
40
+ it 'returns the histories' do
41
+ histories.first.id.should_not be_nil
42
+ end
43
+
44
+ it 'sends the request' do
45
+ a_get('/histories').with(query: {per: 10}).should have_been_made
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,122 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Location do
4
+
5
+ let(:lelylan) do
6
+ a_client
7
+ end
8
+
9
+ describe '#location' do
10
+
11
+ before do
12
+ stub_get('/locations/1').to_return(body: fixture('location.json'))
13
+ end
14
+
15
+ let!(:location) do
16
+ lelylan.location('1')
17
+ end
18
+
19
+ it 'returns the location' do
20
+ location.id.should_not be_nil
21
+ end
22
+
23
+ it 'sends the request' do
24
+ a_get('/locations/1').should have_been_made
25
+ end
26
+ end
27
+
28
+
29
+ describe '#locations' do
30
+
31
+ before do
32
+ stub_get('/locations').to_return(body: fixture('locations.json'))
33
+ end
34
+
35
+ let!(:locations) do
36
+ lelylan.locations
37
+ end
38
+
39
+ it 'returns a list of locations' do
40
+ locations.should have(1).item
41
+ end
42
+
43
+ it 'sends the request' do
44
+ a_get('/locations').should have_been_made
45
+ end
46
+
47
+ context 'with params' do
48
+
49
+ before do
50
+ stub_get('/locations').with(query: { per: '25' }).to_return(body: fixture('location.json'))
51
+ end
52
+
53
+ before do
54
+ lelylan.locations(per: 25)
55
+ end
56
+
57
+ it 'sends the params' do
58
+ a_get('/locations').with(query: { per: '25' }).should have_been_made
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ describe '#create_location' do
65
+
66
+ before do
67
+ stub_post('/locations').with(body: { name: 'Bedroom' }).to_return(body: fixture('location.json'))
68
+ end
69
+
70
+ let!(:location) do
71
+ lelylan.create_location(name: 'Bedroom')
72
+ end
73
+
74
+ it 'returns the location' do
75
+ location.id.should_not be_nil
76
+ end
77
+
78
+ it 'sends the request' do
79
+ a_post('/locations').with(body: { name: 'Bedroom' }).should have_been_made
80
+ end
81
+ end
82
+
83
+
84
+ describe '#update_location' do
85
+
86
+ before do
87
+ stub_put('/locations/1').with(body: { name: 'Bedroom' }).to_return(body: fixture('location.json'))
88
+ end
89
+
90
+ let!(:location) do
91
+ lelylan.update_location('1', name: 'Bedroom')
92
+ end
93
+
94
+ it 'returns the location' do
95
+ location.id.should_not be_nil
96
+ end
97
+
98
+ it 'sends the request' do
99
+ a_put('/locations/1').with(body: { name: 'Bedroom' }).should have_been_made
100
+ end
101
+ end
102
+
103
+
104
+ describe '#delete_location' do
105
+
106
+ before do
107
+ stub_delete('/locations/1').to_return(body: fixture('location.json'))
108
+ end
109
+
110
+ let!(:location) do
111
+ lelylan.delete_location('1')
112
+ end
113
+
114
+ it 'returns the location' do
115
+ location.id.should_not be_nil
116
+ end
117
+
118
+ it 'sends the request' do
119
+ a_delete('/locations/1').should have_been_made
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Type do
4
+
5
+ let(:lelylan) do
6
+ Lelylan::Client.new
7
+ end
8
+
9
+ describe '#physical_properties' do
10
+
11
+ before do
12
+ stub_request(:put, 'http://mqtt.lelylan.com/devices/1').to_return(status: 202)
13
+ end
14
+
15
+ let!(:device) do
16
+ lelylan.physical_properties('http://mqtt.lelylan.com/devices/1', 'secret', { properties: {} })
17
+ end
18
+
19
+ it 'returns the type' do
20
+ device.should be_nil
21
+ end
22
+
23
+ it 'sends the request' do
24
+ stub_request(:put, 'http://mqtt.lelylan.com/devices/1').should have_been_made
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Profile do
4
+
5
+ let(:lelylan) do
6
+ a_client
7
+ end
8
+
9
+ describe '#me' do
10
+
11
+ before do
12
+ stub_get('/me').to_return(body: fixture('profile.json'))
13
+ end
14
+
15
+ let!(:profile) do
16
+ lelylan.me()
17
+ end
18
+
19
+ it 'returns the type' do
20
+ profile.id.should_not be_nil
21
+ end
22
+
23
+ it 'sends the request' do
24
+ a_get('/me').should have_been_made
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,159 @@
1
+ require 'helper'
2
+
3
+ describe Lelylan::Client::Property do
4
+
5
+
6
+ let(:lelylan) do
7
+ a_client
8
+ end
9
+
10
+ describe '#property' do
11
+
12
+ before do
13
+ stub_get('/properties/1').to_return(body: fixture('property.json'))
14
+ end
15
+
16
+ let!(:property) do
17
+ lelylan.property('1')
18
+ end
19
+
20
+ it 'returns the property' do
21
+ property.id.should_not be_nil
22
+ end
23
+
24
+ it 'sends the request' do
25
+ a_get('/properties/1').should have_been_made
26
+ end
27
+ end
28
+
29
+
30
+ describe '#properties' do
31
+
32
+ before do
33
+ stub_get('/properties').to_return(body: fixture('properties.json'))
34
+ end
35
+
36
+ let!(:properties) do
37
+ lelylan.properties
38
+ end
39
+
40
+ it 'returns a list of properties' do
41
+ properties.should have(1).item
42
+ end
43
+
44
+ it 'sends the request' do
45
+ a_get('/properties').should have_been_made
46
+ end
47
+
48
+ context 'with params' do
49
+
50
+ before do
51
+ stub_get('/properties').with(query: { per: '25' }).to_return(body: fixture('property.json'))
52
+ end
53
+
54
+ before do
55
+ lelylan.properties(per: 25)
56
+ end
57
+
58
+ it 'sends the params' do
59
+ a_get('/properties').with(query: { per: '25' }).should have_been_made
60
+ end
61
+ end
62
+ end
63
+
64
+
65
+ describe '#public_properties' do
66
+
67
+ before do
68
+ stub_get('/properties/public').to_return(body: fixture('properties.json'))
69
+ end
70
+
71
+ let!(:properties) do
72
+ lelylan.public_properties
73
+ end
74
+
75
+ it 'returns a list of properties' do
76
+ properties.should have(1).item
77
+ end
78
+
79
+ it 'sends the request' do
80
+ a_get('/properties/public').should have_been_made
81
+ end
82
+
83
+ context 'with params' do
84
+
85
+ before do
86
+ stub_get('/properties/public').with(query: { per: '25' }).to_return(body: fixture('property.json'))
87
+ end
88
+
89
+ before do
90
+ lelylan.public_properties(per: 25)
91
+ end
92
+
93
+ it 'sends the params' do
94
+ a_get('/properties/public').with(query: { per: '25' }).should have_been_made
95
+ end
96
+ end
97
+ end
98
+
99
+
100
+ describe '#create_property' do
101
+
102
+ before do
103
+ stub_post('/properties').with(body: { name: 'Status' }).to_return(body: fixture('property.json'))
104
+ end
105
+
106
+ let!(:property) do
107
+ lelylan.create_property(name: 'Status')
108
+ end
109
+
110
+ it 'returns the property' do
111
+ property.id.should_not be_nil
112
+ end
113
+
114
+ it 'sends the request' do
115
+ a_post('/properties').with(body: { name: 'Status' }).should have_been_made
116
+ end
117
+ end
118
+
119
+
120
+ describe '#update_property' do
121
+
122
+ before do
123
+ stub_put('/properties/1').with(body: { name: 'Status' }).to_return(body: fixture('property.json'))
124
+ end
125
+
126
+ let!(:property) do
127
+ lelylan.update_property('1', name: 'Status')
128
+ end
129
+
130
+ it 'returns the property' do
131
+ property.id.should_not be_nil
132
+ end
133
+
134
+ it 'sends the request' do
135
+ a_put('/properties/1').with(body: { name: 'Status' }).should have_been_made
136
+ end
137
+ end
138
+
139
+
140
+ describe '#delete_property' do
141
+
142
+ before do
143
+ stub_delete('/properties/1').to_return(body: fixture('property.json'))
144
+ end
145
+
146
+ let!(:property) do
147
+ lelylan.delete_property('1')
148
+ end
149
+
150
+ it 'returns the property' do
151
+ property.id.should_not be_nil
152
+ end
153
+
154
+ it 'sends the request' do
155
+ a_delete('/properties/1').should have_been_made
156
+ end
157
+ end
158
+ end
159
+