hiveline 0.0.1

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: e74826756263ed6a1cfe2f288bd0b2f4bce40f6e
4
+ data.tar.gz: 9cae527e6b04b298180bc4540a0bf0f7a32dc402
5
+ SHA512:
6
+ metadata.gz: b0c61bc41413c44da0380cd8b86dc4ce0ad56afe3771b1c9d4949caa50bb1525c87caddff999fc50502b4bdc31367b5ffa0d07b25c2386c6e8cdadedc6279b71
7
+ data.tar.gz: c296db8126ca29c25f70bb74146f935073c26914f9b741d8bef475614a70dec4789d49320bb34e70d0393c11d494f4dff67d2a674be8371407d2e9176b6b97a3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hiveline.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris Blanchard
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Hiveline
2
+
3
+ Adjust your [Hive](https://my.hivehome.com/) thermostat via your terminal.
4
+
5
+ Warning: This uses hives unofficial and undocumented API. It can break at any time.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install hiveline
11
+ ```
12
+
13
+ ## Configure
14
+
15
+ Export credentials to your environment in `.bashrc` or `.bash_profile`
16
+
17
+ ```bash
18
+ export HIVE_USERNAME="your_hive_email"
19
+
20
+ export HIVE_PASSWORD="your_hive_password"
21
+ ```
22
+
23
+ Alternatively pass then as flags to hiveline
24
+
25
+ ```
26
+ $ hiveline -u <email> -p <password>
27
+ ```
28
+
29
+ ## Use
30
+
31
+ Set the temperature to 20C
32
+
33
+ ```bash
34
+ $ hiveline 20
35
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/hiveline ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'hiveline'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: example.rb [options]"
10
+
11
+ opts.on("-u", "--username", "Login username") do |username|
12
+ options[:username] = username
13
+ end
14
+
15
+ opts.on("-p", "--password", "Login password") do |password|
16
+ options[:password] = password
17
+ end
18
+ end.parse!
19
+
20
+ username = options[:username] || ENV["HIVE_USERNAME"]
21
+
22
+ if username.nil?
23
+ print "Please provide a username with a flag (-u) or as an environment variable exports HIVE_USERNAME=\"your_username\"\n"
24
+ exit false
25
+ end
26
+
27
+ password = options[:password] || ENV["HIVE_PASSWORD"]
28
+
29
+ if password.nil?
30
+ print "Please provide a password with a flag (-p) or as an environment variable exports HIVE_PASSWORD=\"your_password\"\n"
31
+ exit false
32
+ end
33
+
34
+ temp = ARGV.last
35
+
36
+ def numeric?(number)
37
+ return true if number =~ /^\d+$/
38
+ true if Float(number) rescue false
39
+ end
40
+
41
+ if temp.nil? or !numeric?(temp)
42
+ print "Please supply a temperature. E.g. hiveline 21\n"
43
+ exit false
44
+ else
45
+ temp = temp.to_i
46
+ end
47
+
48
+ client = Hiveline::Client.new(username, password)
49
+ client.set_temperature temp
data/hiveline.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hiveline/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hiveline"
8
+ spec.version = Hiveline::VERSION
9
+ spec.authors = ["Chris Blanchard"]
10
+ spec.email = ["cablanchard@gmail.com"]
11
+ spec.summary = %q{A small Ruby script to change your Hive thermostat temperature through your terminal.}
12
+ spec.description = %q{The Hive API was reversed engineered via the Hive thermostat website (https://www.hivehome.com). This API is unsupported and undocumented. Please don't be suprised if it breaks.}
13
+ spec.homepage = "https://github.com/cblanc/hiveline"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty", "~> 0.13.3"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
data/lib/hiveline.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'hiveline/version'
4
+
5
+ module Hiveline
6
+ class Client
7
+ attr_accessor :username, :password, :hive_id
8
+
9
+ def initialize(username, password)
10
+ @username = username
11
+ @password = password
12
+ @id = retrieve_session
13
+ end
14
+
15
+ def set_temperature(temp)
16
+ print "Setting temperature to #{temp}C...\n"
17
+ heating_url = "https://my.hivehome.com/heating/target"
18
+ response = HTTParty.put(heating_url, {
19
+ body: {
20
+ id:1,
21
+ target:temp
22
+ },
23
+ headers: {
24
+ "Cookie" => "hsid=#{@id}"
25
+ },
26
+ follow_redirects: false
27
+ })
28
+
29
+ if response.code == 200
30
+ target = JSON.parse(response.body)["target"]
31
+ print "Successfully updated temperature. Set to #{target}C\n"
32
+ else
33
+ print "Something went wrong. Not sure what, maybe get up and go check your thermostat?\n"
34
+ end
35
+ response
36
+ end
37
+
38
+ private
39
+
40
+ def login
41
+ print "Authenticating credentials...\n"
42
+ login_url = "https://my.hivehome.com/login"
43
+ HTTParty.post(login_url, {
44
+ body: {
45
+ username: @username,
46
+ password: @password
47
+ },
48
+ follow_redirects: false
49
+ })
50
+ end
51
+
52
+ def extract_session_id(response)
53
+ id_attribute_regex = /^hsid=/
54
+ set_cookie_header = response.headers["set-cookie"]
55
+ set_cookie_header
56
+ .split(";")
57
+ .each(&:strip!)
58
+ .grep(id_attribute_regex)
59
+ .first
60
+ .gsub(id_attribute_regex, "")
61
+ end
62
+
63
+ def retrieve_session
64
+ extract_session_id login
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Hiveline
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiveline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Blanchard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: The Hive API was reversed engineered via the Hive thermostat website
56
+ (https://www.hivehome.com). This API is unsupported and undocumented. Please don't
57
+ be suprised if it breaks.
58
+ email:
59
+ - cablanchard@gmail.com
60
+ executables:
61
+ - hiveline
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/hiveline
70
+ - hiveline.gemspec
71
+ - lib/hiveline.rb
72
+ - lib/hiveline/version.rb
73
+ homepage: https://github.com/cblanc/hiveline
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A small Ruby script to change your Hive thermostat temperature through your
97
+ terminal.
98
+ test_files: []