hue 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad60609e78dfac717ff59ed735c6ec9c309f8faa
4
- data.tar.gz: 0d2fc9f44ae1279957886998ba2ce97ca5880b55
3
+ metadata.gz: c7a23b14e8208a859509d097fef847c13d57d182
4
+ data.tar.gz: 2e272e991cf0e356918d0ece627ebabb85e2c24a
5
5
  SHA512:
6
- metadata.gz: eb07141d9c06f26184b2f97ff74a4ac233fdd51a6619f08269ccec08a0091c13410106595a36b49615aef7cb41fb213704d0108de26aa639583d82e210f750ba
7
- data.tar.gz: ff655b5c6066d7c6ca4af4317f4b172f84ce4cc846005c9684e31686ad5d27db45fd95ee31fc1a71b9e66720d0b76f70bfeb50a1a14bb67c19286a5a85c1b060
6
+ metadata.gz: 1afc23c78f02b7a51531c38bb83a35c09d2fbf797ade300209c2b59ce6cefa4860a0b9647d1b82db83b7b8a107e1434faf55952e5d726d355ab7f51391828b74
7
+ data.tar.gz: 74a25b2a7c6cd6cc19c126dc151f541ff70c1e769b8b4aea24448c170f2c5f967b100c22785a30eb08ca1ff55fba21c28ca8df2fd0db9df8a3fe0f5f8b21f20a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Sam Soffes
1
+ Copyright (c) 2013-2014 Sam Soffes, http://soff.es
2
2
 
3
3
  MIT License
4
4
 
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.required_ruby_version = '>= 1.8.7'
22
- spec.add_dependency 'multi_json'
23
22
  spec.add_dependency 'thor'
23
+ spec.add_dependency 'json'
24
24
  end
@@ -68,6 +68,22 @@ module Hue
68
68
  unpack(json)
69
69
  end
70
70
 
71
+ def lights
72
+ @lights ||= begin
73
+ json = JSON(Net::HTTP.get(URI.parse("http://#{ip}/api/#{@client.username}")))
74
+ json['lights'].map do |key, value|
75
+ Light.new(@client, self, key, value)
76
+ end
77
+ end
78
+ end
79
+
80
+ def add_lights
81
+ uri = URI.parse("http://#{ip}/api/#{@client.username}/lights")
82
+ http = Net::HTTP.new(uri.host)
83
+ response = http.request_post(uri.path, nil)
84
+ (response.body).first
85
+ end
86
+
71
87
  private
72
88
 
73
89
  KEYS_MAP = {
@@ -85,7 +101,6 @@ module Hue
85
101
  }
86
102
 
87
103
  def unpack(hash)
88
- puts hash
89
104
  KEYS_MAP.each do |local_key, remote_key|
90
105
  value = hash[remote_key.to_s]
91
106
  next unless value
@@ -94,7 +109,7 @@ module Hue
94
109
  end
95
110
 
96
111
  def get_configuration
97
- MultiJson.load(Net::HTTP.get(URI.parse("#{base_url}/config")))
112
+ JSON(Net::HTTP.get(URI.parse("#{base_url}/config")))
98
113
  end
99
114
 
100
115
  def base_url
@@ -1,5 +1,5 @@
1
1
  require 'net/http'
2
- require 'multi_json'
2
+ require 'json'
3
3
 
4
4
  module Hue
5
5
  class Client
@@ -24,7 +24,7 @@ module Hue
24
24
  def bridges
25
25
  @bridges ||= begin
26
26
  bs = []
27
- MultiJson.load(Net::HTTP.get(URI.parse('http://www.meethue.com/api/nupnp'))).each do |hash|
27
+ JSON(Net::HTTP.get(URI.parse('https://www.meethue.com/api/nupnp'))).each do |hash|
28
28
  bs << Bridge.new(self, hash)
29
29
  end
30
30
  bs
@@ -32,21 +32,11 @@ module Hue
32
32
  end
33
33
 
34
34
  def lights
35
- @lights ||= begin
36
- ls = []
37
- json = MultiJson.load(Net::HTTP.get(URI.parse("http://#{bridge.ip}/api/#{@username}")))
38
- json['lights'].each do |key, value|
39
- ls << Light.new(self, bridge, key, value)
40
- end
41
- ls
42
- end
35
+ bridge.lights
43
36
  end
44
37
 
45
38
  def add_lights
46
- uri = URI.parse("http://#{bridge.ip}/api/#{@username}/lights")
47
- http = Net::HTTP.new(uri.host)
48
- response = http.request_post(uri.path, nil)
49
- MultiJson.load(response.body).first
39
+ bridge.add_lights
50
40
  end
51
41
 
52
42
  def light(id)
@@ -56,7 +46,7 @@ module Hue
56
46
  private
57
47
 
58
48
  def validate_user
59
- response = MultiJson.load(Net::HTTP.get(URI.parse("http://#{bridge.ip}/api/#{@username}")))
49
+ response = JSON(Net::HTTP.get(URI.parse("http://#{bridge.ip}/api/#{@username}")))
60
50
 
61
51
  if response.is_a? Array
62
52
  response = response.first
@@ -76,7 +66,7 @@ module Hue
76
66
 
77
67
  uri = URI.parse("http://#{bridge.ip}/api")
78
68
  http = Net::HTTP.new(uri.host)
79
- response = MultiJson.load(http.request_post(uri.path, MultiJson.dump(body)).body).first
69
+ response = JSON(http.request_post(uri.path, JSON.dump(body)).body).first
80
70
 
81
71
  if error = response['error']
82
72
  parse_error(error)
@@ -99,8 +99,8 @@ module Hue
99
99
 
100
100
  uri = URI.parse(base_url)
101
101
  http = Net::HTTP.new(uri.host)
102
- response = http.request_put(uri.path, MultiJson.dump(body))
103
- response = MultiJson.load(response.body).first
102
+ response = http.request_put(uri.path, JSON.dump(body))
103
+ response = JSON(response.body).first
104
104
  if response['success']
105
105
  @name = new_name
106
106
  # else
@@ -112,7 +112,7 @@ module Hue
112
112
  @state['on']
113
113
  end
114
114
 
115
- %w{on hue saturation brightness color_temperature}.each do |key|
115
+ %w{on hue saturation brightness color_temperature alert}.each do |key|
116
116
  define_method "#{key}=".to_sym do |value|
117
117
  set_state({key.to_sym => value})
118
118
  instance_variable_set("@#{key}".to_sym, value)
@@ -143,13 +143,13 @@ module Hue
143
143
 
144
144
  uri = URI.parse("#{base_url}/state")
145
145
  http = Net::HTTP.new(uri.host)
146
- response = http.request_put(uri.path, MultiJson.dump(body))
147
- MultiJson.load(response.body)
146
+ response = http.request_put(uri.path, JSON.dump(body))
147
+ JSON(response.body)
148
148
  end
149
149
 
150
150
  # Refresh the state of the lamp
151
151
  def refresh
152
- json = MultiJson.load(Net::HTTP.get(URI.parse(base_url)))
152
+ json = JSON(Net::HTTP.get(URI.parse(base_url)))
153
153
  unpack(json)
154
154
  end
155
155
 
@@ -1,3 +1,3 @@
1
1
  module Hue
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: multi_json
14
+ name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: thor
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Work with Philips Hue light bulbs.
@@ -46,7 +46,7 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
50
  - Contributing.markdown
51
51
  - Gemfile
52
52
  - LICENSE
@@ -72,17 +72,17 @@ require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.8.7
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.0.3
85
+ rubygems_version: 2.2.2
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Work with Philips Hue light bulbs from Ruby.