portfolio_manager 0.3.0 → 0.5.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: d1af332f66597bbac4ea7ef5e86f9e8218ad5347
4
- data.tar.gz: '00294142f3d3f47e8c275357c8392ac8e79e6b9d'
2
+ SHA256:
3
+ metadata.gz: c11e10b4cc1d39ef7786f32cb008592026541cf755281d8cbdccf24158c7241d
4
+ data.tar.gz: 9e85f566088fcd0ef283e4d11a6fbea65c1c15c7ecb705ff7b55cbf0a13e1978
5
5
  SHA512:
6
- metadata.gz: c2054b5c323b280f07a373827b152f747f0de31e74f6e8c5e7523c46eee8a8d39c10dbfd031392db7b3f0b282f10e2025c4a7e8e15325931cd37f2718f90814a
7
- data.tar.gz: 9a963132c4eed65d85ab5de8790253165c48f907d9cb9b6a4630a2adee4a185c1f0c936f70b48b091ec69a6b036788258e1e11d64f7102d2663de048710d01b7
6
+ metadata.gz: 174a443420fd097fb6df1aebd5cf6468795619c5afc2f4ebc0bb4e00517490c152d2297d38ff7bac8810a8b15b42b90e5cf1717b6b6522790ab6662e8b7e14bf
7
+ data.tar.gz: 8201b5eb4197ed16def24025a4e5d13599ba46c89234f7ba47911fd6e2e92b08d06c6dbc2808280f931eb51a063d49ac52fdbe3bb3f5f5edb4ca29035bffab62
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
@@ -64,8 +66,26 @@ HTTP | Path | Method | Description
64
66
  ---- | ---- | ------ | -----------
65
67
  GET | /meter/(meterId) | `meter(meter_id)` | Returns information for a specified meter.
66
68
  GET | /property/(propertyId)/meter/list | `meter_list(property_id)` | Returns a list of meters for a specified property.
67
- 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.
69
+ GET | /meter/(meterId)/consumptionData?page=(page)&startDate=(YYYY-MM-DD)&endDate=(YYYY-MM-DD) | `consumption_data(meter_id, page: nil, start_date: nil, end_date: nil)` | Returns the consumption data for a specified meter in sets of 120.
68
70
 
71
+ #### Reporting Services
72
+ https://portfoliomanager.energystar.gov/webservices/home/api/reporting
73
+
74
+ HTTP | Path | Method | Description
75
+ ---- | ---- | ------ | -----------
76
+ GET | /property/(propertyId)/metrics | `property_metrics(property_id, year, month, measurement_system, metric)` | Returns the values for a specified set of metrics and units for a specific property and period ending date. The property must already be shared with you.
77
+
78
+ #### Connection/Share Services
79
+ https://portfoliomanager.energystar.gov/webservices/home/api/connection
80
+
81
+ HTTP | Path | Method | Description
82
+ ---- | ---- | ------ | -----------
83
+ GET | /connect/account/pending/list | `pending_connections(link = nil)` | Returns a list of customer connection requests that are pending.
84
+ POST | /connect/account/(accountId) | `connection_request(customer_id, accept = true)` | Accepts/rejects a pending connection request from a specific customer.
85
+ 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.
86
+ POST | /share/property/(propertyId) | `property_share_request(property_id, accept = true)` | Accepts/rejects a pending share request for a specific property.
87
+ 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.
88
+ POST | /share/meter/(meterId) | `meter_share_request(meter_id, accept = true)` | Accepts/rejects a pending share request for a specific meter.
69
89
 
70
90
  ## Contributing
71
91
 
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,8 +1,11 @@
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'
8
+ require 'portfolio_manager/rest/reporting'
6
9
  require 'portfolio_manager/rest/customer'
7
10
  require 'portfolio_manager/rest/connection'
8
11
  require 'portfolio_manager/rest/share'
@@ -18,6 +21,7 @@ module PortfolioManager
18
21
  include PortfolioManager::REST::DataExchangeSettings
19
22
  include PortfolioManager::REST::Meter
