nest_connect 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 5bc6bc67aa24461c5d8282091c6f1dfe99087abe93fec34d404ce706e4ba2bb2
4
- data.tar.gz: 2a79d0123e9c1038f3ea5acf9342752e708acb77d3ad468db946d5065edc5682
3
+ metadata.gz: f22e8c2c849a0c92ee4f70f162dcfaf0703293e63d23ce6955947f846ade0d36
4
+ data.tar.gz: 6023e55362c53c4226f51f7f4a58e2449e96dfd56a6ebd51bb045301cb5f5c72
5
5
  SHA512:
6
- metadata.gz: b41922f30b1c175f1048768fba16223263f7be809895f7633b03816b6ee91006658a83b72487893e4e3e07520a2112420830bafde4b9265db0f7ca0185e57966
7
- data.tar.gz: ddf4c26ab21b570c8f3f124eef7e94e375655cccddb9437cd84cbff9b2cb1145f05f4a4980866e6ba532a7467a0bc62b7380ee5f417442cf0effc7fbcecbc172
6
+ metadata.gz: da9b7fe679d73a26c2da24d4f14d84307ef83b615a3ae24b9c2f0127949672ee8c758a6cccd4491d6d24cbaca8861fdca2ab9bbcaca7e4995276ecbd30a9ddf3
7
+ data.tar.gz: fd6967a3151049e264260fd692f350bce82682d779c4d67cd1a0af38d98b8902cf0f76dc18c5cf7ba068db82e2e97bdec309a3046b12df00cd344920ccc7546d
data/.travis.yml CHANGED
@@ -1,7 +1,18 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
1
  cache: bundler
2
+ language: ruby
3
+ install:
4
+ - 'gem update --system'
5
+ - 'gem --version'
6
+ - 'gem install bundler -v 1.17.2'
7
+ - 'bundle --version'
8
+ - bundle
5
9
  rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.17.1
