nest_thermostat 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ecd5a762a529bd2d84c543a322e06a94efd8fba
4
+ data.tar.gz: c8e3344c2dc09dee5960d30f7fc249f34387961c
5
+ SHA512:
6
+ metadata.gz: 233fb931a2d243fb28c4221b4060b3a1053051623865514e8f0ea7a4812d3414d12ade8d105111531d857f8389eff08ced9b64b7a8f74e286740727c9f616d71
7
+ data.tar.gz: 571cd38d59b7e4730196e7d5ad4e4d13307cb33d75e1bab10d8aa1aa0183cceca37b0881948c5c0726b57b376219f8ed21c2808ea351ceb96129bd7fadb3ad0b
data/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ NEST_EMAIL=test@example.com
2
+ NEST_PASS=abcdefg123
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ PATH_add vendor/bundle/bin
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .env
19
+ vendor/bundle
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nest_thermostat.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -5,15 +5,22 @@ PATH
5
5
  httparty (~> 0.8.3)
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
10
  awesome_print (1.0.2)
11
+ coderay (1.0.9)
11
12
  diff-lcs (1.1.3)
13
+ dotenv (0.6.0)
12
14
  httparty (0.8.3)
13
15
  multi_json (~> 1.0)
14
16
  multi_xml
17
+ method_source (0.8.1)
15
18
  multi_json (1.3.6)
16
19
  multi_xml (0.5.1)
20
+ pry (0.9.12)
21
+ coderay (~> 1.0.5)
22
+ method_source (~> 0.8)
23
+ slop (~> 3.4)
17
24
  rspec (2.10.0)
18
25
  rspec-core (~> 2.10.0)
19
26
  rspec-expectations (~> 2.10.0)
@@ -22,11 +29,14 @@ GEM
22
29
  rspec-expectations (2.10.0)
23
30
  diff-lcs (~> 1.1.3)
24
31
  rspec-mocks (2.10.1)
32
+ slop (3.4.4)
25
33
 
26
34
  PLATFORMS
27
35
  ruby
28
36
 
29
37
  DEPENDENCIES
30
38
  awesome_print
39
+ dotenv
31
40
  nest_thermostat!
41
+ pry
32
42
  rspec (~> 2.10)
data/README.md CHANGED
@@ -77,8 +77,7 @@ device/location support added.
77
77
  If you use Alfred.app for OS X you may be interested in an extension.