20
23
  include PortfolioManager::REST::Property
24
+ include PortfolioManager::REST::Reporting
21
25
  include PortfolioManager::REST::Customer
22
26
  include PortfolioManager::REST::Connection
23
27
  include PortfolioManager::REST::Share
@@ -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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -7,9 +9,9 @@ module PortfolioManager
7
9
  # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
8
10
  module Connection
9
11
  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
-
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
+
13
15
  ##
14
16
  # This web service returns a list of pending customer connection requests.
15
17
  # A connection to the customer must be established first before any properties and meters can be shared with you.
@@ -27,9 +29,9 @@ module PortfolioManager
27
29
  # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/connect/post
28
30
  def connection_request(customer_id, accept = true)
29
31
  perform_post_request(
30
- "/connect/account/#{customer_id}",
31
- body: connection_response_body(accept)
32
- )
32
+ "/connect/account/#{customer_id}",
33
+ body: connection_response_body(accept)
34
+ )
33
35
  end
34
36
 
35
37
  private
@@ -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
  ##
@@ -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
@@ -27,16 +29,18 @@ module PortfolioManager
27
29
  perform_get_request("/property/#{property_id}/meter/list")
28
30
  end
29
31
 
30
- def metrics(property_id, year, month, measurement_system, metric)
31
- perform_get_request(
32
- "/property/#{property_id}/metrics",
33
- query: {
34
- year: year, month: month, measurementSystem: measurement_system
35
- },
36
- header: {
37
- 'PM-Metrics' => metric
38
- }
39
- )
32
+ ##
33
+ # This web service retrieves a list of consumption data for a specific
34
+ # meter. The meter must already be shared with you.
35
+ #
36
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/meter/consumptionData/get
37
+ # page_link template:
38
+ # "/meter/#{meter_id}/consumptionData/?page=#{page}&startDate=#{start_date}&endDate=#{end_date}"
39
+ def consumption_data(meter_id, page: nil, start_date: nil, end_date: nil)
40
+ query_string = URI.encode_www_form({ page: page, startDate: start_date, endDate: end_date }.reject! {|k,v| v.nil?})
41
+ resource_path = "/meter/#{meter_id}/consumptionData"
42
+ link = query_string.empty? ? resource_path : "#{resource_path}?#{query_string}"
43
+ perform_get_request(link)
40
44
  end
41
45
  end
