portfolio_manager 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9e73d6df7977436db99c3ba6c5d24328d71277f4
4
- data.tar.gz: 8851befec3c8da7cd756bc70a1db701f7c36957d
2
+ SHA256:
3
+ metadata.gz: 177b5b07384c5f9c24b5cb9ef69cb1517af02f1f76d9af1cc74eab9654dfe477
4
+ data.tar.gz: 87ae59aa73df92530ae4c6ea1feb139a4e8b964c6a6ca3ad39fc6249cf3acd9f
5
5
  SHA512:
6
- metadata.gz: 98f0605bd91c41974d843379c0ae1816c479b68c48a42a6a7084fb500309b532b96df464e8578379446d8755933b116f30ed6ca26f3e24d56d5aab7aadf19a0b
7
- data.tar.gz: 2f3b7d75360623a9f7baee86f621b032ea615e9ca8e49c6f08c8d9520775830af570b302efceb512e32c47e5d7f51b31f583fd7707a4cc7542123cd07b8a3b07
6
+ metadata.gz: a85026346412c4a627b41518f0b7967e113f7f6679738ff153e8953b3a1c5da587f499c4a5b635d867121d0f0fffc6e0fe9bcbdcf6f5700caf184234da16381d
7
+ data.tar.gz: 4ccfa27318accc589869fe8676f749c64a8a59e02f29cf02cb7a5f5e77622c3decb5faf4d3b14721ded9013481a7003a44e2afa49204fdcf96da17f263b66634
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in portfolio_manager.gemspec
4
6
  gemspec
5
7
 
6
8
  group :test do
7
- gem 'webmock'
8
9
  gem 'coveralls', require: false
10
+ gem 'webmock'
9
11
  end
data/README.md CHANGED
@@ -40,6 +40,8 @@ HTTP | Path | Method | Description
40
40
  GET | /account | `account` | Returns general information for your account.
41
41
  GET | /dataExchangeSettings | `data_exchange_settings` | Returns the settings that define your data exchange service offerings.
42
42
  GET | /dataExchangeSettings/customField/list | `data_exchange_custom_field_list` | Returns a list of custom fields that you have defined for your account.
43
+ GET | /customer/list | `customer_list` | Returns a list of customers that you are connected to.
44
+ GET | /customer/(customerId) | `customer(customer_id)` | Returns general account information for a specific customer that you are connected to.
43
45
 
44
46
  #### Property Services
45
47
  http://portfoliomanager.energystar.gov/webservices/home/api/property
@@ -66,6 +68,17 @@ GET | /meter/(meterId) | `meter(meter_id)` | Returns information for a specifie
66
68
  GET | /property/(propertyId)/meter/list | `meter_list(property_id)` | Returns a list of meters for a specified property.
67
69
  GET | /meter/(meterId)/consumptionData?page=(page)&startDate=(YYYY-MM-DD)&endDate=(YYYY-MM-DD) | `metrics(property_id, year, month, measurement_system, metric)` | Returns the consumption data for a specified meter in sets of 20.
68
70
 
71
+ #### Connection/Share Services
72
+ https://portfoliomanager.energystar.gov/webservices/home/api/connection
73
+
74
+ HTTP | Path | Method | Description
75
+ ---- | ---- | ------ | -----------
76
+ GET | /connect/account/pending/list | `pending_connections(link = nil)` | Returns a list of customer connection requests that are pending.
77
+ POST | /connect/account/(accountId) | `connection_request(customer_id, accept = true)` | Accepts/rejects a pending connection request from a specific customer.
78
+ GET | /share/property/pending/list | `pending_property_shares(link = nil)` | Returns a list of property share requests that are pending. These property share requests belong to customers that you are already connected to.
79
+ POST | /share/property/(propertyId) | `property_share_request(property_id, accept = true)` | Accepts/rejects a pending share request for a specific property.
80
+ GET | /share/meter/pending/list | `pending_meter_shares(link = nil)` | Returns a list of meter share requests that are pending. These meter share requests belong to customers that you are already connected to.
81
+ POST | /share/meter/(meterId) | `meter_share_request(meter_id, accept = true)` | Accepts/rejects a pending share request for a specific meter.
69
82
 
