portfolio_manager 0.2.0 → 0.3.0
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 +4 -4
- data/lib/portfolio_manager/rest/api.rb +4 -0
- data/lib/portfolio_manager/rest/connection.rb +44 -0
- data/lib/portfolio_manager/rest/customer.rb +1 -1
- data/lib/portfolio_manager/rest/request.rb +10 -2
- data/lib/portfolio_manager/rest/share.rb +62 -0
- data/lib/portfolio_manager/rest/utils.rb +16 -0
- data/lib/portfolio_manager/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1af332f66597bbac4ea7ef5e86f9e8218ad5347
|
4
|
+
data.tar.gz: '00294142f3d3f47e8c275357c8392ac8e79e6b9d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2054b5c323b280f07a373827b152f747f0de31e74f6e8c5e7523c46eee8a8d39c10dbfd031392db7b3f0b282f10e2025c4a7e8e15325931cd37f2718f90814a
|
7
|
+
data.tar.gz: 9a963132c4eed65d85ab5de8790253165c48f907d9cb9b6a4630a2adee4a185c1f0c936f70b48b091ec69a6b036788258e1e11d64f7102d2663de048710d01b7
|
@@ -4,6 +4,8 @@ require 'portfolio_manager/rest/data_exchange_settings'
|
|
4
4
|
require 'portfolio_manager/rest/meter'
|
5
5
|
require 'portfolio_manager/rest/property'
|
6
6
|
require 'portfolio_manager/rest/customer'
|
7
|
+
require 'portfolio_manager/rest/connection'
|
8
|
+
require 'portfolio_manager/rest/share'
|
7
9
|
|
8
10
|
module PortfolioManager
|
9
11
|
module REST
|
@@ -17,6 +19,8 @@ module PortfolioManager
|
|
17
19
|
include PortfolioManager::REST::Meter
|
18
20
|
include PortfolioManager::REST::Property
|
19
21
|
include PortfolioManager::REST::Customer
|
22
|
+
include PortfolioManager::REST::Connection
|
23
|
+
include PortfolioManager::REST::Share
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'portfolio_manager/rest/utils'
|
2
|
+
|
3
|
+
module PortfolioManager
|
4
|
+
module REST
|
5
|
+
##
|
6
|
+
# Connection services
|
7
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
|
8
|
+
module Connection
|
9
|
+
include PortfolioManager::REST::Utils
|
10
|
+
REJECT_NOTE = 'Unfortunately we cannot provide services for you at this time.'.freeze
|
11
|
+
ACCEPT_NOTE = 'Your connection request has been verified and accepted.'.freeze
|
12
|
+
|
13
|
+
##
|
14
|
+
# This web service returns a list of pending customer connection requests.
|
15
|
+
# A connection to the customer must be established first before any properties and meters can be shared with you.
|
16
|
+
# The list of pending customer connection requests is returned in sets of 20.
|
17
|
+
#
|
18
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingAccountList/get
|
19
|
+
def pending_connections(link = nil)
|
20
|
+
link ||= '/connect/account/pending/list'
|
21
|
+
perform_get_request(link)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Accepts/rejects a pending connection request from a specific customer.
|
26
|
+
#
|
27
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/connect/post
|
28
|
+
def connection_request(customer_id, accept = true)
|
29
|
+
perform_post_request(
|
30
|
+
"/connect/account/#{customer_id}",
|
31
|
+
body: connection_response_body(accept)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def connection_response_body(accept)
|
38
|
+
action = accept ? 'Accept' : 'Reject'
|
39
|
+
note = accept ? ACCEPT_NOTE : REJECT_NOTE
|
40
|
+
request_response_xml(action, note)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -21,7 +21,7 @@ module PortfolioManager
|
|
21
21
|
#
|
22
22
|
# https://portfoliomanager.energystar.gov/webservices/home/api/account/customer/get
|
23
23
|
def customer(customer_id)
|
24
|
-
perform_get_request("/
|
24
|
+
perform_get_request("/customer/#{customer_id}")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -9,6 +9,7 @@ module PortfolioManager
|
|
9
9
|
BASE_URL = 'https://portfoliomanager.energystar.gov'
|
10
10
|
LIVE_PATH = '/ws'
|
11
11
|
TEST_PATH = '/wstest'
|
12
|
+
CONTENT_TYPE = 'application/xml'
|
12
13
|
|
13
14
|
attr_reader :client, :path, :request_method, :parser
|
14
15
|
attr_accessor :options
|
@@ -19,7 +20,7 @@ module PortfolioManager
|
|
19
20
|
# @param [Hash] options used for creating query params and headers
|
20
21
|
def initialize(client, request_method, path, options)
|
21
22
|
@client = client
|
22
|
-
@path = path
|
23
|
+
@path = api_environment + path
|
23
24
|
@options = options
|
24
25
|
@request_method = request_method
|
25
26
|
@conn = Hurley::Client.new(BASE_URL)
|
@@ -38,7 +39,14 @@ module PortfolioManager
|
|
38
39
|
##
|
39
40
|
# @return [String]
|
40
41
|
def response_body
|
41
|
-
|
42
|
+
case request_method
|
43
|
+
when :get
|
44
|
+
@conn.get(path).body
|
45
|
+
when :post
|
46
|
+
@conn.post(path, options[:body], CONTENT_TYPE).body
|
47
|
+
else
|
48
|
+
raise ArgumentError, '#{request_method} is not yet implemented'
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
def setup_client
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'portfolio_manager/rest/utils'
|
2
|
+
|
3
|
+
module PortfolioManager
|
4
|
+
module REST
|
5
|
+
##
|
6
|
+
# Share services
|
7
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
|
8
|
+
module Share
|
9
|
+
include PortfolioManager::REST::Utils
|
10
|
+
|
11
|
+
##
|
12
|
+
# Returns a list of property or meter share requests that are pending.
|
13
|
+
# These property share requests belong to customers that you are already connected to.
|
14
|
+
# The list of pending property share requests is returned in sets of 20.
|
15
|
+
#
|
16
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingPropertyList/get
|
17
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingMeterList/get
|
18
|
+
def pending_meter_shares(link = nil)
|
19
|
+
pending_shares(:meter, link)
|
20
|
+
end
|
21
|
+
|
22
|
+
def pending_property_shares(link = nil)
|
23
|
+
pending_shares(:property, link)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Accepts/rejects a pending share request for a specific property or meter.
|
28
|
+
#
|
29
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareProperty/post
|
30
|
+
# @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareMeter/post
|
31
|
+
def meter_share_request(meter_id, accept = true)
|
32
|
+
share_request(meter_id, :meter, accept)
|
33
|
+
end
|
34
|
+
|
35
|
+
def property_share_request(property_id, accept = true)
|
36
|
+
share_request(property_id, :property, accept)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def pending_shares(resource_name, link)
|
42
|
+
link ||= "/share/#{resource_name}/pending/list"
|
43
|
+
perform_get_request(link)
|
44
|
+
end
|
45
|
+
|
46
|
+
def share_request(resource_id, resource_name, accept = true)
|
47
|
+
perform_post_request(
|
48
|
+
"/share/#{resource_name}/#{resource_id}",
|
49
|
+
body: share_response_body(accept, resource_name)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def share_response_body(accept, resource_name)
|
54
|
+
accept_note = "Your #{resource_name} sharing request has been verified and accepted."
|
55
|
+
reject_note = "Your #{resource_name} sharing request has been rejected."
|
56
|
+
action = accept ? 'Accept' : 'Reject'
|
57
|
+
note = accept ? accept_note : reject_note
|
58
|
+
request_response_xml(action, note)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -14,6 +14,13 @@ module PortfolioManager
|
|
14
14
|
perform_request(:get, path, options)
|
15
15
|
end
|
16
16
|
|
17
|
+
##
|
18
|
+
# @param [String] path
|
19
|
+
# @param [Hash] options
|
20
|
+
def perform_post_request(path, options = {})
|
21
|
+
perform_request(:post, path, options)
|
22
|
+
end
|
23
|
+
|
17
24
|
##
|
18
25
|
# @param [Symbol, String] request_method
|
19
26
|
# @param [String] path
|
@@ -26,6 +33,15 @@ module PortfolioManager
|
|
26
33
|
options
|
27
34
|
).perform
|
28
35
|
end
|
36
|
+
|
37
|
+
def request_response_xml(action, note)
|
38
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
39
|
+
xml.sharingResponse {
|
40
|
+
xml.action action
|
41
|
+
xml.note note
|
42
|
+
}
|
43
|
+
end.to_xml
|
44
|
+
end
|
29
45
|
end
|
30
46
|
end
|
31
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: portfolio_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Reed
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hurley
|
@@ -115,11 +115,13 @@ files:
|
|
115
115
|
- lib/portfolio_manager/rest/api.rb
|
116
116
|
- lib/portfolio_manager/rest/building.rb
|
117
117
|
- lib/portfolio_manager/rest/client.rb
|
118
|
+
- lib/portfolio_manager/rest/connection.rb
|
118
119
|
- lib/portfolio_manager/rest/customer.rb
|
119
120
|
- lib/portfolio_manager/rest/data_exchange_settings.rb
|
120
121
|
- lib/portfolio_manager/rest/meter.rb
|
121
122
|
- lib/portfolio_manager/rest/property.rb
|
122
123
|
- lib/portfolio_manager/rest/request.rb
|
124
|
+
- lib/portfolio_manager/rest/share.rb
|
123
125
|
- lib/portfolio_manager/rest/utils.rb
|
124
126
|
- lib/portfolio_manager/version.rb
|
125
127
|
- portfolio_manager.gemspec
|