nest-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba1e9ac59a9cced62288368ab77f8304d77746e9
4
+ data.tar.gz: f233c6b21e8cb42a86f1e8638c918e142ffc2801
5
+ SHA512:
6
+ metadata.gz: 2b289d311b00248ef4d944dd74d0d8efd15589442ff544c57f48cbefadb72af2e880568f3071346a87858ffe1ac8a86b5ae32085140f77738e899d61a0e29e49
7
+ data.tar.gz: dd68b94c86dea9143184b3f7e58c8310fb7805ebed8e25c3a617bff5d700629cf3df76c9f4c518cd963a8795e15c6030a5f4f7ace71459320928d60b12ca3145
@@ -0,0 +1,2 @@
1
+ .env
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nest-api (0.0.1)
5
+ awesome_print
6
+ cistern (~> 2.8.2)
7
+ excon (~> 0.45.5)
8
+ faraday (~> 0.15.4)
9
+ faraday_middleware
10
+ oj
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ awesome_print (1.8.0)
16
+ byebug (11.0.1)
17
+ cistern (2.8.2)
18
+ coderay (1.1.2)
19
+ diff-lcs (1.3)
20
+ excon (0.45.5)
21
+ faraday (0.15.4)
22
+ multipart-post (>= 1.2, < 3)
23
+ faraday_middleware (0.13.1)
24
+ faraday (>= 0.7.4, < 1.0)
25
+ method_source (0.9.2)
26
+ multipart-post (2.0.0)
27
+ oj (3.6.2)
28
+ pry (0.12.2)
29
+ coderay (~> 1.1.0)
30
+ method_source (~> 0.9.0)
31
+ pry-byebug (3.7.0)
32
+ byebug (~> 11.0)
33
+ pry (~> 0.10)
34
+ rspec (3.8.0)
35
+ rspec-core (~> 3.8.0)
36
+ rspec-expectations (~> 3.8.0)
37
+ rspec-mocks (~> 3.8.0)
38
+ rspec-core (3.8.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-expectations (3.8.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-mocks (3.8.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-support (3.8.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ byebug
53
+ nest-api!
54
+ pry-byebug
55
+ rspec
56
+
57
+ BUNDLED WITH
58
+ 2.0.1
@@ -0,0 +1,19 @@
1
+ # Nest API Client
2
+
3
+ Nest API client using Cistern. Currently this client can only read thermostat params
4
+
5
+ ## Usage
6
+
7
+ ### Installation
8
+ `gem install nest-api`
9
+
10
+ `require 'nest'`
11
+
12
+ ###
13
+ 1. Initialize the client
14
+
15
+ `client = Nest.new(access_token: API_KEY)`
16
+
17
+ 2. Get a device
18
+
19
+ `thermostat = client.thermostats.first`
@@ -0,0 +1,17 @@
1
+ require "awesome_print"
2
+ require "cistern"
3
+ require "excon"
4
+ require "faraday"
5
+ require "faraday_middleware"
6
+ require "oj"
7
+
8
+ class Nest
9
+ include Cistern::Client.with(interface: :module)
10
+
11
+ recognizes :url, :access_token
12
+
13
+ require_relative "nest/real"
14
+ require_relative "nest/requests/get_metadata"
15
+ require_relative "nest/models/thermostat"
16
+ require_relative "nest/models/thermostats"
17
+ end
@@ -0,0 +1,56 @@
1
+ class Nest::Thermostat
2
+ include Nest::Model
3
+
4
+ identity :id, aliases: [:device_id]
5
+
6
+ attribute :ambient_temperature_c, type: :float
7
+ attribute :ambient_temperature_f, type: :float
8
+ attribute :away_temperature_high_c, type: :float
9
+ attribute :away_temperature_high_f, type: :float
10
+ attribute :away_temperature_low_c, type: :float
11
+ attribute :away_temperature_low_f, type: :float
12
+ attribute :can_cool, type: :boolean
13
+ attribute :can_heat, type: :boolean
14
+ attribute :device_id
15
+ attribute :eco_temperature_high_c, type: :float
16
+ attribute :eco_temperature_high_f, type: :float
17
+ attribute :eco_temperature_low_c, type: :float
18
+ attribute :eco_temperature_low_f, type: :float
19
+ attribute :fan_timer_active, type: :boolean
20
+ attribute :fan_timer_duration, type: :float
21
+ attribute :fan_timer_timeout
22
+ attribute :has_fan, type: :boolean
23
+ attribute :has_leaf, type: :boolean
24
+ attribute :humidity, type: :float
25
+ attribute :hvac_mode
26
+ attribute :hvac_state
27
+ attribute :is_locked, type: :boolean
28
+ attribute :is_online, type: :boolean
29
+ attribute :is_using_emergency_heat, type: :boolean
30
+ attribute :label
31
+ attribute :last_connection
32
+ attribute :locale
33
+ attribute :locked_temp_max_c, type: :float
34
+ attribute :locked_temp_max_f, type: :float
35
+ attribute :locked_temp_min_c, type: :float
36
+ attribute :locked_temp_min_f, type: :float
37
+ attribute :name
38
+ attribute :name_long
39
+ attribute :previous_hvac_mode
40
+ attribute :software_version
41
+ attribute :structure_id
42
+ attribute :sunlight_correction_active, type: :boolean
43
+ attribute :sunlight_correction_enabled, type: :boolean
44
+ attribute :target_temperature_c, type: :float
45
+ attribute :target_temperature_f, type: :float
46
+ attribute :target_temperature_high_c, type: :float
47
+ attribute :target_temperature_high_f, type: :float
48
+ attribute :target_temperature_low_c, type: :float
49
+ attribute :target_temperature_low_f, type: :float
50
+ attribute :temperature_scale
51
+ attribute :time_to_target
52
+ attribute :time_to_target_training
53
+ attribute :where_id
54
+ attribute :where_name
55
+ end
56
+
@@ -0,0 +1,10 @@
1
+ class Nest::Thermostats
2
+ include Nest::Collection
3
+
4
+ model Nest::Thermostat
5
+
6
+ def all
7
+ data = cistern.get_metadata["devices"]["thermostats"].map { |k,v| v }
8
+ load(data)
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ class Nest::Real
2
+ attr_reader :url, :connection, :access_token
3
+
4
+ def initialize(attributes={})
5
+ @url = attributes[:url] || 'https://developer-api.nest.com/'
6
+ @access_token = attributes[:access_token] || ENV["ACCESS_TOKEN"]
7
+ @connection = Faraday.new(url: @url, headers: { "Content-Type" => "application/json" }) do |b|
8
+ b.adapter :excon
9
+ b.authorization :Bearer, @access_token
10
+ end
11
+ end
12
+
13
+ def request(method, path, args={})
14
+ res = connection.send(method) do |req|
15
+ req.url path
16
+ end
17
+
18
+ while res.status == 307
19
+ redirect_client = Faraday.new(res.headers["Location"]) do |b|
20
+ b.adapter :excon
21
+ b.authorization :Bearer, @access_token
22
+ end
23
+
24
+ res = redirect_client.send(method, "/")
25
+ end
26
+
27
+ Oj.load(res.body)
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ class Nest::GetMetadata
2
+ include Nest::Request
3
+
4
+ def real
5
+ cistern.request(:get, "/")
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Nest
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative "./lib/nest/version"
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Eugene Howe"]
5
+ gem.email = ["eugene@xtreme-computers.net"]
6
+ gem.description = %q{}
7
+ gem.summary = %q{}
8
+ gem.homepage = "https://github.com/ehowe/nest-api.git"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "nest-api"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Nest::VERSION
16
+
17
+ gem.add_dependency "awesome_print", "~> 1.8"
18
+ gem.add_dependency "cistern", "~> 2.8"
19
+ gem.add_dependency "excon", "~> 0.45"
20
+ gem.add_dependency "faraday", "~> 0.15"
21
+ gem.add_dependency "faraday_middleware", "~> 0.13"
22
+ gem.add_dependency "oj", "~> 3.6"
23
+
24
+ gem.add_development_dependency "byebug", "~> 11.0"
25
+ gem.add_development_dependency "dotenv", "~> 2.7"
26
+ gem.add_development_dependency "pry-byebug", "~> 3.7"
27
+ gem.add_development_dependency "rspec", "~> 3.8"
28
+ end
@@ -0,0 +1 @@
1
+ require_relative "../lib/nest"
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ describe "Thermostats" do
4
+ let(:client) { Nest.new }
5
+
6
+ it "has a collection of thermostats" do
7
+ expect(client.thermostats.all).to be_a(Nest::Thermostats)
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nest-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eugene Howe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cistern
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: excon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.45'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.45'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.15'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oj
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '11.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '11.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: dotenv
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.8'
153
+ description: ''
154
+ email:
155
+ - eugene@xtreme-computers.net
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - Gemfile
162
+ - Gemfile.lock
163
+ - README.md
164
+ - lib/nest.rb
165
+ - lib/nest/models/thermostat.rb
166
+ - lib/nest/models/thermostats.rb
167
+ - lib/nest/real.rb
168
+ - lib/nest/requests/get_metadata.rb
169
+ - lib/nest/version.rb
170
+ - nest-api.gemspec
171
+ - spec/test_helper.rb
172
+ - spec/thermostat_spec.rb
173
+ homepage: https://github.com/ehowe/nest-api.git
174
+ licenses: []
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.6.14
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: ''
196
+ test_files:
197
+ - spec/test_helper.rb
198
+ - spec/thermostat_spec.rb