70
83
  ## Contributing
71
84
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "portfolio_manager"
4
+ require 'bundler/setup'
5
+ require 'portfolio_manager'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "portfolio_manager"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/account'
2
4
  require 'portfolio_manager/rest/building'
3
5
  require 'portfolio_manager/rest/data_exchange_settings'
4
6
  require 'portfolio_manager/rest/meter'
5
7
  require 'portfolio_manager/rest/property'
6
8
  require 'portfolio_manager/rest/customer'
9
+ require 'portfolio_manager/rest/connection'
10
+ require 'portfolio_manager/rest/share'
7
11
 
8
12
  module PortfolioManager
9
13
  module REST
@@ -17,6 +21,8 @@ module PortfolioManager
17
21
  include PortfolioManager::REST::Meter
18
22
  include PortfolioManager::REST::Property
19
23
  include PortfolioManager::REST::Customer
24
+ include PortfolioManager::REST::Connection
25
+ include PortfolioManager::REST::Share
20
26
  end
21
27
  end
22
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/api'
2
4
  require 'portfolio_manager/rest/utils'
3
5
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'portfolio_manager/rest/utils'
4
+
5
+ module PortfolioManager
6
+ module REST
7
+ ##
8
+ # Connection services
9
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
10
+ module Connection
11
+ include PortfolioManager::REST::Utils
12
+ REJECT_NOTE = 'Unfortunately we cannot provide services for you at this time.'
13
+ ACCEPT_NOTE = 'Your connection request has been verified and accepted.'
14
+
15
+ ##
16
+ # This web service returns a list of pending customer connection requests.
17
+ # A connection to the customer must be established first before any properties and meters can be shared with you.
18
+ # The list of pending customer connection requests is returned in sets of 20.
19
+ #
20
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingAccountList/get
21
+ def pending_connections(link = nil)
22
+ link ||= '/connect/account/pending/list'
23
+ perform_get_request(link)
24
+ end
25
+
26
+ ##
27
+ # Accepts/rejects a pending connection request from a specific customer.
28
+ #
29
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/connect/post
30
+ def connection_request(customer_id, accept = true)
31
+ perform_post_request(
32
+ "/connect/account/#{customer_id}",
33
+ body: connection_response_body(accept)
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def connection_response_body(accept)
40
+ action = accept ? 'Accept' : 'Reject'
41
+ note = accept ? ACCEPT_NOTE : REJECT_NOTE
42
+ request_response_xml(action, note)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -13,7 +15,7 @@ module PortfolioManager
13
15
  #
14
16
  # @see https://portfoliomanager.energystar.gov/webservices/home/api/account/customerList/get
15
17
  def customer_list
16
- perform_get_request("/customer/list")
18
+ perform_get_request('/customer/list')
17
19
  end
18
20
 
19
21
  ##
@@ -21,7 +23,7 @@ module PortfolioManager
21
23
  #
22
24
  # https://portfoliomanager.energystar.gov/webservices/home/api/account/customer/get
23
25
  def customer(customer_id)
24
- perform_get_request("/cutomer/#{customer_id}")
26
+ perform_get_request("/customer/#{customer_id}")
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -1,4 +1,7 @@
1
- require 'hurley'
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday/xml'
2
5
  require 'nori'
3
6
 
4
7
  module PortfolioManager
@@ -9,9 +12,11 @@ module PortfolioManager
9
12
  BASE_URL = 'https://portfoliomanager.energystar.gov'
10
13
  LIVE_PATH = '/ws'
11
14
  TEST_PATH = '/wstest'
15
+ CONTENT_TYPE = 'application/xml'
12
16
 
13
17
  attr_reader :client, :path, :request_method, :parser
14
18
  attr_accessor :options
19
+
15
20
  ##
16
21
  # @param [PortfolioManager::Client] client
17
22
  # @param [Symbol, String] request_method
@@ -19,10 +24,13 @@ module PortfolioManager
19
24
  # @param [Hash] options used for creating query params and headers
20
25
  def initialize(client, request_method, path, options)
21
26
  @client = client
22
- @path = path
27
+ @path = api_environment + path
23
28
  @options = options
24
29
  @request_method = request_method
25
- @conn = Hurley::Client.new(BASE_URL)
30
+ @conn = Faraday.new(url: BASE_URL) do |conn|
31
+ conn.request :authorization, :basic, client.username, client.password
32
+ conn.request :xml
33
+ end
26
34
  @parser = Nori.new
27
35
  setup_client
28
36
  end
@@ -38,31 +46,42 @@ module PortfolioManager
38
46
  ##
39
47
  # @return [String]
40
48
  def response_body
41
- @conn.public_send(request_method, api_environment + path).body
49
+ case request_method
50
+ when :get
51
+ @conn.get(path).body
52
+ when :post
53
+ @conn.post(path, options[:body]).body
54
+ else
55
+ raise ArgumentError, "#{request_method} is not yet implemented"
56
+ end
42
57
  end
43
58
 
44
59
  def setup_client
45
60
  set_header
46
61
  set_query
47
- set_basic_authentication
48
62
  end
49
63
 
50
64
  def set_header
51
- @conn.header[:user_agent] = 'Ruby PortfolioManager API Client'
52
- options[:header].each do |key, value|
53
- @conn.header[key] = value
54
- end unless options[:header].nil?
65
+ headers = {
66
+ 'User-Agent' => 'Ruby PortfolioManager API Client',
67
+ 'Accept' => 'application/xml',
68
+ 'Content-Type' => 'application/xml;charset=UTF-8'
69
+ }
70
+
71
+ options[:header]&.each do |key, value|
72
+ headers[key] = value
73
+ end
74
+
75
+ @conn.headers = headers
55
76
  end
56
77
 
57
78
  def set_query
58
- options[:query].each do |key, value|
59
- @conn.query[key] = value
60
- end unless options[:query].nil?
61
- end
79
+ params = {}
80
+ options[:query]&.each do |key, value|
81
+ params[key] = value
82
+ end
62
83
 
63
- def set_basic_authentication
64
- @conn.url.user = client.username
65
- @conn.url.password = client.password
84
+ @conn.params = params
66
85
  end
67
86
 
68
87
  def api_environment
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'portfolio_manager/rest/utils'
4
+
5
+ module PortfolioManager
6
+ module REST
7
+ ##
8
+ # Share services
9
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
10
+ module Share
11
+ include PortfolioManager::REST::Utils
12
+
13
+ ##
14
+ # Returns a list of property or meter share requests that are pending.
15
+ # These property share requests belong to customers that you are already connected to.
16
+ # The list of pending property share requests is returned in sets of 20.
17
+ #
18
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingPropertyList/get
19
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingMeterList/get
20
+ def pending_meter_shares(link = nil)
21
+ pending_shares(:meter, link)
22
+ end
23
+
24
+ def pending_property_shares(link = nil)
25
+ pending_shares(:property, link)
26
+ end
27
+
28
+ ##
29
+ # Accepts/rejects a pending share request for a specific property or meter.
30
+ #
31
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareProperty/post
32
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareMeter/post
33
+ def meter_share_request(meter_id, accept = true)
34
+ share_request(meter_id, :meter, accept)
35
+ end
36
+
37
+ def property_share_request(property_id, accept = true)
38
+ share_request(property_id, :property, accept)
39
+ end
40
+
41
+ private
42
+
43
+ def pending_shares(resource_name, link)
44
+ link ||= "/share/#{resource_name}/pending/list"
45
+ perform_get_request(link)
46
+ end
47
+
48
+ def share_request(resource_id, resource_name, accept = true)
49
+ perform_post_request(
50
+ "/share/#{resource_name}/#{resource_id}",
51
+ body: share_response_body(accept, resource_name)
52
+ )
53
+ end
54
+
55
+ def share_response_body(accept, resource_name)
56
+ accept_note = "Your #{resource_name} sharing request has been verified and accepted."
57
+ reject_note = "Your #{resource_name} sharing request has been rejected."
58
+ action = accept ? 'Accept' : 'Reject'
59
+ note = accept ? accept_note : reject_note
60
+ request_response_xml(action, note)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/request'
4
+ require 'nokogiri'
2
5
 
3
6
  module PortfolioManager
4
7
  module REST
@@ -14,6 +17,13 @@ module PortfolioManager
14
17
  perform_request(:get, path, options)
15
18
  end
16
19
 
20
+ ##
21
+ # @param [String] path
22
+ # @param [Hash] options
23
+ def perform_post_request(path, options = {})
24
+ perform_request(:post, path, options)
25
+ end
26
+
17
27
  ##
18
28
  # @param [Symbol, String] request_method
19
29
  # @param [String] path
@@ -26,6 +36,15 @@ module PortfolioManager
26
36
  options
27
37
  ).perform
