toon_api 1.0.0

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: 69082bc51f619df6ec80160364ffcee89c20c900
4
+ data.tar.gz: 9647700ab0bcaf1991d5acb9ae41d9431b5c31d6
5
+ SHA512:
6
+ metadata.gz: e606154c40390ec6708881aa5b7cfab20c95ccbb746533e1e3f779b5d02aebcaffa9aa58ddd8c86dffc042f3f3a61df5fdc53b8411392f359abd7c899ffff624
7
+ data.tar.gz: 280b99490697ee69fecf54150572551175e969c0098c2394999025829d47e2494eb8af8e10f4dbe8d0ae9be65f81e0752e0efce1388add4a2b4c78efd59a957c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.kick ADDED
@@ -0,0 +1,18 @@
1
+ require 'set'
2
+ require 'benchmark'
3
+
4
+ process do |file, flags|
5
+ test_files = Set.new
6
+ case file
7
+ when %r(^spec/.*_spec.rb$)
8
+ test_files << file
9
+ when %r(^lib/(.*).rb)
10
+ test_files << 'spec/lib/' + $1 + '_spec.rb'
11
+ when %r(^spec/helpers/expected)
12
+ test_files.merge Dir['spec/helpers/**/*_spec.rb']
13
+ end
14
+ test_files = test_files.select { |filename| File.exist?(filename) }
15
+ unless test_files.empty?
16
+ watcher.execute("bundle exec rspec --fail-fast #{test_files.to_a.join(' ')}")
17
+ end
18
+ end
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.0
5
+ script: bundle exec rspec
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at maartenvanvliet@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in toon_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Maarten van Vliet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # ToonApi (WIP)
2
+
3
+ Ruby gem to interface with Eneco Toon intelligent thermostat. Port of https://github.com/rvdm/toon
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ require 'toon_api'
9
+
10
+ toon = ToonApi.new(username, password)
11
+ toon.login
12
+
13
+ toon.get_thermostat_info
14
+
15
+ ```
16
+
17
+ ## Contributing
18
+
19
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maartenvanvliet/toon_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
20
+
21
+
22
+ ## License
23
+
24
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
25
+
data/lib/toon_api.rb ADDED
@@ -0,0 +1,120 @@
1
+ require "toon_api/version"
2
+ require 'json'
3
+ require 'securerandom'
4
+ class ToonApi
5
+ attr_accessor :username, :password, :session_data, :toon_state, :http
6
+ attr_reader :_last_response
7
+
8
+ def initialize(username, password)
9
+ self.username = username
10
+ self.password = password
11
+ clear_toon_state
12
+ end
13
+
14
+ def base_url
15
+ "https://toonopafstand.eneco.nl"
16
+ end
17
+
18
+ def clear_toon_state
19
+ self.toon_state = {}
20
+ end
21
+
22
+ def http
23
+ @http ||= begin
24
+ uri = uri_for_path(base_url)
25
+ http = Net::HTTP.new(uri.host, uri.port)
26
+ http.use_ssl = uri.scheme == 'https'
27
+ http
28
+ end
29
+ end
30
+
31
+ def uri_for_path(path)
32
+ URI.parse(File.join(base_url, path))
33
+ end
34
+
35
+ def get(path, params = {}, headers={})
36
+ uri = uri_for_path("#{path}?#{URI.encode_www_form(params)}")
37
+ request = Net::HTTP::Get.new(uri.request_uri, {})
38
+ perform(request)
39
+ end
40
+
41
+ def login
42
+ response = get("/toonMobileBackendWeb/client/login", { username: username, password: password })
43
+
44
+ self.session_data = JSON.parse(response.body)
45
+
46
+ params = client_params.merge({
47
+ agreementId: session_data["agreements"][0]["agreementId"],
48
+ agreementIdChecksum: session_data["agreements"][0]["agreementIdChecksum"],
49
+ })
50
+
51
+ response = get("/toonMobileBackendWeb/client/auth/start", params)
52
+
53
+ successful_response?(response)
54
+ end
55
+
56
+ def logout
57
+ return unless session_data
58
+ response = get("/toonMobileBackendWeb/client/auth/logout", client_params)
59
+ clear_toon_state
60
+ self.session_data = nil
61
+ successful_response?(response)
62
+ end
63
+
64
+ def client_params
65
+ {
66
+ clientId: self.session_data["clientId"],
67
+ clientIdChecksum: self.session_data["clientIdChecksum"],
68
+ random: SecureRandom.uuid
69
+ }
70
+ end
71
+
72
+ def retrieve_toon_state
73
+ return unless session_data
74
+ return toon_state unless toon_state.empty?
75
+
76
+ self.toon_state = begin
77
+ response = get("/toonMobileBackendWeb/client/auth/retrieveToon_State", client_params)
78
+ JSON.parse(response.body)
79
+ end
80
+ end
81
+
82
+ def refresh_toon_state
83
+ clear_toon_state
84
+ retrieve_toon_state
85
+ end
86
+
87
+ def get_thermostat_info
88
+ retrieve_toon_state
89
+ toon_state["thermostatInfo"]
90
+ end
91
+
92
+ def get_gas_usage
93
+ retrieve_toon_state
94
+ toon_state["gasUsage"]
95
+ end
96
+
97
+ def get_power_usage
98
+ retrieve_toon_state
99
+ toon_state["powerUsage"]
100
+ end
101
+
102
+ def get_thermostat_states
103
+ retrieve_toon_state
104
+ toon_state["thermostatStates"]
105
+ end
106
+
107
+ def get_program_state
108
+ retrieve_toon_state
109
+ toon_state["thermostatInfo"]["activeState"]
110
+ end
111
+
112
+ private
113
+ def successful_response?(response)
114
+ JSON.parse(response.body)['success'] == true
115
+ end
116
+
117
+ def perform(request)
118
+ @_last_response = http.request(request)
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ class ToonApi
2
+ VERSION = "1.0.0"
3
+ end
data/toon_api.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'toon_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "toon_api"
8
+ spec.version = ToonApi::VERSION
9
+ spec.authors = ["Maarten van Vliet"]
10
+ spec.email = ["maartenvanvliet@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to interface with Eneco Toon api}
13
+ spec.description = %q{Gem to interface with Eneco Toon api. Port of https://github.com/rvdm/toon}
14
+ spec.homepage = "https://github.com/maartenvanvliet/toon_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "rspec", "~> 3.0"
21
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toon_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maarten van Vliet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Gem to interface with Eneco Toon api. Port of https://github.com/rvdm/toon
28
+ email:
29
+ - maartenvanvliet@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".kick"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - lib/toon_api.rb
43
+ - lib/toon_api/version.rb
44
+ - toon_api.gemspec
45
+ homepage: https://github.com/maartenvanvliet/toon_api
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Gem to interface with Eneco Toon api
69
+ test_files: []
70
+ has_rdoc: