also_energy 0.1.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: 27e68266a184519416063a4296d43c221e685b1d
4
+ data.tar.gz: 4fa3a253a82ccea0aa1f09dfecc0c048dde62ae2
5
+ SHA512:
6
+ metadata.gz: faec045419682a0e9e8aa0f7362c11d504b825b78bcc736a64fc8d42d5daa48ee1b4887f2bcc29974a14f7ef1589ed9d1f1b6e933deb0aa06496d0803954d55d
7
+ data.tar.gz: 1976c2ba963fc6a8e10848c27d020b587eb635e3e5ba1a51a1021115ddd541237ebac014f3af59d947d8ef30eb18eca880c1b5c7bdd85c881e4d0a2d596ecda6
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ *.here
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in also_energy.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
7
+ gem 'virtus'
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ also_energy (0.1.0)
5
+ savon (~> 2.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.8)
11
+ akami (1.3.1)
12
+ gyoku (>= 0.4.0)
13
+ nokogiri
14
+ axiom-types (0.1.1)
15
+ descendants_tracker (~> 0.0.4)
16
+ ice_nine (~> 0.11.0)
17
+ thread_safe (~> 0.3, >= 0.3.1)
18
+ builder (3.2.2)
19
+ coderay (1.1.0)
20
+ coercible (1.0.0)
21
+ descendants_tracker (~> 0.0.1)
22
+ crack (0.4.2)
23
+ safe_yaml (~> 1.0.0)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ equalizer (0.0.11)
27
+ gyoku (1.3.1)
28
+ builder (>= 2.1.2)
29
+ httpi (2.4.1)
30
+ rack
31
+ ice_nine (0.11.1)
32
+ macaddr (1.7.1)
33
+ systemu (~> 2.6.2)
34
+ method_source (0.8.2)
35
+ mini_portile (0.6.2)
36
+ minitest (5.8.0)
37
+ nokogiri (1.6.6.2)
38
+ mini_portile (~> 0.6.0)
39
+ nori (2.6.0)
40
+ pry (0.10.1)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ rack (1.6.4)
45
+ rake (10.4.2)
46
+ safe_yaml (1.0.4)
47
+ savon (2.10.1)
48
+ akami (~> 1.2)
49
+ builder (>= 2.1.2)
50
+ gyoku (~> 1.2)
51
+ httpi (~> 2.3)
52
+ nokogiri (>= 1.4.0)
53
+ nori (~> 2.4)
54
+ uuid (~> 2.3.7)
55
+ wasabi (~> 3.4)
56
+ slop (3.6.0)
57
+ systemu (2.6.5)
58
+ thread_safe (0.3.5)
59
+ uuid (2.3.8)
60
+ macaddr (~> 1.0)
61
+ vcr (2.9.3)
62
+ virtus (1.0.5)
63
+ axiom-types (~> 0.1)
64
+ coercible (~> 1.0)
65
+ descendants_tracker (~> 0.0, >= 0.0.3)
66
+ equalizer (~> 0.0, >= 0.0.9)
67
+ wasabi (3.5.0)
68
+ httpi (~> 2.0)
69
+ nokogiri (>= 1.4.2)
70
+ webmock (1.21.0)
71
+ addressable (>= 2.3.6)
72
+ crack (>= 0.3.2)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ also_energy!
79
+ bundler (~> 1.10)
80
+ minitest
81
+ pry
82
+ rake (~> 10.0)
83
+ vcr
84
+ virtus
85
+ webmock
86
+
87
+ BUNDLED WITH
88
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Edit LLC
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # AlsoEnergy
2
+
3
+ This is a Ruby wrapper for the Also Energy Production Data SOAP API Version 1.6.1
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'also_energy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install also_energy
20
+
21
+ ## Usage
22
+
23
+ TBD
24
+
25
+ ## Development
26
+
27
+ TBD
28
+
29
+ ## Contributing
30
+
31
+ TBD
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'also_energy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "also_energy"
8
+ spec.version = AlsoEnergy::VERSION
9
+ spec.authors = ["Tyler Whitsett", "Darin Haener"]
10
+ spec.email = ["whitsett.tyler@gmail.com", "dphaener@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby wrapper for the AlsoEnergy API}
13
+ spec.description = %q{A Ruby wrapper for the AlsoEnergy API}
14
+ spec.homepage = "https://github.com/EditLLC/also-energy-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "vcr"
26
+ spec.add_development_dependency "webmock"
27
+
28
+ spec.add_dependency "savon", "~> 2.10.0"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "also_energy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "also_energy/version"
2
+ require 'also_energy/client'
3
+
4
+ module AlsoEnergy
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'savon'
2
+ require 'pry'
3
+ require 'virtus'
4
+ require './lib/also_energy/hash_wrangler'
5
+ require './lib/also_energy/connection'
6
+ require './lib/also_energy/site'
7
+ require './lib/also_energy/hardware'
8
+
9
+ module AlsoEnergy
10
+ class AuthError < StandardError; end
11
+ class QueryError < StandardError; end
12
+
13
+ class Client
14
+ include HashWrangler
15
+ include APIConnection
16
+
17
+ attr_accessor :username, :password, :session_id
18
+
19
+ def initialize
20
+ yield(self) if block_given?
21
+ end
22
+
23
+ def login
24
+ message = { 'als:username' => username, 'als:password' => password }
25
+ response = find_in_hash(:session_id, (connection.call(:login, message: message).body))
26
+ if response.nil?
27
+ fail AuthError, 'Login Failed!'
28
+ else
29
+ self.session_id = response
30
+ end
31
+ end
32
+
33
+ def get_sites
34
+ message = { 'als:sessionID' => session_id }
35
+ response = find_in_hash(:items, (connection.call(:get_site_list, message: message).body))
36
+ if response.nil?
37
+ fail QueryError, 'Query Failed!'
38
+ else
39
+ response.map { |site| AlsoEnergy::Site.new(site[1]) }
40
+ end
41
+ end
42
+
43
+ def get_site_hardware(site_id)
44
+ message = { 'als:sessionID' => session_id, 'als:siteID' => site_id }
45
+ response = find_in_hash(:hardware_complete, (connection.call(:get_site_hardware_list, message: message).body))
46
+ if response.nil?
47
+ fail QueryError, 'Query Failed!'
48
+ else
49
+ response.map { |hw| AlsoEnergy::HardWare.new(hw) }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ module APIConnection
2
+ def connection
3
+ @connect = Savon.client do |globals|
4
+ globals.wsdl "http://www.alsoenergy.com/WebAPI/WebAPI.svc?wsdl"
5
+ globals.endpoint "https://www.alsoenergy.com/WebAPI/WebAPI.svc"
6
+ globals.env_namespace :soapenv
7
+ globals.namespaces("xmlns:als1" => "http://schemas.datacontract.org/2004/07/AlsoEnergyAPI.Data")
8
+ globals.namespace_identifier :als
9
+ globals.pretty_print_xml true
10
+ globals.log true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module AlsoEnergy
2
+ class HardWare
3
+ include HashWrangler
4
+ include APIConnection
5
+ include Virtus.model
6
+
7
+ attribute :device_code, String
8
+ attribute :device_id, Integer
9
+ attribute :device_num, Integer
10
+ attribute :flags, String
11
+ attribute :gateway_id, String
12
+ attribute :hardware_id, Integer
13
+ attribute :name, String
14
+ attribute :site_id, Integer
15
+ attribute :field_list, Array
16
+ attribute :session_id, String
17
+
18
+ def initialize(params = {})
19
+ super(params)
20
+ end
21
+
22
+ def get_bin_data(period_start, period_end, bin_size, query_blob)
23
+ message = {
24
+ 'als:sessionID' => session_id,
25
+ 'als:fromLocal' => period_start,
26
+ 'als:toLocal' => period_end,
27
+ 'als:binSize' => bin_size,
28
+ 'als:Fields' => query_blob
29
+ }
30
+ response = find_in_hash(:data_set, (connection.call(:get_bin_data, message: message).body))
31
+ response.nil? ? (fail QueryError, 'Query Failed!') : response
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module HashWrangler
2
+ #credit to http://stackoverflow.com/questions/8301566/
3
+ def find_in_hash(key, object=self, found=nil)
4
+ if object.respond_to?(:key?) && object.key?(key)
5
+ return object[key]
6
+ elsif object.is_a? Enumerable
7
+ object.find { |*a| found = find_in_hash(key, a.last) }
8
+ return found
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module AlsoEnergy
2
+ class Site
3
+ include HashWrangler
4
+ include Virtus.model
5
+
6
+ attribute :id, Integer
7
+ attribute :name, String
8
+ attribute :latitude, Float
9
+ attribute :longitude, Float
10
+ attribute :city, String
11
+ attribute :state, String
12
+ attribute :time_zone, String
13
+ attribute :dst, Boolean
14
+ attribute :type, String
15
+
16
+ def initialize(params = {})
17
+ super(params)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module AlsoEnergy
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: also_energy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Whitsett
8
+ - Darin Haener
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-09-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: vcr
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: savon
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 2.10.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 2.10.0
98
+ description: A Ruby wrapper for the AlsoEnergy API
99
+ email:
100
+ - whitsett.tyler@gmail.com
101
+ - dphaener@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - also_energy.gemspec
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/also_energy.rb
117
+ - lib/also_energy/client.rb
118
+ - lib/also_energy/connection.rb
119
+ - lib/also_energy/hardware.rb
120
+ - lib/also_energy/hash_wrangler.rb
121
+ - lib/also_energy/site.rb
122
+ - lib/also_energy/version.rb
123
+ homepage: https://github.com/EditLLC/also-energy-ruby
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A Ruby wrapper for the AlsoEnergy API
147
+ test_files: []