28
38
  end
39
+
40
+ def request_response_xml(action, note)
41
+ Nokogiri::XML::Builder.new do |xml|
42
+ xml.sharingResponse do
43
+ xml.action action
44
+ xml.note note
45
+ end
46
+ end.to_xml
47
+ end
29
48
  end
30
49
  end
31
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PortfolioManager
2
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
3
5
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/client'
2
4
  require 'portfolio_manager/version'
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'portfolio_manager/version'
5
6
 
@@ -9,8 +10,8 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ['Jack Reed']
10
11
  spec.email = ['phillipjreed@gmail.com']
11
12
 
12
- spec.summary = %q{A Ruby client for the EnergyStar Portfolio Manager web services.}
13
- spec.description = %q{A Ruby client for the EnergyStar Portfolio Manager web services.}
13
+ spec.summary = 'A Ruby client for the EnergyStar Portfolio Manager web services.'
14
+ spec.description = 'A Ruby client for the EnergyStar Portfolio Manager web services.'
14
15
  spec.homepage = 'https://github.com/mejackreed/portfolio_manager'
15
16
  spec.license = 'MIT'
16
17
 
@@ -19,11 +20,12 @@ Gem::Specification.new do |spec|
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_dependency 'hurley'
23
+ spec.add_dependency 'faraday'
24
+ spec.add_dependency 'faraday-xml'
23
25
  spec.add_dependency 'nokogiri'