42
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'portfolio_manager/rest/utils'
4
+
5
+ module PortfolioManager
6
+ module REST
7
+ module Reporting
8
+ include PortfolioManager::REST::Utils
9
+
10
+ def property_metrics(property_id, year, month, measurement_system, metric)
11
+ perform_get_request(
12
+ "/property/#{property_id}/metrics",
13
+ query: {
14
+ year: year, month: month, measurementSystem: measurement_system
15
+ },
16
+ header: {
17
+ 'PM-Metrics' => metric
18
+ }
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -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
@@ -13,6 +16,7 @@ module PortfolioManager
13
16
 
14
17
  attr_reader :client, :path, :request_method, :parser
15
18
  attr_accessor :options
19
+
16
20
  ##
17
21
  # @param [PortfolioManager::Client] client
18
22
  # @param [Symbol, String] request_method
@@ -23,7 +27,10 @@ module PortfolioManager
23
27
  @path = api_environment + path
24
28
  @options = options
25
29
  @request_method = request_method
26
- @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
27
34
  @parser = Nori.new
28
35
  setup_client
29
36
  end
@@ -43,34 +50,38 @@ module PortfolioManager
43
50
  when :get
44
51
  @conn.get(path).body
45
52
  when :post
46
- @conn.post(path, options[:body], CONTENT_TYPE).body
53
+ @conn.post(path, options[:body]).body
47
54
  else
48
- raise ArgumentError, '#{request_method} is not yet implemented'
55
+ raise ArgumentError, "#{request_method} is not yet implemented"
49
56
  end
50
57
  end
51
58
 
52
59
  def setup_client
53
60
  set_header
54
61
  set_query
55
- set_basic_authentication
56
62
  end
57
63
 
58
64
  def set_header
59
- @conn.header[:user_agent] = 'Ruby PortfolioManager API Client'
60
- options[:header].each do |key, value|
61
- @conn.header[key] = value
62
- 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
63
76
  end
64
77
 
65
78
  def set_query
66
- options[:query].each do |key, value|
67
- @conn.query[key] = value
68
- end unless options[:query].nil?
69
- end
79
+ params = {}
80
+ options[:query]&.each do |key, value|
81
+ params[key] = value
82
+ end
70
83
 
71
- def set_basic_authentication
72
- @conn.url.user = client.username
73
- @conn.url.password = client.password
84
+ @conn.params = params
74
85
  end
75
86
 
76
87
  def api_environment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/utils'
2
4
 
3
5
  module PortfolioManager
@@ -9,7 +11,7 @@ module PortfolioManager
9
11
  include PortfolioManager::REST::Utils
10
12
 
11
13
  ##
12
- # Returns a list of property or meter share requests that are pending.
14
+ # Returns a list of property or meter share requests that are pending.
13
15
  # These property share requests belong to customers that you are already connected to.
14
16
  # The list of pending property share requests is returned in sets of 20.
15
17
  #
@@ -37,17 +39,17 @@ module PortfolioManager
37
39
  end
38
40
 
39
41
  private
40
-
42
+
41
43
  def pending_shares(resource_name, link)
42
- link ||= "/share/#{resource_name}/pending/list"
44
+ link ||= "/share/#{resource_name}/pending/list"
43
45
  perform_get_request(link)
44
46
  end
45
47
 
46
48
  def share_request(resource_id, resource_name, accept = true)
47
49
  perform_post_request(
48
- "/share/#{resource_name}/#{resource_id}",
49
- body: share_response_body(accept, resource_name)
50
- )
50
+ "/share/#{resource_name}/#{resource_id}",
51
+ body: share_response_body(accept, resource_name)
52
+ )
51
53
  end
52
54
 
53
55
  def share_response_body(accept, resource_name)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'portfolio_manager/rest/request'
2
4
 
3
5
  module PortfolioManager
@@ -35,11 +37,11 @@ module PortfolioManager
35
37
  end
36
38
 
37
39
  def request_response_xml(action, note)
38
- builder = Nokogiri::XML::Builder.new do |xml|
39
- xml.sharingResponse {
40
+ Nokogiri::XML::Builder.new do |xml|
41
+ xml.sharingResponse do
40
42
  xml.action action
41
43
  xml.note note
42
- }
44
+ end
43
45
  end.to_xml
44
46
  end
45
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PortfolioManager
2
- VERSION = '0.3.0'
4
+ VERSION = '0.5.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.3.0
4
+ version: 0.5.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-08-17 00:00:00.000000000 Z
11
+ date: 2024-12-04 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
@@ -120,6 +134,7 @@ files:
120
134
  - lib/portfolio_manager/rest/data_exchange_settings.rb
121
135
  - lib/portfolio_manager/rest/meter.rb
122
136
  - lib/portfolio_manager/rest/property.rb
137
+ - lib/portfolio_manager/rest/reporting.rb
123
138
  - lib/portfolio_manager/rest/request.rb
124
139
  - lib/portfolio_manager/rest/share.rb
125
140
  - lib/portfolio_manager/rest/utils.rb
@@ -129,7 +144,7 @@ homepage: https://github.com/mejackreed/portfolio_manager
129
144
  licenses:
130
145
  - MIT
131
146
  metadata: {}
132
- post_install_message:
147
+ post_install_message:
133
148
  rdoc_options: []
134
149
  require_paths:
135
150
  - lib
@@ -144,9 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
159
  - !ruby/object:Gem::Version
145
160
  version: '0'
146
161
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.5.2
149
- signing_key:
162
+ rubygems_version: 3.4.6
163
+ signing_key:
150
164
  specification_version: 4
151
165
  summary: A Ruby client for the EnergyStar Portfolio Manager web services.
152
166
  test_files: []