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 @@
1
+ console.log('This would be the main JS file.');
data/lelylan_rb.gemspec CHANGED
@@ -2,35 +2,34 @@
2
2
  require File.expand_path('../lib/lelylan/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
+
6
+ gem.authors = ["Andrea Reginato"]
7
+ gem.description = %q{Ruby wrapper for Lelylan API}
8
+ gem.email = ['touch@lelylan.com']
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.homepage = 'https://github.com/lelylan/lelylan-rb'
11
+ gem.name = 'lelylan-rb'
12
+ gem.version = Lelylan::Version
13
+
5
14
  gem.add_dependency 'addressable', '~> 2.2'
6
15
  gem.add_dependency 'oauth2', '~> 0.8'
7
16
  gem.add_dependency 'faraday', '~> 0.8'
8
17
  gem.add_dependency 'faraday_middleware', '~> 0.8'
9
18
  gem.add_dependency 'hashie', '~> 1.2'
10
19
  gem.add_dependency 'multi_json', '~> 1.3'
20
+
11
21
  gem.add_development_dependency 'json'
12
- gem.add_development_dependency 'maruku'
13
22
  gem.add_development_dependency 'rake'
14
23
  gem.add_development_dependency 'rspec'
15
- gem.add_development_dependency 'simplecov'
16
24
  gem.add_development_dependency 'webmock'
17
25
  gem.add_development_dependency 'guard-rspec'
18
26
  gem.add_development_dependency 'fuubar'
19
27
  gem.add_development_dependency 'growl'
20
- gem.add_development_dependency 'yard'
21
- gem.add_development_dependency 'yard-tomdoc'
22
- gem.add_development_dependency 'redcarpet'
23
- gem.add_development_dependency 'github-markup'
24
- gem.authors = ["Andrea Reginato"]
25
- gem.description = %q{Ruby wrapper for Lelylan API}
26
- gem.email = ['touch@lelylan.com']
27
- gem.files = `git ls-files`.split("\n")
28
- gem.homepage = 'https://github.com/lelylan/lelylan-rb'
29
- gem.name = 'lelylan-rb'
28
+ gem.add_development_dependency 'rb-fsevent'
29
+
30
30
  gem.platform = Gem::Platform::RUBY
31
31
  gem.require_paths = ['lib']
32
32
  gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
33
33
  gem.summary = gem.description
34
34
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
35
- gem.version = Lelylan::Version
36
35
  end
@@ -2,15 +2,16 @@ require 'lelylan/authentication'
2
2
  require 'lelylan/connection'
3
3
  require 'lelylan/request'
4
4
 
5
- require 'lelylan/client/devices'
6
- require 'lelylan/client/consumptions'
7
- require 'lelylan/client/histories'
8
- require 'lelylan/client/types'
9
- require 'lelylan/client/properties'
10
- require 'lelylan/client/functions'
11
- require 'lelylan/client/statuses'
12
- require 'lelylan/client/categories'
13
- require 'lelylan/client/locations'
5
+ require 'lelylan/client/profile'
6
+ require 'lelylan/client/device'
7
+ require 'lelylan/client/history'
8
+ require 'lelylan/client/type'
9
+ require 'lelylan/client/property'
10
+ require 'lelylan/client/function'
11
+ require 'lelylan/client/status'
12
+ require 'lelylan/client/location'
13
+ require 'lelylan/client/subscription'
14
+ require 'lelylan/client/physical'
14
15
 
15
16
  module Lelylan
16
17
  class Client
@@ -23,25 +24,21 @@ module Lelylan
23
24
  end
24
25
  end
25
26
 
26
- # helper method
27
- def find_id(uri)
28
- Addressable::URI.parse(uri).basename
29
- end
30
-
31
27
  # structure related
32
28
  include Lelylan::Authentication
33
29
  include Lelylan::Connection
34
30
  include Lelylan::Request
35
31
 
36
32
  # client related
37
- include Lelylan::Client::Devices
38
- include Lelylan::Client::Consumptions
39
- include Lelylan::Client::Histories
40
- include Lelylan::Client::Types
41
- include Lelylan::Client::Properties
42
- include Lelylan::Client::Functions
43
- include Lelylan::Client::Statuses
44
- include Lelylan::Client::Categories
45
- include Lelylan::Client::Locations
33
+ include Lelylan::Client::Profile
34
+ include Lelylan::Client::Device
35
+ include Lelylan::Client::History
36
+ include Lelylan::Client::Type
37
+ include Lelylan::Client::Property
38
+ include Lelylan::Client::Function
39
+ include Lelylan::Client::Status
40
+ include Lelylan::Client::Location
41
+ include Lelylan::Client::Subscription
42
+ include Lelylan::Client::Physical
46
43
  end
47
44
  end
@@ -0,0 +1,121 @@
1
+ module Lelylan
2
+ class Client
3
+ module Device
4
+
5
+ #
6
+ # Public: Returns extended information for a given device identified from its ID.
7
+ #
8
+ # id - A String that represent the device ID.
9
+ #
10
+ # Returns Hashie The device.
11
+ #
12
+ def device(id)
13
+ get("/devices/#{id}")
14
+ end
15
+
16
+ #
17
+ # Public: Returns extended information for a given device identified from its ID.
18
+ #
19
+ # id - A String that represent the device ID.
20
+ #
21
+ # Returns Hashie The device.
22
+ #
23
+ def device_privates(id)
24
+ get("/devices/#{id}/privates")
25
+ end
26
+
27
+ #
28
+ # Public: Returns a list of owned devices.
29
+ #
30
+ # params - The Hash used to refine the search (default: {}).
31
+ #
32
+ # Returns Array List of devices.
33
+ #
34
+ def devices(params = {})
35
+ get('/devices', params)
36
+ end
37
+
38
+ #
39
+ # Public: Create a device and returns extended information for it.
40
+ #
41
+ # params - The Hash used to create the resource (default: {}).
42
+ #
43
+ # Returns Hashie The created device.
44
+ #
45
+ def create_device(params = {})
46
+ post('/devices', params)
47
+ end
48
+
49
+ #
50
+ # Public: Update a device identified from its ID and returns extended information for it.
51
+ #
52
+ # id - A String that represent the device ID.
53
+ # params - The Hash used to update the resource (default: {}).
54
+ #
55
+ # Returns Hashie The updated device.
56
+ #
57
+ def update_device(id, params = {})
58
+ put("/devices/#{id}", params)
59
+ end
60
+
61
+ #
62
+ # Public: Delete a device identified from its ID and returns extended information for it.
63
+ #
64
+ # id - A String that represent the device ID.
65
+ #
66
+ # Returns Hashie The deleted device.
67
+ #
68
+ def delete_device(id)
69
+ delete("/devices/#{id}")
70
+ end
71
+
72
+ #
73
+ # Public: Execute a function on a device identified from its ID and returns
74
+ # extended information for it.
75
+ #
76
+ # id - A String that represent the device ID.
77
+ # params - An Hash containing the function to execute and the device properties.
78
+ #
79
+ # Returns Hashie The device with the updated properties.
80
+ #
81
+ def execute(id, params={})
82
+ put("/devices/#{id}/functions", params)
83
+ end
84
+
85
+ #
86
+ # Public: Update properties on a device identified from its ID and returns
87
+ # extended information for it.
88
+ #
89
+ # id - A String that represent the device ID.
90
+ # params - An Hash containing the device properties.
91
+ #
92
+ # Returns Hashie The device with the updated properties.
93
+ #
94
+ def device_properties(id, params={})
95
+ put("/devices/#{id}/properties", params)
96
+ end
97
+
98
+ #
99
+ # Public: Activate a device and returns extended information for it.
100
+ #
101
+ # params - A Hash containing the activation code.
102
+ #
103
+ # Returns Hashie The activated device.
104
+ #
105
+ def activate_device(params = {})
106
+ post('/activations', params)
107
+ end
108
+
109
+ #
110
+ # Public: Deactivate a device and returns extended information for it.
111
+ #
112
+ # activation_code - A String that represents the activation_code.
113
+ #
114
+ # Returns Hashie The activated device.
115
+ #
116
+ def deactivate_device(activation_code)
117
+ delete("/activations/#{activation_code}")
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,73 @@
1
+ module Lelylan
2
+ class Client
3
+ module Function
4
+
5
+ #
6
+ # Public: Returns extended information for a given function identified from its ID.
7
+ #
8
+ # id - A String that represent the function ID.
9
+ #
10
+ # Returns Hashie The function.
11
+ #
12
+ def function(id)
13
+ get("/functions/#{id}")
14
+ end
15
+
16
+ #
17
+ # Public: Returns a list of owned functions.
18
+ #
19
+ # params - The Hash used to refine the search (default: {}).
20
+ #
21
+ # Returns Array List of functions.
22
+ #
23
+ def functions(params = {})
24
+ get('/functions', params)
25
+ end
26
+
27
+ #
28
+ # Public: Returns a list of all existing functions.
29
+ #
30
+ # params - The Hash used to refine the search (default: {}).
31
+ #
32
+ # Returns Array List of functions.
33
+ #
34
+ def public_functions(params = {})
35
+ get('/functions/public', params)
36
+ end
37
+
38
+ #
39
+ # Public: Create a function and returns extended information for it.
40
+ #
41
+ # params - The Hash used to create the resource (default: {}).
42
+ #
43
+ # Returns Hashie The created function.
44
+ #
45
+ def create_function(params = {})
46
+ post('/functions', params)
47
+ end
48
+
49
+ #
50
+ # Public: Update a function identified from its ID and returns extended information for it.
51
+ #
52
+ # id - A String that represent the function ID.
53
+ # params - The Hash used to update the resource (default: {}).
54
+ #
55
+ # Returns Hashie The updated function.
56
+ #
57
+ def update_function(id, params = {})
58
+ put("/functions/#{id}", params)
59
+ end
60
+
61
+ #
62
+ # Public: Delete a function identified from its ID and returns extended information for it.
63
+ #
64
+ # id - A String that represent the function ID.
65
+ #
66
+ # Returns Hashie The deleted function.
67
+ #
68
+ def delete_function(id)
69
+ delete("/functions/#{id}")
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ module Lelylan
2
+ class Client
3
+ module History
4
+
5
+ #
6
+ # Public: Returns extended information for a given history identified from its ID.
7
+ #
8
+ # id - A String that represent the history ID.
9
+ #
10
+ # Returns Hashie The history.
11
+ #
12
+ def find_history(id)
13
+ get("/histories/#{id}")
14
+ end
15
+
16
+ #
17
+ # Public: Returns a list of histories related to owned devices.
18
+ #
19
+ # params - The Hash used to refine the search (default: {}).
20
+ #
21
+ # Returns Array List of histories.
22
+ #
23
+ def all_histories(params = {})
24
+ get('/histories', params)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,62 @@
1
+ module Lelylan
2
+ class Client
3
+ module Location
4
+
5
+ #
6
+ # Public: Returns extended information for a given location identified from its ID.
7
+ #
8
+ # id - A String that represent the location ID.
9
+ #
10
+ # Returns Hashie The location.
11
+ #
12
+ def location(id)
13
+ get("/locations/#{id}")
14
+ end
15
+
16
+ #
17
+ # Public: Returns a list of owned locations.
18
+ #
19
+ # params - The Hash used to refine the search (default: {}).
20
+ #
21
+ # Returns Array List of locations.
22
+ #
23
+ def locations(params = {})
24
+ get('/locations', params)
25
+ end
26
+
27
+ #
28
+ # Public: Create a location and returns extended information for it.
29
+ #
30
+ # params - The Hash used to create the resource (default: {}).
31
+ #
32
+ # Returns Hashie The created location.
33
+ #
34
+ def create_location(params = {})
35
+ post('/locations', params)
36
+ end
37
+
38
+ #
39
+ # Public: Update a location identified from its ID and returns extended information for it.
40
+ #
41
+ # id - A String that represent the location ID.
42
+ # params - The Hash used to update the resource (default: {}).
43
+ #
44
+ # Returns Hashie The updated location.
45
+ #
46
+ def update_location(id, params = {})
47
+ put("/locations/#{id}", params)
48
+ end
49
+
50
+ #
51
+ # Public: Delete a location identified from its ID and returns extended information for it.
52
+ #
53
+ # id - A String that represent the location ID.
54
+ #
55
+ # Returns Hashie The deleted location.
56
+ #
57
+ def delete_location(id)
58
+ delete("/locations/#{id}")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+ require 'openssl'
3
+ require 'securerandom'
4
+ require 'json'
5
+ require 'lelylan/authentication'
6
+
7
+ module Lelylan
8
+ class Client
9
+ module Physical
10
+
11
+ #
12
+ # Public: Send a request adding a nonce and a X-Physical-Signature
13
+ # header.
14
+ #
15
+ # uri - A String that represents the uri of the physical device.
16
+ # secret - The device secret.
17
+ # params - An object containing the JSON params to send.
18
+ #
19
+ # Returns Hashie The JSON resource.
20
+ #
21
+ def physical_properties(uri, secret, params)
22
+ params[:nonce] = SecureRandom.uuid if not params[:nonce]
23
+
24
+ digest = OpenSSL::Digest::Digest.new('sha1')
25
+ signature = OpenSSL::HMAC.hexdigest(digest, secret, params.to_json.to_s)
26
+ headers = { 'X-Physical-Signature' => signature, 'Content-Type' => 'application/json' }
27
+
28
+ request = Faraday.new
29
+ response = request.put(uri, params, headers)
30
+ response.body
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ module Lelylan
2
+ class Client
3
+ module Profile
4
+
5
+ #
6
+ # Public: Returns extended information for a given type identified from its ID.
7
+ #
8
+ # id - A String that represent the type ID.
9
+ #
10
+ # Returns Hashie The type.
11
+ #
12
+ def me()
13
+ get('/me')
14
+ end
15
+ end
16
+ end
17
+ end