24
26
  spec.add_dependency 'nori'
25
27
 
26
- spec.add_development_dependency 'bundler', '~> 1.10'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake'
28
30
  spec.add_development_dependency 'rspec'
29
31
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portfolio_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Reed
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2023-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: hurley
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-xml
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -56,30 +70,30 @@ dependencies:
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '1.10'
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '1.10'
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '10.0'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '10.0'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -115,11 +129,13 @@ files:
115
129
  - lib/portfolio_manager/rest/api.rb
116
130
  - lib/portfolio_manager/rest/building.rb
117
131
  - lib/portfolio_manager/rest/client.rb
132
+ - lib/portfolio_manager/rest/connection.rb
118
133
  - lib/portfolio_manager/rest/customer.rb
119
134
  - lib/portfolio_manager/rest/data_exchange_settings.rb
120
135
  - lib/portfolio_manager/rest/meter.rb
121
136
  - lib/portfolio_manager/rest/property.rb
122
137
  - lib/portfolio_manager/rest/request.rb
138
+ - lib/portfolio_manager/rest/share.rb
123
139
  - lib/portfolio_manager/rest/utils.rb
124
140
  - lib/portfolio_manager/version.rb
125
141
  - portfolio_manager.gemspec
@@ -127,7 +143,7 @@ homepage: https://github.com/mejackreed/portfolio_manager
127
143
  licenses:
128
144
  - MIT
129
145
  metadata: {}
130
- post_install_message:
146
+ post_install_message:
131
147
  rdoc_options: []
132
148
  require_paths:
133
149
  - lib
@@ -142,9 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
158
  - !ruby/object:Gem::Version
143
159
  version: '0'
144
160
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.5.2
147
- signing_key:
161
+ rubygems_version: 3.4.6
162
+ signing_key:
148
163
  specification_version: 4
149
164
  summary: A Ruby client for the EnergyStar Portfolio Manager web services.
150
165
  test_files: []