green-button-data 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/green-button-data.gemspec +1 -1
- data/lib/green-button-data.rb +1 -0
- data/lib/green-button-data/client.rb +18 -0
- data/lib/green-button-data/configuration.rb +13 -1
- data/lib/green-button-data/fetchable.rb +4 -0
- data/lib/green-button-data/interval_block.rb +1 -0
- data/lib/green-button-data/parser.rb +5 -0
- data/lib/green-button-data/parser/content.rb +12 -0
- data/lib/green-button-data/parser/cost_additional_detail_last_period.rb +1 -23
- data/lib/green-button-data/parser/customer_agreement.rb +15 -0
- data/lib/green-button-data/parser/main_address.rb +43 -0
- data/lib/green-button-data/parser/service_location.rb +15 -0
- data/lib/green-button-data/parser/street_detail.rb +16 -0
- data/lib/green-button-data/parser/town_detail.rb +21 -0
- data/lib/green-button-data/parser/usage_summary.rb +4 -0
- data/lib/green-button-data/retail_customer.rb +40 -0
- data/lib/green-button-data/usage_summary.rb +4 -0
- data/lib/green-button-data/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWE4MjIxNGU3MGY3OGQ3M2Y4ZTc4ZjgwYjJkNmVjYzU3MmFjZTA1Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGYxZWY5MzMwY2Y1MDhhOTU0NmVhZTY5MDk2ODlhMWQzYWNhZTMyZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmU1NDQ1NTNjYWYyYWJkMzYzNGNmYTQ2OGExNzQ1YzRlY2UwZDQ2NTAyZjk3
|
10
|
+
N2ZlNTEyZGM5Zjk3MGI4ZmZkOWI4MTMzZTQ2OTgyYTgyMjkyMjhlNzE5YmRh
|
11
|
+
OTVlYjI4YTgyNGViNmZmNDQ2ZjEyMjBmNTgzYzY0MzY5MzU0ZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWQ1ZTk4MTAzOTEwMjIwMmNkNDM1YThiMGEyMzM5OGQ5NDdjMzkwODgyMjNh
|
14
|
+
MWUwODdmMjNkNjU0NDlmYzA5MmM1ZGY2ZGNlNzBjZmYzMDlmMGYwMzM4Njcz
|
15
|
+
ZDhkNjIxMTkzNDY1ZGIyMGNiZTFjN2Q2ZTgwOGZlMzZmN2Q1ZjM=
|
data/green-button-data.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = 'http://verdigris.co'
|
10
10
|
s.licenses = ['BSD-2-Clause']
|
11
11
|
|
12
|
-
s.summary = '
|
12
|
+
s.summary = 'Client and parser for Green Button API'
|
13
13
|
s.description = 'Green Button Data is a Ruby gem that can consume Green ' +
|
14
14
|
'Button APIs and parse the Green Button data XML schema ' +
|
15
15
|
'very quickly. It uses an event-driven SAX parser which ' +
|
data/lib/green-button-data.rb
CHANGED
@@ -20,6 +20,7 @@ require 'green-button-data/meter_reading'
|
|
20
20
|
require 'green-button-data/reading_type'
|
21
21
|
require 'green-button-data/usage_point'
|
22
22
|
require 'green-button-data/usage_summary'
|
23
|
+
require 'green-button-data/retail_customer'
|
23
24
|
require 'green-button-data/client'
|
24
25
|
|
25
26
|
module GreenButtonData
|
@@ -174,6 +174,24 @@ module GreenButtonData
|
|
174
174
|
)
|
175
175
|
end
|
176
176
|
|
177
|
+
def retail_customer(id = nil, options = {})
|
178
|
+
if id.is_a? Hash
|
179
|
+
options = id
|
180
|
+
id = nil
|
181
|
+
end
|
182
|
+
|
183
|
+
retail_customer_id = options[:subscription_id]
|
184
|
+
|
185
|
+
get_resource(
|
186
|
+
@configuration.retail_customer_url(
|
187
|
+
subscription_id: retail_customer_id
|
188
|
+
),
|
189
|
+
id,
|
190
|
+
RetailCustomer,
|
191
|
+
sanitize_options(options)
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
177
195
|
private
|
178
196
|
|
179
197
|
def get_resource(url, id = nil, klazz = nil, options = {})
|
@@ -11,7 +11,8 @@ module GreenButtonData
|
|
11
11
|
:reading_type_path,
|
12
12
|
:subscription_path,
|
13
13
|
:usage_point_path,
|
14
|
-
:usage_summary_path
|
14
|
+
:usage_summary_path,
|
15
|
+
:retail_customer_path
|
15
16
|
|
16
17
|
def application_information_url(id = nil)
|
17
18
|
return build_url @application_information_path, id
|
@@ -125,6 +126,17 @@ module GreenButtonData
|
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
129
|
+
def retail_customer_url(kwargs = {})
|
130
|
+
retail_customer_id = kwargs[:subscription_id]
|
131
|
+
|
132
|
+
if retail_customer_id
|
133
|
+
retail_customer_url = build_url(@retail_customer_path)
|
134
|
+
return "#{retail_customer_url}/#{retail_customer_id}"
|
135
|
+
else
|
136
|
+
raise ArgumentError.new "Missing required arguments: subscription_id"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
128
140
|
private
|
129
141
|
|
130
142
|
def build_url(path, id = nil)
|
@@ -189,6 +189,10 @@ module GreenButtonData
|
|
189
189
|
entry.content.usage_point
|
190
190
|
when 'usagesummary'
|
191
191
|
entry.content.usage_summary
|
192
|
+
when 'servicelocation'
|
193
|
+
entry.content.service_location
|
194
|
+
when 'customeragreement'
|
195
|
+
entry.content.customer_agreement
|
192
196
|
else
|
193
197
|
nil
|
194
198
|
end
|
@@ -28,6 +28,7 @@ module GreenButtonData
|
|
28
28
|
|
29
29
|
reading[:cost] = interval_reading.cost if interval_reading.cost
|
30
30
|
reading[:quality] = interval_reading.quality if interval_reading.quality
|
31
|
+
reading[:tou] = interval_reading.tou if interval_reading.tou
|
31
32
|
|
32
33
|
result << reading
|
33
34
|
end
|
@@ -11,6 +11,11 @@ require 'green-button-data/parser/summary_measurement'
|
|
11
11
|
require 'green-button-data/parser/cost_additional_detail_last_period'
|
12
12
|
require 'green-button-data/parser/usage_point'
|
13
13
|
require 'green-button-data/parser/usage_summary'
|
14
|
+
require 'green-button-data/parser/street_detail'
|
15
|
+
require 'green-button-data/parser/town_detail'
|
16
|
+
require 'green-button-data/parser/main_address'
|
17
|
+
require 'green-button-data/parser/service_location'
|
18
|
+
require 'green-button-data/parser/customer_agreement'
|
14
19
|
require 'green-button-data/parser/content'
|
15
20
|
require 'green-button-data/parser/entry'
|
16
21
|
require 'green-button-data/parser/feed'
|
@@ -17,6 +17,10 @@ module GreenButtonData
|
|
17
17
|
element :ReadingType, class: ReadingType, as: :reading_type
|
18
18
|
element :UsagePoint, class: UsagePoint, as: :usage_point
|
19
19
|
element :UsageSummary, class: UsageSummary, as: :usage_summary
|
20
|
+
element :ServiceLocation, class: ServiceLocation,
|
21
|
+
as: :service_location
|
22
|
+
element :CustomerAgreement, class: CustomerAgreement,
|
23
|
+
as: :customer_agreement
|
20
24
|
|
21
25
|
# ESPI Namespacing
|
22
26
|
element :'espi:ApplicationInformation', class: ApplicationInformation,
|
@@ -33,6 +37,10 @@ module GreenButtonData
|
|
33
37
|
element :'espi:ReadingType', class: ReadingType, as: :reading_type
|
34
38
|
element :'espi:UsagePoint', class: UsagePoint, as: :usage_point
|
35
39
|
element :'espi:UsageSummary', class: UsageSummary, as: :usage_summary
|
40
|
+
element :'espi:ServiceLocation', class: ServiceLocation,
|
41
|
+
as: :service_location
|
42
|
+
element :'espi:CustomerAgreement', class: CustomerAgreement,
|
43
|
+
as: :customer_agreement
|
36
44
|
|
37
45
|
# Special case for PG&E generic namespaces
|
38
46
|
element :'ns0:ApplicationInformation', class: ApplicationInformation,
|
@@ -44,6 +52,10 @@ module GreenButtonData
|
|
44
52
|
element :'ns0:ReadingType', class: ReadingType, as: :reading_type
|
45
53
|
element :'ns0:UsagePoint', class: UsagePoint, as: :usage_point
|
46
54
|
element :'ns0:UsageSummary', class: UsageSummary, as: :usage_summary
|
55
|
+
element :'ns0:ServiceLocation', class: ServiceLocation,
|
56
|
+
as: :service_location
|
57
|
+
element :'ns0:CustomerAgreement', class: CustomerAgreement,
|
58
|
+
as: :customer_agreement
|
47
59
|
end
|
48
60
|
end
|
49
61
|
end
|
@@ -1,36 +1,14 @@
|
|
1
1
|
module GreenButtonData
|
2
2
|
module Parser
|
3
|
-
class CostAdditionalDetailLastPeriod
|
4
|
-
include SAXMachine
|
5
|
-
|
6
|
-
element :powerOfTenMultiplier, class: Integer,
|
7
|
-
as: :power_of_ten_multiplier
|
8
|
-
element :uom, class: Integer
|
9
|
-
element :value, class: Integer
|
3
|
+
class CostAdditionalDetailLastPeriod < SummaryMeasurement
|
10
4
|
element :note
|
11
5
|
element :itemKind, class: Integer, as: :item_kind
|
12
6
|
|
13
|
-
def value
|
14
|
-
@value
|
15
|
-
end
|
16
|
-
|
17
|
-
def note
|
18
|
-
@note
|
19
|
-
end
|
20
|
-
|
21
7
|
# ESPI Namespacing
|
22
|
-
element :'espi:powerOfTenMultiplier', class: Integer,
|
23
|
-
as: :power_of_ten_multiplier
|
24
|
-
element :'espi:uom', class: Integer, as: :uom
|
25
|
-
element :'espi:value', class: Integer, as: :value
|
26
8
|
element :'espi:note', as: :note
|
27
9
|
element :'espi:itemKind', class: Integer, as: :item_kind
|
28
10
|
|
29
11
|
# Special case for PG&E generic namespacing
|
30
|
-
element :'ns0:powerOfTenMultiplier', class: Integer,
|
31
|
-
as: :power_of_ten_multiplier
|
32
|
-
element :'ns0:uom', class: Integer, as: :uom
|
33
|
-
element :'ns0:value', class: Integer, as: :value
|
34
12
|
element :'ns0:note', as: :note
|
35
13
|
element :'ns0:itemKind', class: Integer, as: :item_kind
|
36
14
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
module Parser
|
3
|
+
class CustomerAgreement
|
4
|
+
include SAXMachine
|
5
|
+
|
6
|
+
element :name, as: :customer_agreement_id
|
7
|
+
|
8
|
+
# ESPI Namespacing
|
9
|
+
element :'espi:name', as: :customer_agreement_id
|
10
|
+
|
11
|
+
# Special case for PG&E generic namespacing
|
12
|
+
element :'ns0:name', as: :customer_agreement_id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
module Parser
|
3
|
+
class MainAddress
|
4
|
+
include SAXMachine
|
5
|
+
|
6
|
+
def town_detail_info
|
7
|
+
[town, state, zipcode].join(',')
|
8
|
+
end
|
9
|
+
|
10
|
+
def town
|
11
|
+
town_detail.name
|
12
|
+
end
|
13
|
+
|
14
|
+
def state
|
15
|
+
town_detail.state_or_province
|
16
|
+
end
|
17
|
+
|
18
|
+
def zipcode
|
19
|
+
town_detail.code.gsub(/\s+/, "")
|
20
|
+
end
|
21
|
+
|
22
|
+
def address_general
|
23
|
+
street_detail.address_general
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
address_general + ',' + town_detail_info
|
28
|
+
end
|
29
|
+
|
30
|
+
element :town_detail, class: TownDetail, as: :town_detail
|
31
|
+
element :street_detail, class: StreetDetail, as: :town_detail
|
32
|
+
|
33
|
+
|
34
|
+
# ESPI Namespacing
|
35
|
+
element :'espi:townDetail', class: TownDetail, as: :town_detail
|
36
|
+
element :'espi:streetDetail', class: StreetDetail, as: :street_detail
|
37
|
+
|
38
|
+
# Special case for PG&E generic namespacing
|
39
|
+
element :'ns0:townDetail', class: TownDetail, as: :town_detail
|
40
|
+
element :'ns0:streetDetail', class: StreetDetail, as: :street_detail
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
module Parser
|
3
|
+
class ServiceLocation
|
4
|
+
include SAXMachine
|
5
|
+
|
6
|
+
element :main_address, class: MainAddress, as: :main_address
|
7
|
+
|
8
|
+
# ESPI Namespacing
|
9
|
+
element :'espi:mainAddress', class: MainAddress, as: :main_address
|
10
|
+
|
11
|
+
# Special case for PG&E generic namespacing
|
12
|
+
element :'ns0:mainAddress', class: MainAddress, as: :main_address
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
module Parser
|
3
|
+
class StreetDetail
|
4
|
+
include SAXMachine
|
5
|
+
|
6
|
+
element :address_general, as: :address_general
|
7
|
+
|
8
|
+
# ESPI Namespacing
|
9
|
+
element :'espi:addressGeneral', as: :address_general
|
10
|
+
|
11
|
+
# Special case for PG&E generic namespacing
|
12
|
+
element :'ns0:addressGeneral', as: :address_general
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
module Parser
|
3
|
+
class TownDetail
|
4
|
+
include SAXMachine
|
5
|
+
|
6
|
+
element :state_or_province, as: :state_or_province
|
7
|
+
element :code, as: :code
|
8
|
+
element :name, as: :name
|
9
|
+
|
10
|
+
# ESPI Namespacing
|
11
|
+
element :'espi:stateOrProvince', as: :state_or_province
|
12
|
+
element :'espi:code', as: :code
|
13
|
+
element :'espi:name', as: :name
|
14
|
+
|
15
|
+
# Special case for PG&E generic namespacing
|
16
|
+
element :'ns0:stateOrProvince', as: :state_or_province
|
17
|
+
element :'ns0:code', as: :code
|
18
|
+
element :'ns0:name', as: :name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -56,6 +56,10 @@ module GreenButtonData
|
|
56
56
|
Time.at(normalize_epoch(@status_time_stamp)).utc.to_datetime
|
57
57
|
end
|
58
58
|
|
59
|
+
def cost
|
60
|
+
@bill_last_period / 100_000.0
|
61
|
+
end
|
62
|
+
|
59
63
|
# ESPI Namespacing
|
60
64
|
element :'espi:billingPeriod', class: Interval, as: :billing_period
|
61
65
|
element :'espi:billLastPeriod', class: Integer, as: :bill_last_period
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module GreenButtonData
|
2
|
+
class RetailCustomer < Entry
|
3
|
+
def has_address?
|
4
|
+
present?(address_general)
|
5
|
+
end
|
6
|
+
|
7
|
+
def has_agreement_id_map?
|
8
|
+
present?(customer_agreement_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def address_general
|
12
|
+
@main_address.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def agreement_id_service_uuid_map
|
16
|
+
{
|
17
|
+
customer_agreement_id: customer_agreement_id,
|
18
|
+
service_uuid: service_uuid
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def service_uuid
|
25
|
+
@id
|
26
|
+
end
|
27
|
+
|
28
|
+
def customer_agreement_id
|
29
|
+
@customer_agreement_id
|
30
|
+
end
|
31
|
+
|
32
|
+
def present?(data)
|
33
|
+
!blank?(data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def blank?(data)
|
37
|
+
data.respond_to?(:empty?) ? !!data.empty? : !data
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: green-button-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Jo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -152,20 +152,26 @@ files:
|
|
152
152
|
- lib/green-button-data/parser/authorization.rb
|
153
153
|
- lib/green-button-data/parser/content.rb
|
154
154
|
- lib/green-button-data/parser/cost_additional_detail_last_period.rb
|
155
|
+
- lib/green-button-data/parser/customer_agreement.rb
|
155
156
|
- lib/green-button-data/parser/entry.rb
|
156
157
|
- lib/green-button-data/parser/feed.rb
|
157
158
|
- lib/green-button-data/parser/interval.rb
|
158
159
|
- lib/green-button-data/parser/interval_block.rb
|
159
160
|
- lib/green-button-data/parser/interval_reading.rb
|
160
161
|
- lib/green-button-data/parser/local_time_parameters.rb
|
162
|
+
- lib/green-button-data/parser/main_address.rb
|
161
163
|
- lib/green-button-data/parser/rational_number.rb
|
162
164
|
- lib/green-button-data/parser/reading_type.rb
|
163
165
|
- lib/green-button-data/parser/service_category.rb
|
166
|
+
- lib/green-button-data/parser/service_location.rb
|
167
|
+
- lib/green-button-data/parser/street_detail.rb
|
164
168
|
- lib/green-button-data/parser/summary_measurement.rb
|
169
|
+
- lib/green-button-data/parser/town_detail.rb
|
165
170
|
- lib/green-button-data/parser/usage_point.rb
|
166
171
|
- lib/green-button-data/parser/usage_summary.rb
|
167
172
|
- lib/green-button-data/reading_type.rb
|
168
173
|
- lib/green-button-data/relations.rb
|
174
|
+
- lib/green-button-data/retail_customer.rb
|
169
175
|
- lib/green-button-data/usage_point.rb
|
170
176
|
- lib/green-button-data/usage_summary.rb
|
171
177
|
- lib/green-button-data/utilities.rb
|
@@ -193,6 +199,6 @@ rubyforge_project:
|
|
193
199
|
rubygems_version: 2.2.2
|
194
200
|
signing_key:
|
195
201
|
specification_version: 4
|
196
|
-
summary:
|
202
|
+
summary: Client and parser for Green Button API
|
197
203
|
test_files: []
|
198
204
|
has_rdoc:
|