78
78
  [Download it](http://erc.bz/HtOe). You'll need ruby 1.9+ and this gem
79
79
  installed. Then just enter your nest email/pass as the arguments in the
80
- alfred extension (after you import it). It also uses [Growl](http://growl.info/downloads) to display
81
- output so you'll need that installed as well.
80
+ alfred extension (after you import it).
82
81
 
83
82
  ![Screenshot of Alfred Extension](http://erc.bz/H9Hm/Image%202012.06.05%202:18:56%20PM.png) ![Screenshot of Alfred Extension Growl Output](http://erc.bz/H97m/Image%202012.06.05%202:34:49%20PM.png)
84
83
 
@@ -10,7 +10,7 @@ module NestThermostat
10
10
  :transport_host, :structure_id, :device_id, :headers
11
11
 
12
12
  def initialize(config = {})
13
- raise 'Please specify your nest email' unless config[:email]
13
+ raise 'Please specify your nest email' unless config[:email]
14
14
  raise 'Please specify your nest password' unless config[:password]
15
15
 
16
16
  # User specified information
@@ -21,10 +21,10 @@ module NestThermostat
21
21
  self.user_agent = config[:user_agent] ||'Nest/1.1.0.10 CFNetwork/548.0.4'
22
22
 
23
23
  # Login and get token, user_id and URLs
24
- login
25
- self.token = login["access_token"]
26
- self.user_id = login["userid"]
27
- self.transport_url = login["urls"]["transport_url"]
24
+ perform_login
25
+ self.token = @auth["access_token"]
26
+ self.user_id = @auth["userid"]
27
+ self.transport_url = @auth["urls"]["transport_url"]
28
28
  self.transport_host = URI.parse(self.transport_url).host
29
29
  self.headers = {
30
30
  'Host' => self.transport_host,
@@ -52,7 +52,7 @@ module NestThermostat
52
52
  end
53
53
 
54
54
  def public_ip
55
- status["metadata"][self.device_id]["last_ip"].strip
55
+ status["track"][self.device_id]["last_ip"].strip
56
56
  end
57
57
 
58
58
  def leaf
@@ -107,14 +107,15 @@ module NestThermostat
107
107
  end
108
108
 
109
109
  private
110
- def login
110
+ def perform_login
111
111
  login_request = HTTParty.post(
112
112
  self.login_url,
113
113
  body: { username: self.email, password: self.password },
114
114
  headers: { 'User-Agent' => self.user_agent }
115
115
  )
116
116
 
117
- self.auth = JSON.parse(login_request.body) rescue nil
117
+ self.auth ||= JSON.parse(login_request.body) rescue nil
118
+ raise 'Invalid login credentials' if self.auth.has_key?('error') && self.auth['error'] == "access_denied"
118
119
  end
119
120
 
120
121
  def convert_temp_for_get(degrees)
@@ -154,6 +155,5 @@ module NestThermostat
154
155
  def f2c(degrees)
155
156
  (degrees.to_f - 32) * 5 / 9
156
157
  end
157
-
158
158
  end
159
159
  end
@@ -1,3 +1,3 @@
1
1
  module NestThermostat
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_development_dependency "rspec", "~> 2.10"
20
20
  gem.add_development_dependency "awesome_print"
21
+ gem.add_development_dependency "dotenv"
22
+ gem.add_development_dependency "pry"
21
23
  end
@@ -1,5 +1,8 @@
1
+ require 'dotenv'
2
+ require 'pry'
1
3
  require 'nest_thermostat'
2
4
 
5
+ Dotenv.load
3
6
  RSpec.configure do |c|
4
7
  c.filter_run focus: true
5
8
  c.run_all_when_everything_filtered = true
@@ -14,11 +17,16 @@ describe NestThermostat::Nest do
14
17
  @nest.transport_url.should match /transport.nest.com/
15
18
  end
16
19
 
20
+ it "detects invalid logins" do
21
+ expect { NestThermostat::Nest.new({email: 'invalid@example.com', password: 'asdf'})
22
+ }.to raise_error
23
+ end
24
+
17
25
  it "gets the status" do
18
26
  @nest.status['device'].first[1]['mac_address'].should match /(\d|[a-f]|[A-F])+/
19
27
  end
20
28
 
21
- it "gets the pubic ip address",focus:true do
29
+ it "gets the pubic ip address" do
22
30
  @nest.public_ip.should match /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/
23
31
  end
24
32
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nest_thermostat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric Boehs
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-05 00:00:00.000000000 Z
11
+ date: 2013-03-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,17 +41,43 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: awesome_print
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
60
81
  - !ruby/object:Gem::Version
61
82
  version: '0'
62
83
  description: Control your nest thermostat
@@ -66,6 +87,8 @@ executables: []
66
87
  extensions: []
67
88
  extra_rdoc_files: []
68
89
  files:
90
+ - .env.example
91
+ - .envrc
69
92
  - .gitignore
70
93
  - Gemfile
71
94
  - Gemfile.lock
@@ -79,33 +102,26 @@ files:
79
102
  - spec/nest_thermostat_spec.rb
80
103
  homepage: http://github.com/ericboehs/nest_thermostat
81
104
  licenses: []
105
+ metadata: {}
82
106
  post_install_message:
83
107
  rdoc_options: []
84
108
  require_paths:
85
109
  - lib
86
110
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
111
  requirements:
89
- - - ! '>='
112
+ - - '>='
90
113
  - !ruby/object:Gem::Version
91
114
  version: '0'
92
- segments:
93
- - 0
94
- hash: 3375862277283861610
95
115
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
116
  requirements:
98
- - - ! '>='
117
+ - - '>='
99
118
  - !ruby/object:Gem::Version
100
119
  version: '0'
101
- segments:
102
- - 0
103
- hash: 3375862277283861610
104
120
  requirements: []
105
121
  rubyforge_project:
106
- rubygems_version: 1.8.23
122
+ rubygems_version: 2.0.0
107
123
  signing_key:
108
- specification_version: 3
124
+ specification_version: 4
109
125
  summary: View and set temperature and away status for your Nest
110
126
  test_files:
111
127
  - spec/nest_thermostat_spec.rb