portfoliomanager-rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1d08210a0f87d2a223f37ed3a7bc5d7d3c17b4a1be32d73e47bad8e4c3c146ef
4
+ data.tar.gz: 8e0e39dd94114e40d810712ff9b5f3cd127876ed40d034af39947f44dbca09b8
5
+ SHA512:
6
+ metadata.gz: fa7b8f14d72e55d96d07ee0131864b2eeebc7b2f1c972b434ad5d8dc839a7af420107dbabffcd3b29f44d97d0f37c18f5d6a829c1c0220256a5b9d0be45ab737
7
+ data.tar.gz: b36abe0b406c7e5c4a05858ed780ee9f9449b156d9c33051e577bdb0504e99abec8093d99d4842e57fed917f6ae40ec9d35f3bbb3c9b3c07f4beabbd51504b54
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.5
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.5
6
+ before_install: gem install bundler -v 2.1.4
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private --protected lib/**/*.rb - README.md CHANGELOG.md LICENSE.txt WARRANTY.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.0.1] - 2022-02-23
11
+ ### Added
12
+ - Initial commit.
13
+
14
+ [Unreleased]: https://github.com/pnnl/portfoliomanager-rb/compare/v0.0.1...HEAD
15
+ [0.0.1]: https://github.com/pnnl/portfoliomanager-rb/releases/tag/v0.0.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in portfoliomanager.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "yard", "~> 0.9"
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ portfoliomanager-rb (0.0.1)
5
+ logger-application (~> 0.0.2)
6
+ soap4r-ng (~> 2.0.4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.5.0)
12
+ logger-application (0.0.2)
13
+ rake (12.3.3)
14
+ rspec (3.11.0)
15
+ rspec-core (~> 3.11.0)
16
+ rspec-expectations (~> 3.11.0)
17
+ rspec-mocks (~> 3.11.0)
18
+ rspec-core (3.11.0)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-expectations (3.11.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-mocks (3.11.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-support (3.11.0)
27
+ soap4r-ng (2.0.4)
28
+ webrick (1.7.0)
29
+ yard (0.9.27)
30
+ webrick (~> 1.7.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ portfoliomanager-rb!
37
+ rake (~> 12.0)
38
+ rspec (~> 3.0)
39
+ yard (~> 0.9)
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2022, Battelle Memorial Institute
2
+ All rights reserved.
3
+
4
+ 1. Battelle Memorial Institute (hereinafter Battelle) hereby grants permission
5
+ to any person or entity lawfully obtaining a copy of this software and
6
+ associated documentation files (hereinafter "the Software") to redistribute
7
+ and use the Software in source and binary forms, with or without
8
+ modification. Such person or entity may use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and may permit
10
+ others to do so, subject to the following conditions:
11
+
12
+ * Redistributions of source code must retain the above copyright notice, this
13
+ list of conditions and the following disclaimers.
14
+ * Redistributions in binary form must reproduce the above copyright notice,
15
+ this list of conditions and the following disclaimer in the documentation
16
+ and/or other materials provided with the distribution.
17
+ * Other than as used herein, neither the name Battelle Memorial Institute or
18
+ Battelle may be used in any form whatsoever without the express written
19
+ consent of Battelle.
20
+
21
+ 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # ENERGY STAR Portfolio Manager - Web Services Clients in Ruby
2
+
3
+ `portfoliomanager-rb` provides clients for [ENERGY STAR Portfolio Manager Web Services](https://portfoliomanager.energystar.gov/webservices/home) for the Ruby programming language.
4
+
5
+ A short rundown of some of the major features:
6
+ * 100% API coverage (version 18.0).
7
+ ```ruby
8
+ test_client = PortfolioManager::Client::Test.new("SampleJohnDoeAccount", "Sample123")
9
+
10
+ test_client.methods
11
+ # => [:accept_reject_pending_connection_requests, :accept_reject_pending_meter_share_requests, :accept_reject_pending_property_share_requests, :add_building, :add_energy_performance_project, :add_individual_meter_to_aggregated_meter, :add_meter, :add_meter_consumption_data, :add_meter_identifier_value, :add_meter_waste_data, :add_property, :add_property_identifier_value, :add_property_use, :add_property_verification_information, :add_property_verification_professional_designation_information, :associate_building_to_a_property, :associate_meter_to_a_property, :associate_meter_to_a_property_use, :associate_meters_to_a_property, :associate_meters_to_a_property_use, :create_customer, :delete_all_individual_meters_of_an_aggregate_meter, :delete_building, :delete_consumption_data, :delete_custom_field, :delete_energy_performance_project, :delete_individual_meter_of_an_aggregated_meter, :delete_meter, :delete_meter_consumption_data, :delete_meter_identifier_value, :delete_meter_waste_data, :delete_property, :delete_property_identifier_value, :delete_property_pgp, :delete_property_use, :delete_property_verification_information, :delete_property_verification_professional_designation_information, :delete_specific_professional_designation_license_from_property_verification_information, :delete_specific_professional_designation_type_from_property_verification_information, :delete_waste_data, :disassociate_meter_from_a_property, :disassociate_meter_from_a_property_use, :disconnect_from_customer, :edit_account, :edit_billboard_setting_at_property_level_for_account, :edit_billboard_setting_at_property_level_for_customer, :edit_building, :edit_consumption_data, :edit_custom_field, :edit_customer, :edit_data_exchange_settings, :edit_design, :edit_energy_performance_project, :edit_meter, :edit_meter_identifier_value, :edit_property, :edit_property_baseline_and_target, :edit_property_edu, :edit_property_identifier_value, :edit_property_international_weather_station, :edit_property_pgp, :edit_property_use, :edit_use_details, :edit_use_details_correction, :edit_waste_data, :get_account, :get_all_meter_identifier_list, :get_associated_property_meters, :get_associated_property_use_meters, :get_billboard_metric_list, :get_billboard_setting_at_property_level_for_account, :get_billboard_setting_at_property_level_for_customer, :get_building, :get_building_list, :get_custom_field, :get_custom_field_list, :get_customer, :get_customer_custom_field_values, :get_customer_list, :get_data_exchange_settings, :get_design, :get_design_metrics, :get_egrid_subregion_list, :get_energy_performance_project, :get_energy_performance_project_list, :get_federal_agency_list, :get_id_hierarchy_for_consumption_data, :get_id_hierarchy_for_meter, :get_id_hierarchy_for_property, :get_id_hierarchy_for_property_use, :get_id_hierarchy_for_use_detail, :get_id_hierarchy_for_waste_data, :get_individual_meter_of_an_aggregated_meter, :get_international_weather_station_list, :get_meter, :get_meter_aggregation_indicator, :get_meter_aggregation_list, :get_meter_consumption_data, :get_meter_custom_field_values, :get_meter_identifier_list, :get_meter_identifier_value, :get_meter_identifier_value_list, :get_meter_list, :get_meter_waste_data, :get_notifications, :get_parent_property_list, :get_pending_connection_requests, :get_pending_meter_share_requests, :get_pending_property_share_requests, :get_professional_designation_types_list, :get_property, :get_property_baseline_and_target, :get_property_custom_field_values, :get_property_edu_list, :get_property_identifier_list, :get_property_identifier_value, :get_property_identifier_value_list, :get_property_list, :get_property_metrics, :get_property_monthly_metrics, :get_property_pgp_list, :get_property_use, :get_property_use_list, :get_property_use_metrics, :get_property_verification_information, :get_property_verification_professional_designation_information, :get_reasons_for_no_energy_score, :get_reasons_for_no_water_score, :get_use_details, :get_use_details_revision_history, :get_what_changed_consumption_data_meter_list, :get_what_changed_meter_list, :get_what_changed_meter_list_for_a_specific_property, :get_what_changed_property_list, :get_what_changed_property_use_list, :get_what_changed_property_use_list_from_use_detail_changes_only, :get_what_changed_waste_data_meter_list, :remove_building_association, :remove_instance_variable, :send_connection_request_from_test_environment, :send_meter_share_request_from_test_environment, :submit_customer_level_custom_field_values, :submit_meter_level_custom_field_values, :submit_property_level_custom_field_values, :target_finder, :unshare_meter, :unshare_property, :update_individual_meter_of_aggregated_meter, :update_property_verification_information, :update_property_verification_professional_designation_information, :update_specific_professional_designation_license_of_property_verification_information, ...]
12
+ ```
13
+ * Automated mapping between XML schemas and Ruby objects.
14
+ ```ruby
15
+ property = PortfolioManager::Xml::PropertyType.new
16
+ property.name = "My Property"
17
+
18
+ xml = PortfolioManager::Mapper.instance.obj2xml(property)
19
+ # => "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><property><name>My Property</name></property>"
20
+
21
+ obj = PortfolioManager::Mapper.instance.xml2obj(xml)
22
+ obj.name
23
+ # => "My Property"
24
+ ```
25
+ * Clients for [Live](https://portfoliomanager.energystar.gov/webservices/home/api) and [Test](https://portfoliomanager.energystar.gov/webservices/home/test/api) environments.
26
+ ```ruby
27
+ # Live Environment
28
+ live_client = PortfolioManager::Client::Live.new("SampleJohnDoeAccount", "Sample123")
29
+
30
+ # Test Environment
31
+ test_client = PortfolioManager::Client::Test.new("SampleJohnDoeAccount", "Sample123")
32
+ ```
33
+ * Debug mode with HTTP request/response logging.
34
+ ```ruby
35
+ # Test Environment with Debugging
36
+ test_client = PortfolioManager::Client::Test.new("SampleJohnDoeAccount", "Sample123", true)
37
+
38
+ account = test_client.get_account
39
+ # I, [2022-02-18T11:48:19.422074 #91494] INFO -- PortfolioManager: Request:
40
+ # Protocol: HTTP/1.2
41
+ # Method: GET
42
+ # Scheme: https
43
+ # Host: portfoliomanager.energystar.gov
44
+ # Path: /wstest/account
45
+ # QueryString:
46
+ # Body:
47
+ # Accept: application/xml, text/xml
48
+ # Authorization: Basic U2FtcGxlSm9obkRvZUFjY291bnQxMjM0NTY3OTAzOlNhbXBsZTEyMw==
49
+ #
50
+ # I, [2022-02-18T11:48:19.581841 #91494] INFO -- PortfolioManager: Response:
51
+ # Protocol: HTTP/1.1
52
+ # URI: https://portfoliomanager.energystar.gov/wstest/account
53
+ # Code: 200
54
+ # Message:
55
+ # Body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><account><id>379547</id><username>SampleJohnDoeAccount1234567903</username><password>********</password><webserviceUser>true</webserviceUser><searchable>false</searchable><includeTestPropertiesInGraphics>true</includeTestPropertiesInGraphics><emailPreferenceCanadianAccount>true</emailPreferenceCanadianAccount><contact><address address1="123 South St" city="Edmonton" state="AB" postalCode="T5G 2S7" country="CA"/><email>jack_brown@acme.com</email><firstName>Jack</firstName><phone>703-555-2121</phone><lastName>Brown</lastName><jobTitle>Building Administrator Data Exchange User</jobTitle></contact><organization name="ACME Corporation"><primaryBusiness>Other</primaryBusiness><otherBusinessDescription>other</otherBusinessDescription><energyStarPartner>true</energyStarPartner><energyStarPartnerType>Service and Product Providers</energyStarPartnerType></organization><billboardMetric>No Selection Made</billboardMetric><languagePreference>en_US</languagePreference></account>
56
+ #
57
+ # => #<PortfolioManager::Xml::AccountType:0x00007fdaedbfbfb0 @id=379547, @username="SampleJohnDoeAccount1234567903", @password="********", @webserviceUser=true, @searchable=false, @includeTestPropertiesInGraphics=true, @emailPreferenceCanadianAccount=true, @contact=#<PortfolioManager::Xml::ContactType:0x00007fdaedbfa868 @address=#<PortfolioManager::Xml::AddressType:0x00007fdaedbfa7f0 @__xmlattr={#<XSD::QName:0x1d74 {}address1>=>"123 South St", #<XSD::QName:0x1d88 {}city>=>"Edmonton", #<XSD::QName:0x1d9c {}postalCode>=>"T5G 2S7", #<XSD::QName:0x1db0 {}state>=>"AB", #<XSD::QName:0x1dc4 {}country>=>"CA"}>, @email="jack_brown@acme.com", @firstName="Jack", @phone="703-555-2121", @lastName="Brown", @jobTitle="Building Administrator Data Exchange User">, @organization=#<PortfolioManager::Xml::OrganizationType:0x00007fdaedbebdb8 @primaryBusiness="Other", @otherBusinessDescription="other", @energyStarPartner=true, @energyStarPartnerType="Service and Product Providers", @__xmlattr={#<XSD::QName:0x1dd8 {}name>=>"ACME Corporation"}>, @billboardMetric="No Selection Made", @languagePreference="en_US">
58
+ ```
59
+
60
+ ## Installation
61
+
62
+ Add this line to your application's Gemfile:
63
+
64
+ ```ruby
65
+ gem 'portfoliomanager-rb'
66
+ ```
67
+
68
+ And then execute:
69
+
70
+ $ bundle install
71
+
72
+ Or install it yourself as:
73
+
74
+ $ gem install portfoliomanager-rb
75
+
76
+ ## Usage
77
+
78
+ See YARD documentation for source code for usage instructions.
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pnnl/portfoliomanager-rb.
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of [The 2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/WARRANTY.txt ADDED
@@ -0,0 +1,22 @@
1
+ This material was prepared as an account of work sponsored by an agency of the
2
+ United States Government. Neither the United States Government nor the United
3
+ States Department of Energy, nor Battelle, nor any of their employees, nor any
4
+ jurisdiction or organization that has cooperated in the development of these
5
+ materials, makes any warranty, express or implied, or assumes any legal
6
+ liability or responsibility for the accuracy, completeness, or usefulness or any
7
+ information, apparatus, product, software, or process disclosed, or represents
8
+ that its use would not infringe privately owned rights.
9
+
10
+ Reference herein to any specific commercial product, process, or service by
11
+ trade name, trademark, manufacturer, or otherwise does not necessarily
12
+ constitute or imply its endorsement, recommendation, or favoring by the United
13
+ States Government or any agency thereof, or Battelle Memorial Institute. The
14
+ views and opinions of authors expressed herein do not necessarily state or
15
+ reflect those of the United States Government or any agency thereof.
16
+
17
+ PACIFIC NORTHWEST NATIONAL LABORATORY
18
+ operated by
19
+ BATTELLE
20
+ for the
21
+ UNITED STATES DEPARTMENT OF ENERGY
22
+ under Contract DE-AC05-76RL01830
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "portfolio_manager"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,199 @@
1
+ require "erb"
2
+ require "logger/application"
3
+ require "net/http"
4
+ require "uri"
5
+
6
+ module PortfolioManager
7
+ # HTTP Request Error
8
+ class HTTPRequestError < PortfolioManager::Error
9
+ attr_reader :request
10
+
11
+ # Default constructor.
12
+ #
13
+ # @param request [Net::HTTPRequest]
14
+ # @param args [Array<Object>]
15
+ def initialize(request, *args)
16
+ super(*args)
17
+
18
+ @request = request
19
+ end
20
+ end
21
+
22
+ # HTTP Response Error
23
+ #
24
+ # @!attribute [r] response
25
+ # @return [Net::HTTPResponse]
26
+ class HTTPResponseError < PortfolioManager::Error
27
+ attr_reader :response
28
+
29
+ # Default constructor.
30
+ #
31
+ # @param response [Net::HTTPResponse]
32
+ # @param args [Array<Object>]
33
+ def initialize(response, *args)
34
+ super(*args)
35
+
36
+ @response = response
37
+ end
38
+ end
39
+
40
+ # HTTP Basic Credentials Not Found Error
41
+ class HTTPBasicCredentialsNotFoundError < HTTPRequestError; end
42
+
43
+ module Client
44
+ # Base Client
45
+ #
46
+ # @!attribute [r] user
47
+ # @return [String]
48
+ # @!attribute [r] pass
49
+ # @return [String]
50
+ # @!attribute [r] base_uri
51
+ # @return [URI]
52
+ # @!attribute [r] debug
53
+ # @return [Boolean]
54
+ class Base < Logger::Application
55
+ attr_reader :base_uri
56
+ attr_reader :user, :pass
57
+ attr_reader :debug
58
+
59
+ # Default constructor.
60
+ #
61
+ # @param base_uri [URI]
62
+ # @param user [nil, String]
63
+ # @param pass [nil, String]
64
+ # @param debug [Boolean]
65
+ # @return [PortfolioManager::Client::Base]
66
+ def initialize(base_uri, user = nil, pass = nil, debug = false)
67
+ super("PortfolioManager")
68
+
69
+ @base_uri, @user, @pass, @debug = base_uri, user, pass, debug
70
+ end
71
+
72
+ protected
73
+
74
+ # Send HTTP request.
75
+ #
76
+ # @param verb [Class]
77
+ # @param path [String]
78
+ # @param params [Hash<String, Object>]
79
+ # @param initheader [Hash<String, String>]
80
+ # @param obj [nil, Object]
81
+ # @param elename [nil, String]
82
+ # @param klass [nil, Class]
83
+ # @param options [Hash<Symbol, Object>]
84
+ # @option options [Boolean] :basic_auth
85
+ # @return [Object]
86
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
87
+ # @raise [PortfolioManager::HTTPResponseError]
88
+ def request(verb = Net::HTTP::Get, path = "/", params = {}, initheader = {}, obj = nil, elename = nil, klass = nil, **options)
89
+ uri = url_for(path, params)
90
+
91
+ request = verb.new(uri, initheader)
92
+
93
+ request["Accept"] = "application/xml, text/xml"
94
+
95
+ unless obj.nil?
96
+ request["Content-Type"] = "application/xml; charset=UTF-8"
97
+
98
+ request.body = PortfolioManager::Mapper.instance.obj2xml(obj, elename)
99
+ end
100
+
101
+ if options[:basic_auth]
102
+ if @user.nil? || @pass.nil?
103
+ raise PortfolioManager::HTTPBasicCredentialsNotFoundError.new(request)
104
+ else
105
+ request.basic_auth(@user, @pass)
106
+ end
107
+ end
108
+
109
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.is_a?(URI::HTTPS)) do |http|
110
+ log(INFO, "Request:\n" + ([
111
+ "Protocol: HTTP/#{Net::HTTP.version_1_2? ? "1.2" : "1.1"}",
112
+ "Method: #{verb.name.split("::")[-1].upcase}",
113
+ "Scheme: #{uri.scheme}",
114
+ "Host: #{uri.host}",
115
+ "Path: #{uri.path}",
116
+ "QueryString: #{uri.query}",
117
+ "Body: #{request.body}",
118
+ ] + (["Accept", "Authorization", "Content-Type"] + initheader.keys).sort.uniq.collect { |key|
119
+ request.key?(key) ? "#{key}: #{request[key]}" : nil
120
+ }.compact).collect { |s|
121
+ "\t#{s}"
122
+ }.join("\n"))
123
+
124
+ response = http.request(request)
125
+
126
+ log(INFO, "Response:\n" + ([
127
+ "Protocol: HTTP/#{response.http_version}",
128
+ "URI: #{response.uri}",
129
+ "Code: #{response.code}",
130
+ "Message: #{response.message}",
131
+ "Body: #{response.body}",
132
+ ]).compact.collect { |s|
133
+ "\t#{s}"
134
+ }.join("\n"))
135
+
136
+ if response.body.start_with?("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
137
+ PortfolioManager::Mapper.instance.xml2obj(response.body, klass)
138
+ else
139
+ raise PortfolioManager::HTTPResponseError.new(response)
140
+ end
141
+ end
142
+ end
143
+
144
+ # Build path for the given arguments.
145
+ #
146
+ # @param args [Array<#to_s>]
147
+ # @return [String]
148
+ def path_for(*args)
149
+ "/#{args.collect { |arg| ERB::Util.url_encode(arg.to_s) }.join("/")}"
150
+ end
151
+
152
+ # Build URL for given path and query parameters.
153
+ #
154
+ # @param path [String]
155
+ # @param params [Hash<String, Object>]
156
+ # @return [URI]
157
+ def url_for(path, params = {})
158
+ query_string = params.each_pair.collect { |pair|
159
+ key, value = *pair
160
+
161
+ value.nil? ? nil : "#{ERB::Util.url_encode(key)}=#{ERB::Util.url_encode(value.to_s)}"
162
+ }.compact.join("&")
163
+
164
+ URI("#{@base_uri}#{path}#{query_string.empty? ? nil : "?#{query_string}"}")
165
+ end
166
+ end
167
+
168
+ # Live Environment Client
169
+ class Live < Base
170
+ # Default constructor.
171
+ #
172
+ # @param user [nil, String]
173
+ # @param pass [nil, String]
174
+ # @param debug [Boolean]
175
+ # @return [PortfolioManager::Client::Live]
176
+ def initialize(user = nil, pass = nil, debug = false)
177
+ super(URI("https://portfoliomanager.energystar.gov/ws"), user, pass, debug)
178
+ end
179
+
180
+ include PortfolioManager::Services::All::Live
181
+ end
182
+
183
+ # Test Environment Client
184
+ class Test < Base
185
+ # Default constructor.
186
+ #
187
+ # @param user [nil, String]
188
+ # @param pass [nil, String]
189
+ # @param debug [Boolean]
190
+ # @return [PortfolioManager::Client::Test]
191
+ def initialize(user = nil, pass = nil, debug = false)
192
+ super(URI("https://portfoliomanager.energystar.gov/wstest"), user, pass, debug)
193
+ end
194
+
195
+ include PortfolioManager::Services::All::Live
196
+ include PortfolioManager::Services::All::Test
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,14 @@
1
+ require "singleton"
2
+ require "xsd/mapping"
3
+
4
+ module PortfolioManager
5
+ # Mapper
6
+ class Mapper < XSD::Mapping::Mapper
7
+ include Singleton
8
+
9
+ # Singleton constructor.
10
+ def initialize
11
+ super(PortfolioManager::MappingRegistry::Registry)
12
+ end
13
+ end
14
+ end