10
+ - 2.4
11
+ - 2.5
12
+ - 2.6
13
+ - ruby-head
14
+ os:
15
+ - linux
16
+ - osx
17
+ notifications:
18
+ email: false
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/karlentwistle/nest_connect.svg?branch=master)](https://travis-ci.org/karlentwistle/nest_connect)
2
+
1
3
  # NestConnect
2
4
 
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nest_connect`. To experiment with that code, run `bin/console` for an interactive prompt.
@@ -5,6 +5,9 @@ require_relative 'adapter/streaming_net_http'
5
5
 
6
6
  module NestConnect
7
7
  class API
8
+ def access_token
9
+ @access_token || configuration.access_token
10
+ end
8
11
 
9
12
  private
10
13
 
@@ -24,10 +27,6 @@ module NestConnect
24
27
  def configuration
25
28
  GlobalConfig.new
26
29
  end
27
-
28
- def access_token
29
- configuration.access_token
30
- end
31
30
  end
32
31
  end
33
32
 
@@ -1,9 +1,10 @@
1
1
  module NestConnect
2
2
  class API
3
- class Devices
3
+ module Devices
4
4
  class Camera < API
5
- def initialize(device_id)
5
+ def initialize(device_id, access_token: nil)
6
6
  @device_id = device_id
7
+ @access_token = access_token
7
8
  end
8
9
 
9
10
  def put(body)
@@ -1,9 +1,10 @@
1
1
  module NestConnect
2
2
  class API
3
- class Devices
3
+ module Devices
4
4
  class Protect < API
5
- def initialize(device_id)
5
+ def initialize(device_id, access_token: nil)
6
6
  @device_id = device_id
7
+ @access_token = access_token
7
8
  end
8
9
 
9
10
  def get
@@ -1,9 +1,10 @@
1
1
  module NestConnect
2
2
  class API
3
- class Devices
3
+ module Devices
4
4
  class Structure < API
5
- def initialize(structure_id)
5
+ def initialize(structure_id, access_token: nil)
6
6
  @structure_id = structure_id
7
+ @access_token = access_token
7
8
  end
8
9
 
9
10
  def put(body)
@@ -1,9 +1,10 @@
1
1
  module NestConnect
2
2
  class API
3
- class Devices
3
+ module Devices
4
4
  class Thermostat < API
5
- def initialize(device_id)
5
+ def initialize(device_id, access_token: nil)
6
6
  @device_id = device_id
7
+ @access_token = access_token
7
8
  end
8
9
 
9
10
  def put(body)
@@ -1,8 +1,9 @@
1
1
  module NestConnect
2
2
  class API
3
3
  class Stream < API
4
- def initialize(output: STDOUT)
4
+ def initialize(output: STDOUT, access_token: nil)
5
5
  @output = output
6
+ @access_token = access_token
6
7
  end
7
8
 
8
9
  def run
@@ -0,0 +1,21 @@
1
+ module NestConnect
2
+ module Device
3
+ class BaseDevice
4
+ def self.from_hash_collection(hash)
5
+ hash.values.map { |value| new(value) }
6
+ end
7
+
8
+ def reload
9
+ api_runner.get.body.each do |key, value|
10
+ instance_variable_set("@#{key}", value)
11
+ end
12
+ end
13
+
14
+ attr_accessor :access_token
15
+
16
+ private
17
+
18
+ attr_reader :api_class
19
+ end
20
+ end
21
+ end
@@ -1,10 +1,6 @@
1
1
  module NestConnect
2
- class Device
3
- class Camera
4
- def self.from_hash_collection(hash)
5
- hash.values.map { |value| new(value) }
6
- end
7
-
2
+ module Device
3
+ class Camera < BaseDevice
8
4
  def initialize(api_class: NestConnect::API::Devices::Camera, **args)
9
5
  @api_class = api_class
10
6
  args.each do |key, value|
@@ -12,12 +8,6 @@ module NestConnect
12
8
  end
13
9
  end
14
10
 
15
- def reload
16
- api_runner.get.body.each do |key, value|
17
- instance_variable_set("@#{key}", value)
18
- end
19
- end
20
-
21
11
  attr_reader(
22
12
  :device_id,
23
13
  :software_version,
@@ -50,10 +40,8 @@ module NestConnect
50
40
 
51
41
  private
52
42
 
53
- attr_reader :api_class
54
-
55
43
  def api_runner
56
- api_class.new(device_id)
44
+ api_class.new(device_id, access_token: access_token)
57
45
  end
58
46
  end
59
47
  end
@@ -1,10 +1,6 @@
1
1
  module NestConnect
2
- class Device
3
- class Protect
4
- def self.from_hash_collection(hash)
5
- hash.values.map { |value| new(value) }
6
- end
7
-
2
+ module Device
3
+ class Protect < BaseDevice
8
4
  def initialize(api_class: NestConnect::API::Devices::Protect, **args)
9
5
  @api_class = api_class
10
6
  args.each do |key, value|
@@ -12,12 +8,6 @@ module NestConnect
12
8
  end
13
9
  end
14
10
 
15
- def reload
16
- api_runner.get.body.each do |key, value|
17
- instance_variable_set("@#{key}", value)
18
- end
19
- end
20
-
21
11
  attr_reader(
22
12
  :battery_health,
23
13
  :co_alarm_state,
@@ -39,10 +29,8 @@ module NestConnect
39
29
 
40
30
  private
41
31
 
42
- attr_reader :api_class
43
-
44
32
  def api_runner
45
- api_class.new(device_id)
33
+ api_class.new(device_id, access_token: access_token)
46
34
  end
47
35
  end
48
36
  end
@@ -1,10 +1,6 @@
1
1
  module NestConnect
2
- class Device
3
- class Structure
4
- def self.from_hash_collection(hash)
5
- hash.values.map { |value| new(value) }
6
- end
7
-
2
+ module Device
3
+ class Structure < BaseDevice
8
4
  def initialize(api_class: NestConnect::API::Devices::Structure, **args)
9
5
  @api_class = api_class
10
6
  args.each do |key, value|
@@ -12,12 +8,6 @@ module NestConnect
12
8
  end
13
9
  end
14
10
 
15
- def reload
16
- api_runner.get.body.each do |key, value|
17
- instance_variable_set("@#{key}", value)
18
- end
19
- end
20
-
21
11
  attr_reader(
22
12
  :co_alarm_state,
23
13
  :country_code,
@@ -75,10 +65,8 @@ module NestConnect
75
65
 
76
66
  private
77
67
 
78
- attr_reader :api_class
79
-
80
68
  def api_runner
81
- api_class.new(structure_id)
69
+ api_class.new(structure_id, access_token: access_token)
82
70
  end
83
71
  end
84
72
  end
@@ -2,12 +2,8 @@ module NestConnect
2
2
  class RangeError < StandardError; end
3
3
  class ValueError < StandardError; end
4
4
 
5
- class Device
6
- class Thermostat
7
- def self.from_hash_collection(hash)
8
- hash.values.map { |value| new(value) }
9
- end
10
-
5
+ module Device
6
+ class Thermostat < BaseDevice
11
7
  def initialize(api_class: NestConnect::API::Devices::Thermostat, **args)
12
8
  @api_class = api_class
13
9
  args.each do |key, value|
@@ -15,12 +11,6 @@ module NestConnect
15
11
  end
16
12
  end
17
13
 
18
- def reload
19
- api_runner.get.body.each do |key, value|
20
- instance_variable_set("@#{key}", value)
21
- end
22
- end
23
-
24
14
  TARGET_TEMPERATURE_F_RANGE = (50..90)
25
15
 
26
16
  attr_reader :target_temperature_f
@@ -184,10 +174,8 @@ module NestConnect
184
174
 
185
175
  private
186
176
 
187
- attr_reader :api_class
188
-
189
177
  def api_runner
190
- api_class.new(device_id)
178
+ api_class.new(device_id, access_token: access_token)
191
179
  end
192
180
  end
193
181
  end
@@ -1,3 +1,3 @@
1
1
  module NestConnect
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/nest_connect.rb CHANGED
@@ -6,6 +6,7 @@ require 'nest_connect/global_config'
6
6
  require 'nest_connect/config_store'
7
7
  require 'nest_connect/api/api'
8
8
  require 'nest_connect/chunk_parser'
9
+ require 'nest_connect/devices/base_device'
9
10
  require 'nest_connect/devices/camera'
10
11
  require 'nest_connect/devices/protect'
11
12
  require 'nest_connect/devices/structure'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nest_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -134,7 +134,6 @@ files:
134
134
  - ".rspec"
135
135
  - ".travis.yml"
136
136
  - Gemfile
137
- - Gemfile.lock
138
137
  - README.md
139
138
  - Rakefile
140
139
  - bin/console
@@ -151,6 +150,7 @@ files:
151
150
  - lib/nest_connect/api/stream.rb
152
151
  - lib/nest_connect/chunk_parser.rb
153
152
  - lib/nest_connect/config_store.rb
153
+ - lib/nest_connect/devices/base_device.rb
154
154
  - lib/nest_connect/devices/camera.rb
155
155
  - lib/nest_connect/devices/protect.rb
156
156
  - lib/nest_connect/devices/structure.rb
@@ -176,8 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.7.6
179
+ rubygems_version: 3.0.1
181
180
  signing_key:
182
181
  specification_version: 4
183
182
  summary: Simple API Wrapper for Nest Thermostats
data/Gemfile.lock DELETED
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- nest_connect (0.1.3)
5
- faraday (~> 0.15)
6
- faraday_middleware (~> 0.12)
7
- thor (~> 0.20)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- addressable (2.5.2)
13
- public_suffix (>= 2.0.2, < 4.0)
14
- byebug (10.0.2)
15
- crack (0.4.3)
16
- safe_yaml (~> 1.0.0)
17
- diff-lcs (1.3)
18
- faraday (0.15.4)
19
- multipart-post (>= 1.2, < 3)
20
- faraday_middleware (0.12.2)
21
- faraday (>= 0.7.4, < 1.0)
22
- hashdiff (0.3.7)
23
- multipart-post (2.0.0)
24
- public_suffix (3.0.3)
25
- rake (10.5.0)
26
- rspec (3.8.0)
27
- rspec-core (~> 3.8.0)
28
- rspec-expectations (~> 3.8.0)
29
- rspec-mocks (~> 3.8.0)
30
- rspec-core (3.8.0)
31
- rspec-support (~> 3.8.0)
32
- rspec-expectations (3.8.2)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-mocks (3.8.0)
36
- diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-support (3.8.0)
39
- safe_yaml (1.0.4)
40
- thor (0.20.3)
41
- webmock (3.4.2)
42
- addressable (>= 2.3.6)
43
- crack (>= 0.3.2)
44
- hashdiff
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
50
- bundler (~> 1.17)
51
- byebug
52
- nest_connect!
53
- rake (~> 10.0)
54
- rspec (~> 3.0)
55
- webmock
56
-
57
- BUNDLED WITH
58
- 1.17.1