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,42 @@
1
+ module Lelylan
2
+ class Client
3
+ module Histories
4
+
5
+ # Public: Returns extended information for a given history identified from its URI.
6
+ # Find more at {http://dev.lelylan.com/rest/devices/history/#get Lelylan Dev Center}.
7
+ #
8
+ # history - A String that represents the history URI.
9
+ #
10
+ # Returns Hashie The history resource.
11
+ #
12
+ # Examples
13
+ #
14
+ # history = "http://api.lelylan.com/histories/4dcb9e23d033a9088900200f"
15
+ # client.history(history)
16
+ #
17
+ def history(history)
18
+ get("/histories/#{find_id(history)}")
19
+ end
20
+
21
+ # Public: Returns a list of history resources for a given device identified from its URI.
22
+ # Find more at {http://dev.lelylan.com/rest/devices/history/#all Lelylan Dev Center}.
23
+ #
24
+ # device - A String that represents the device URI.
25
+ # options - The Hash option used to refine the search (default: {}).
26
+ # Check out the {http://dev.lelylan.com/rest/devices/history/#all API doc} for the accepted options.
27
+ #
28
+ # Returns Hashie List of histories.
29
+ #
30
+ # Examples
31
+ #
32
+ # # Returns the first 10 histories for a specific device)
33
+ # device = "http://api.lelyla.com/devices/4dcb9e23d033a9088900023b"
34
+ # client.histories(device, per: 10)
35
+ #
36
+ #
37
+ def histories(device, options = {})
38
+ get("/devices/#{find_id(device)}/histories", options)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,92 @@
1
+ module Lelylan
2
+ class Client
3
+ module Locations
4
+
5
+ # Public: Returns extended information for a given location identified from its URI.
6
+ # Find more at {http://dev.lelylan.com/rest/locations/#get Lelylan Dev Center}.
7
+ #
8
+ # location - A String that represent the location URI.
9
+ #
10
+ # Returns Hashie The location.
11
+ #
12
+ # Examples
13
+ #
14
+ # location = "http://api.lelylan.com/location/4dcb9e23d033a9088902200a"
15
+ # client.location(location)
16
+ #
17
+ def location(location)
18
+ get("/locations/#{find_id(location)}")
19
+ end
20
+
21
+ # Public: Returns extended information for a given location identified from its URI.
22
+ # Find more at {http://dev.lelylan.com/rest/locations/#all Lelylan Dev Center}.
23
+ #
24
+ # options - The Hash option used to refine the search (default: {}).
25
+ # Check out the {http://dev.lelylan.com/rest/locations/#all API doc} for the accepted options.
26
+ #
27
+ # Returns Hashie List of locations.
28
+ #
29
+ # Examples
30
+ #
31
+ # # Retrurns the first 10 locations
32
+ # client.locations(per: 10)
33
+ #
34
+ # # Returns the device locations from yesterday till now
35
+ # client.locations(type: 'room')
36
+ #
37
+ def locations(options = {})
38
+ get("/locations", options)
39
+ end
40
+
41
+ # Public: Create a location and returns extended information for it.
42
+ # Find more at {http://dev.lelylan.com/rest/locations/#create Lelylan Dev Center}.
43
+ #
44
+ # options - The Hash option used to create the resource (default: {}).
45
+ # Check out the {http://dev.lelylan.com/rest/location/#create API doc} for the accepted options.
46
+ #
47
+ # Returns Hashie The created location.
48
+ #
49
+ # Examples
50
+ #
51
+ # client.create_location(name: 'Kids bedroom', type: 'room')
52
+ #
53
+ def create_location(options = {})
54
+ post("/locations", options)
55
+ end
56
+
57
+ # Public: Update a location identified from its URI and returns extended information for it.
58
+ # Find more at {http://dev.lelylan.com/rest/locations/#update Lelylan Dev Center}.
59
+ #
60
+ # location - A String that represent the location URI.
61
+ # options - The Hash option used to update the resource (default: {}).
62
+ # Check out the {http://dev.lelylan.com/rest/locations/#update API doc} for the accepted options.
63
+ #
64
+ # Returns Hashie The updated location.
65
+ #
66
+ # Examples
67
+ #
68
+ # location = "http://api.lelylan.com/locations/4dcb9e23d033a9088902200a"
69
+ # client.update_location(location, name: 'Big mama bedroom')
70
+ #
71
+ def update_location(location, options = {})
72
+ put("/locations/#{find_id(location)}", options)
73
+ end
74
+
75
+ # Public: Delete a location identified from its URI and returns extended information for it.
76
+ # Find more at {http://dev.lelylan.com/rest/locations/#delete Lelylan Dev Center}.
77
+ #
78
+ # location - A String that represent the location URI.
79
+ #
80
+ # Returns Hashie The deleted location.
81
+ #
82
+ # Examples
83
+ #
84
+ # location = "http://api.lelyla.com/locations/4dcb9e23d033a9088902200a"
85
+ # client.delete_location(location)
86
+ #
87
+ def delete_location(location)
88
+ delete("/locations/#{find_id(location)}")
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,115 @@
1
+ module Lelylan
2
+ class Client
3
+ module Properties
4
+
5
+ # Public: Returns extended information for a given property identified from its URI.
6
+ # Find more at {http://dev.lelylan.com/rest/types/properties/#get Lelylan Dev Center}.
7
+ #
8
+ # property - A String that represent the property URI.
9
+ #
10
+ # Returns Hashie The property.
11
+ #
12
+ # Examples
13
+ #
14
+ # property = "http://api.lelylan.com/properties/4dcb9e23d033a9088902200a"
15
+ # client.property(property)
16
+ #
17
+ def property(property)
18
+ get("/properties/#{find_id(property)}")
19
+ end
20
+
21
+ # Public: Returns a list of properties.
22
+ # Find more at {http://dev.lelylan.com/rest/types/properties/#all Lelylan Dev Center}.
23
+ #
24
+ # options - The Hash option used to refine the search (default: {}).
25
+ # Check out the {http://dev.lelylan.com/rest/types/properties/#all API doc} for the accepted options.
26
+ #
27
+ # Returns Hashie List of properties.
28
+ #
29
+ # Examples
30
+ #
31
+ # # Retrurns the first 10 properties
32
+ # client.properties(per: 10)
33
+ #
34
+ # # Returns the properties where the name match with the desired string
35
+ # client.properties(name: 'Intensity')
36
+ #
37
+ def properties(options = {})
38
+ get("/properties", options)
39
+ end
40
+
41
+ # Public: Returns a list of properties.
42
+ # Find more at {http://dev.lelylan.com/rest/properties/properties/#all Lelylan Dev Center}.
43
+ #
44
+ # options - The Hash option used to refine the search (default: {}).
45
+ # Check out the {http://dev.lelylan.com/rest/properties/properties/#all API doc} for the accepted options.
46
+ #
47
+ # Returns Hashie List of properties.
48
+ #
49
+ # Examples
50
+ #
51
+ # # Retrurns the first 10 properties
52
+ # client.properties(per: 10)
53
+ #
54
+ # # Returns the properties where the name match with the desired string
55
+ # client.properties(name: 'Intensity')
56
+ #
57
+ def public_properties(options = {})
58
+ get("/properties/public", options)
59
+ end
60
+
61
+ # Public: Create a property and returns extended information for it.
62
+ # Find more at {http://dev.lelylan.com/rest/types/properties/#create Lelylan Dev Center}.
63
+ #
64
+ # options - The Hash option used to create the resource (default: {}).
65
+ # Check out the {http://dev.lelylan.com/rest/types/properties/#create API doc} for the accepted options.
66
+ #
67
+ # Returns Hashie The created property.
68
+ #
69
+ # Examples
70
+ #
71
+ # values = 1..100.to_a # [0, 1, 2, 3, 4, ..., 99, 100]
72
+ # client.create_property(name: 'Intensity', default: '0', values: values)
73
+ #
74
+ def create_property(options = {})
75
+ post("/properties", options)
76
+ end
77
+
78
+ # Public: Update a property identified from its URI and returns extended information for it.
79
+ # Find more at {http://dev.lelylan.com/rest/types/properties/#update Lelylan Dev Center}.
80
+ #
81
+ # property - A String that represents the property URI.
82
+ # options - The Hash option used to update the resource (default: {}).
83
+ # Check out the {http://dev.lelylan.com/rest/types/properties/#update API doc} for the accepted options.
84
+ #
85
+ # Returns Hashie The updated property.
86
+ #
87
+ # Examples
88
+ #
89
+ # property = "http://api.lelylan.com/properties/4dcb9e23d033a9088902200a"
90
+ # client.update_property(property, default: '100')
91
+ #
92
+ def update_property(property, options = {})
93
+ put("/properties/#{find_id(property)}", options)
94
+ end
95
+
96
+ # Public: Delete a property identified from its URI and returns extended information for it.
97
+ # Find more at {http://dev.lelylan.com/rest/types/properties/#delete Lelylan Dev Center}.
98
+ #
99
+ # property - A String that represent the property URI.
100
+ #
101
+ # Returns Hashie The deleted property.
102
+ #
103
+ # Examples
104
+ #
105
+ # property = "http://api.lelylan.com/properties/4dcb9e23d033a9088902200a"
106
+ # client.delete_property(property)
107
+ #
108
+ def delete_property(property)
109
+ delete("/properties/#{find_id(property)}")
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+
@@ -0,0 +1,110 @@
1
+ module Lelylan
2
+ class Client
3
+ module Statuses
4
+
5
+ # Public: Returns extended information for a given status identified from its URI.
6
+ # Find more at {http://dev.lelylan.com/rest/types/statuses/#get Lelylan Dev Center}.
7
+ #
8
+ # status - A String that represent the status URI.
9
+ #
10
+ # Returns Hashie The status.
11
+ #
12
+ # Examples
13
+ #
14
+ # status = "http://api.lelylan.com/statuses/4dcb9e23d033a9088902200a"
15
+ # client.status(status)
16
+ #
17
+ def status(status)
18
+ get("/statuses/#{find_id(status)}")
19
+ end
20
+
21
+ # Public: Returns a list of statuses.
22
+ # Find more at {http://dev.lelylan.com/rest/types/statuses/#all Lelylan Dev Center}.
23
+ #
24
+ # options - The Hash option used to refine the search (default: {}).
25
+ # Check out the {http://dev.lelylan.com/rest/types/statuses/#all API doc} for the accepted options.
26
+ #
27
+ # Returns Hashie List of statuses.
28
+ #
29
+ # Examples
30
+ #
31
+ # # Retrurns the first 10 statuses
32
+ # client.statuses(per: 10)
33
+ #
34
+ # # Returns the statuses where the name match with the desired string
35
+ # client.statuses(name: 'Setting')
36
+ #
37
+ def statuses(options = {})
38
+ get("/statuses", options)
39
+ end
40
+
41
+ # Public: Returns a list of all public statuses.
42
+ # Find more at {http://dev.lelylan.com/rest/statuses/core/#all Lelylan Dev Center}.
43
+ #
44
+ # options - The Hash option used to refine the search (default: {}).
45
+ # Check out the {http://dev.lelylan.com/rest/devices/statuses/#all API doc} for the accepted options.
46
+ #
47
+ # Returns Hashie List of statuses.
48
+ #
49
+ # Examples
50
+ #
51
+ # # Retrurns the first 10 public statuses
52
+ # client.public_statuses(per: 10)
53
+ #
54
+ def public_statuses(options = {})
55
+ get("/statuses/public", options)
56
+ end
57
+
58
+ # Public: Create a status and returns extended information for it.
59
+ # Find more at {http://dev.lelylan.com/rest/types/statuses/#create Lelylan Dev Center}.
60
+ #
61
+ # options - The Hash option used to create the resource (default: {}).
62
+ # Check out the {http://dev.lelylan.com/rest/types/statuses/#create API doc} for the accepted options.
63
+ #
64
+ # Returns Hashie The created status.
65
+ #
66
+ # Examples
67
+ #
68
+ # client.create_status(name: 'Setting status')
69
+ #
70
+ def create_status(options = {})
71
+ post("/statuses", options)
72
+ end
73
+
74
+ # Public: Update a status identified from its URI and returns extended information for it.
75
+ # Find more at {http://dev.lelylan.com/rest/types/statuses/#update Lelylan Dev Center}.
76
+ #
77
+ # status - A String that represents the status URI.
78
+ # options - The Hash option used to update the resource (default: {}).
79
+ # Check out the {http://dev.lelylan.com/rest/types/statuses/#update API doc} for the accepted options.
80
+ #
81
+ # Returns Hashie The updated status.
82
+ #
83
+ # Examples
84
+ #
85
+ # status = "http://api.lelylan.com/statuses/4dcb9e23d033a9088902200a"
86
+ # client.update_status(status, pending: true)
87
+ #
88
+ def update_status(status, options = {})
89
+ put("/statuses/#{find_id(status)}", options)
90
+ end
91
+
92
+ # Public: Delete a status identified from its URI and returns extended information for it.
93
+ # Find more at {http://dev.lelylan.com/rest/types/statuses/#delete Lelylan Dev Center}.
94
+ #
95
+ # status - A String that represent the status URI.
96
+ #
97
+ # Returns Hashie The deleted status.
98
+ #
99
+ # Examples
100
+ #
101
+ # status = "http://api.lelylan.com/statuses/4dcb9e23d033a9088902200a"
102
+ # client.delete_status(status)
103
+ #
104
+ def delete_status(status)
105
+ delete("/statuses/#{find_id(status)}")
106
+ end
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,109 @@
1
+ module Lelylan
2
+ class Client
3
+ module Types
4
+
5
+ # Public: Returns extended information for a given type identified from its URI.
6
+ # Find more at {http://dev.lelylan.com/rest/types/core/#get Lelylan Dev Center}.
7
+ #
8
+ # type - A String that represent the type URI.
9
+ #
10
+ # Returns Hashie The type.
11
+ #
12
+ # Examples
13
+ #
14
+ # type = "http://api.lelylan.com/types/4dcb9e23d033a9088902200a"
15
+ # client.type(type)
16
+ #
17
+ def type(type)
18
+ get("/types/#{find_id(type)}")
19
+ end
20
+
21
+ # Public: Returns a list of owned types.
22
+ # Find more at {http://dev.lelylan.com/rest/types/core/#all Lelylan Dev Center}.
23
+ #
24
+ # options - The Hash option used to refine the search (default: {}).
25
+ # Check out the {http://dev.lelylan.com/rest/devices/types/#all API doc} for the accepted options.
26
+ #
27
+ # Returns Hashie List of types.
28
+ #
29
+ # Examples
30
+ #
31
+ # # Retrurns the first 10 types
32
+ # client.types(per: 10)
33
+ #
34
+ # # Returns the types where the name match with the desired string
35
+ # client.types(name: 'dimmer')
36
+ #
37
+ def types(options = {})
38
+ get("/types", options)
39
+ end
40
+
41
+ # Public: Returns a list of all public types.
42
+ # Find more at {http://dev.lelylan.com/rest/types/core/#all Lelylan Dev Center}.
43
+ #
44
+ # options - The Hash option used to refine the search (default: {}).
45
+ # Check out the {http://dev.lelylan.com/rest/devices/types/#all API doc} for the accepted options.
46
+ #
47
+ # Returns Hashie List of types.
48
+ #
49
+ # Examples
50
+ #
51
+ # # Retrurns the first 10 public types
52
+ # client.public_types(per: 10)
53
+ #
54
+ def public_types(options = {})
55
+ get("/types/public", options)
56
+ end
57
+
58
+ # Public: Create a type and returns extended information for it.
59
+ # Find more at {http://dev.lelylan.com/rest/types/core/#create Lelylan Dev Center}.
60
+ #
61
+ # options - The Hash option used to create the resource (default: {}).
62
+ # Check out the {http://dev.lelylan.com/rest/types/core/#create API doc} for the accepted options.
63
+ #
64
+ # Returns Hashie The created type.
65
+ #
66
+ # Examples
67
+ #
68
+ # client.create_type(name: 'Dimmer')
69
+ #
70
+ def create_type(options = {})
71
+ post("/types", options)
72
+ end
73
+
74
+ # Public: Update a type identified from its URI and returns extended information for it.
75
+ # Find more at {http://dev.lelylan.com/rest/types/core/#update Lelylan Dev Center}.
76
+ #
77
+ # type - A String that represents the type URI.
78
+ # options - The Hash option used to update the resource (default: {}).
79
+ # Check out the {http://dev.lelylan.com/rest/types/core/#update API doc} for the accepted options.
80
+ #
81
+ # Returns Hashie The updated type.
82
+ #
83
+ # Examples
84
+ #
85
+ # type = "http://api.lelylan.com/types/4dcb9e23d033a9088902200a"
86
+ # client.update_type(type, name: 'RGB Dimmer')
87
+ #
88
+ def update_type(type, options = {})
89
+ put("/types/#{find_id(type)}", options)
90
+ end
91
+
92
+ # Public: Delete a type identified from its URI and returns extended information for it.
93
+ # Find more at {http://dev.lelylan.com/rest/types/core/#delete Lelylan Dev Center}.
94
+ #
95
+ # type - A String that represent the type URI.
96
+ #
97
+ # Returns Hashie The deleted type.
98
+ #
99
+ # Examples
100
+ #
101
+ # type = "http://api.lelylan.com/types/4dcb9e23d033a9088902200a"
102
+ # client.delete_type(type)
103
+ #
104
+ def delete_type(type)
105
+ delete("/types/#{find_id(type)}")
106
+ end
107
+ end
108
+ end
109
+ end