green-button-data 0.2.1 → 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 +13 -5
- data/README.md +116 -8
- data/green-button-data.gemspec +6 -1
- data/lib/green-button-data.rb +26 -1
- data/lib/green-button-data/application_information.rb +112 -0
- data/lib/green-button-data/authorization.rb +35 -0
- data/lib/green-button-data/configuration.rb +133 -0
- data/lib/green-button-data/core_ext.rb +1 -0
- data/lib/green-button-data/core_ext/string.rb +35 -0
- data/lib/green-button-data/dst.rb +57 -0
- data/lib/green-button-data/entry.rb +87 -0
- data/lib/green-button-data/feed.rb +5 -0
- data/lib/green-button-data/fetchable.rb +242 -0
- data/lib/green-button-data/interval_block.rb +38 -0
- data/lib/green-button-data/local_time_parameters.rb +31 -0
- data/lib/green-button-data/meter_reading.rb +4 -0
- data/lib/green-button-data/model_collection.rb +33 -0
- data/lib/green-button-data/parser/application_information.rb +2 -11
- data/lib/green-button-data/parser/authorization.rb +0 -4
- data/lib/green-button-data/parser/interval.rb +8 -4
- data/lib/green-button-data/parser/interval_reading.rb +4 -1
- data/lib/green-button-data/parser/local_time_parameters.rb +0 -57
- data/lib/green-button-data/parser/summary_measurement.rb +12 -0
- data/lib/green-button-data/reading_type.rb +82 -0
- data/lib/green-button-data/relations.rb +24 -0
- data/lib/green-button-data/usage_point.rb +27 -0
- data/lib/green-button-data/usage_summary.rb +36 -0
- data/lib/green-button-data/utilities.rb +27 -0
- data/lib/green-button-data/version.rb +1 -1
- data/spec/fixtures.rb +5 -0
- data/spec/fixtures/ESPIReadingType.xml +23 -535
- data/spec/fixtures/ESPIReadingTypes.xml +535 -0
- data/spec/fixtures/ESPIUsagePoint.xml +3 -3
- data/spec/fixtures/ESPIUsagePointMeterReading.xml +13 -0
- data/spec/fixtures/ESPIUsagePointMeterReadings.xml +21 -0
- data/spec/fixtures/ESPIUsagePoints.xml +822 -0
- data/spec/lib/green-button-data/application_information_spec.rb +389 -0
- data/spec/lib/green-button-data/authorization_spec.rb +91 -0
- data/spec/{green-button-data → lib/green-button-data}/core_ext/date_spec.rb +0 -0
- data/spec/{green-button-data → lib/green-button-data}/core_ext/fixnum_spec.rb +0 -0
- data/spec/lib/green-button-data/local_time_parameters_spec.rb +106 -0
- data/spec/{green-button-data → lib/green-button-data}/parser/application_information_spec.rb +4 -4
- data/spec/{green-button-data → lib/green-button-data}/parser/authorization_spec.rb +0 -12
- data/spec/{green-button-data → lib/green-button-data}/parser/entry_spec.rb +1 -1
- data/spec/{green-button-data → lib/green-button-data}/parser/interval_block_spec.rb +4 -4
- data/spec/{green-button-data → lib/green-button-data}/parser/local_time_parameter_spec.rb +0 -0
- data/spec/{green-button-data → lib/green-button-data}/parser/reading_type_spec.rb +0 -0
- data/spec/{green-button-data → lib/green-button-data}/parser/usage_point_spec.rb +0 -0
- data/spec/{green-button-data → lib/green-button-data}/parser/usage_summary_spec.rb +0 -0
- data/spec/lib/green-button-data/reading_type_spec.rb +127 -0
- data/spec/lib/green-button-data/usage_point_spec.rb +167 -0
- data/spec/{green-button-data → lib/green-button-data}/utilities_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- metadata +70 -17
File without changes
|
File without changes
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GreenButtonData::LocalTimeParameters do
|
4
|
+
let(:all_url) { GreenButtonData.configuration.local_time_parameters_url }
|
5
|
+
let(:find_url) { "#{all_url}1" }
|
6
|
+
let(:token) { "c51a5047-327d-4a97-9daa-1d1296d11088" }
|
7
|
+
|
8
|
+
subject { GreenButtonData::LocalTimeParameters }
|
9
|
+
|
10
|
+
let(:local_time_parameters) { subject.find(1, token: token) }
|
11
|
+
|
12
|
+
let(:dst_starts_at) { Time.new 2015, 3, 7, 18, 0, 0, '-08:00' }
|
13
|
+
let(:dst_ends_at) { Time.new 2015, 10, 31, 19, 0, 0, '-07:00' }
|
14
|
+
let(:dst_offset) { 3600 }
|
15
|
+
let(:tz_offset) { -18000 }
|
16
|
+
let(:total_offset) { dst_offset + tz_offset }
|
17
|
+
|
18
|
+
before do
|
19
|
+
GreenButtonData.configure do |config|
|
20
|
+
config.base_url = "https://services.greenbuttondata.org/DataCustodian" +
|
21
|
+
"espi/1_1/resource"
|
22
|
+
|
23
|
+
config.local_time_parameters_path = "LocalTimeParameters/"
|
24
|
+
end
|
25
|
+
|
26
|
+
stub_request(
|
27
|
+
:get, all_url
|
28
|
+
).to_return status: 200, body: espi_local_time_parameters
|
29
|
+
|
30
|
+
stub_request(
|
31
|
+
:get, find_url
|
32
|
+
).to_return status: 200, body: espi_local_time_parameters
|
33
|
+
|
34
|
+
stub_request(
|
35
|
+
:get, "#{find_url}/"
|
36
|
+
).to_return status: 200, body: espi_local_time_parameters
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Constructor" do
|
40
|
+
it "should be a valid instance of LocalTimeParameters" do
|
41
|
+
local_time_parameters = subject.new id: "1"
|
42
|
+
expect(local_time_parameters).to be_a subject
|
43
|
+
expect(local_time_parameters.id).to eq "1"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".all" do
|
48
|
+
context "valid authorization" do
|
49
|
+
let(:collection) { subject.all token: token }
|
50
|
+
|
51
|
+
it "should return a ModelCollection" do
|
52
|
+
expect(collection).to be_a GreenButtonData::ModelCollection
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be a collection of GreenButtonData::LocalTimeParameters " +
|
56
|
+
"instances" do
|
57
|
+
|
58
|
+
expect(collection.first).to be_a subject
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should populate attributes" do
|
62
|
+
instance = collection.first
|
63
|
+
expect(instance.id).to eq "1"
|
64
|
+
expect(instance.dst_starts_at).to eq dst_starts_at
|
65
|
+
expect(instance.dst_ends_at).to eq dst_ends_at
|
66
|
+
expect(instance.dst_offset).to eq dst_offset
|
67
|
+
expect(instance.tz_offset).to eq tz_offset
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".find" do
|
73
|
+
context "valid authorization" do
|
74
|
+
it "is an instance of LocalTimeParameters" do
|
75
|
+
expect(local_time_parameters).to be_a subject
|
76
|
+
expect(WebMock).to have_requested(:get, "#{find_url}/")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should populate attributes" do
|
80
|
+
expect(local_time_parameters.id).to eq "1"
|
81
|
+
expect(local_time_parameters.dst_starts_at).to eq dst_starts_at
|
82
|
+
expect(local_time_parameters.dst_ends_at).to eq dst_ends_at
|
83
|
+
expect(local_time_parameters.dst_offset).to eq dst_offset
|
84
|
+
expect(local_time_parameters.tz_offset).to eq tz_offset
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#to_h" do
|
90
|
+
it "should return a Hash" do
|
91
|
+
expect(local_time_parameters.to_h).to be_a Hash
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should populate attributes to Hash key values" do
|
95
|
+
expect(local_time_parameters.to_h).to eq({
|
96
|
+
dst: {
|
97
|
+
starts_at: dst_starts_at,
|
98
|
+
ends_at: dst_ends_at,
|
99
|
+
offset: dst_offset
|
100
|
+
},
|
101
|
+
tz_offset: tz_offset,
|
102
|
+
total_offset: total_offset
|
103
|
+
})
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/spec/{green-button-data → lib/green-button-data}/parser/application_information_spec.rb
RENAMED
@@ -90,11 +90,11 @@ describe GreenButtonData::Parser::ApplicationInformation do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should parse date when client ID was issued" do
|
93
|
-
expect(subject.client_id_issued_at).to eq
|
93
|
+
expect(subject.client_id_issued_at).to eq 1403190000
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should parse when client secret expires" do
|
97
|
-
expect(subject.client_secret_expires_at).to eq
|
97
|
+
expect(subject.client_secret_expires_at).to eq 0
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should parse redirect URI" do
|
@@ -245,11 +245,11 @@ describe GreenButtonData::Parser::ApplicationInformation do
|
|
245
245
|
end
|
246
246
|
|
247
247
|
it "should parse date when client ID was issued" do
|
248
|
-
expect(subject.client_id_issued_at).to eq
|
248
|
+
expect(subject.client_id_issued_at).to eq 1445444481075
|
249
249
|
end
|
250
250
|
|
251
251
|
it "should parse when client secret expires" do
|
252
|
-
expect(subject.client_secret_expires_at).to eq
|
252
|
+
expect(subject.client_secret_expires_at).to eq 0
|
253
253
|
end
|
254
254
|
|
255
255
|
it "should parse redirect URI" do
|
@@ -42,12 +42,6 @@ describe GreenButtonData::Parser::Authorization do
|
|
42
42
|
it "should parse authorization URI" do
|
43
43
|
expect(subject.authorization_uri).to eq "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Authorization/4"
|
44
44
|
end
|
45
|
-
|
46
|
-
describe "#active?" do
|
47
|
-
it "should return true if status is not 0" do
|
48
|
-
expect(subject.active?).to eq true
|
49
|
-
end
|
50
|
-
end
|
51
45
|
end
|
52
46
|
|
53
47
|
context "PG&E namespace" do
|
@@ -91,11 +85,5 @@ describe GreenButtonData::Parser::Authorization do
|
|
91
85
|
it "should parse authorization URI" do
|
92
86
|
expect(subject.authorization_uri).to eq "https://api.pge.com/GreenButtonConnect/espi/1_1/resource/Authorization/0"
|
93
87
|
end
|
94
|
-
|
95
|
-
describe "#active?" do
|
96
|
-
it "should return true if status is not 0" do
|
97
|
-
expect(subject.active?).to eq true
|
98
|
-
end
|
99
|
-
end
|
100
88
|
end
|
101
89
|
end
|
@@ -19,7 +19,7 @@ describe GreenButtonData::Parser::Entry do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should parse self" do
|
22
|
-
expect(subject.self).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/
|
22
|
+
expect(subject.self).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should parse related" do
|
@@ -26,13 +26,13 @@ describe GreenButtonData::Parser::IntervalBlock do
|
|
26
26
|
|
27
27
|
describe "#starts_at" do
|
28
28
|
it "should return the start datetime" do
|
29
|
-
expect(subject.starts_at).to eq DateTime.new
|
29
|
+
expect(subject.starts_at).to eq DateTime.new(2013, 1, 1, 5).to_time
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#ends_at" do
|
34
34
|
it "should return the end datetime" do
|
35
|
-
expect(subject.ends_at).to eq DateTime.new
|
35
|
+
expect(subject.ends_at).to eq DateTime.new(2013, 2, 1, 5).to_time
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -62,13 +62,13 @@ describe GreenButtonData::Parser::IntervalBlock do
|
|
62
62
|
|
63
63
|
describe "#starts_at" do
|
64
64
|
it "should return the start datetime" do
|
65
|
-
expect(subject.starts_at).to eq DateTime.new
|
65
|
+
expect(subject.starts_at).to eq DateTime.new(2015, 4, 30, 7).to_time
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "#ends_at" do
|
70
70
|
it "should return the end datetime" do
|
71
|
-
expect(subject.ends_at).to eq DateTime.new
|
71
|
+
expect(subject.ends_at).to eq DateTime.new(2015, 8, 3, 7).to_time
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GreenButtonData::ReadingType do
|
4
|
+
let(:all_url) { GreenButtonData.configuration.reading_type_url }
|
5
|
+
let(:find_url) { "#{all_url}11" }
|
6
|
+
let(:token) { "c51a5047-327d-4a97-9daa-1d1296d11088" }
|
7
|
+
|
8
|
+
subject { GreenButtonData::ReadingType }
|
9
|
+
|
10
|
+
let(:reading_type) { subject.find(11, token: token) }
|
11
|
+
|
12
|
+
let(:accumulation_behaviour) { :delta_data }
|
13
|
+
let(:commodity) { :electricity_secondary_metered }
|
14
|
+
let(:currency) { :usd }
|
15
|
+
let(:data_qualifier) { :normal }
|
16
|
+
let(:flow_direction) { :forward }
|
17
|
+
let(:interval_length) { 300 }
|
18
|
+
let(:kind) { :energy }
|
19
|
+
let(:phase) { :s12_n }
|
20
|
+
let(:time_attribute) { :none }
|
21
|
+
let(:scale_factor) { 1.0 }
|
22
|
+
let(:unit_of_measurement) { :Wh }
|
23
|
+
|
24
|
+
before do
|
25
|
+
GreenButtonData.configure do |config|
|
26
|
+
config.base_url = "https://services.greenbuttondata.org/DataCustodian" +
|
27
|
+
"espi/1_1/resource"
|
28
|
+
|
29
|
+
config.reading_type_path = "ReadingType/"
|
30
|
+
end
|
31
|
+
|
32
|
+
stub_request(:get, all_url).to_return status: 200, body: espi_reading_types
|
33
|
+
stub_request(:get, find_url).to_return status: 200, body: espi_reading_type
|
34
|
+
|
35
|
+
stub_request(
|
36
|
+
:get, "#{find_url}/"
|
37
|
+
).to_return status: 200, body: espi_reading_type
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Constructor" do
|
41
|
+
it "should be a valid instance of ReadingType" do
|
42
|
+
reading_type = subject.new id: "1"
|
43
|
+
expect(reading_type).to be_a subject
|
44
|
+
expect(reading_type.id).to eq "1"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".all" do
|
49
|
+
context "valid authorization" do
|
50
|
+
let(:collection) { subject.all token: token }
|
51
|
+
|
52
|
+
it "should return a ModelCollection" do
|
53
|
+
expect(collection).to be_a GreenButtonData::ModelCollection
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be a collection of GreenButtonData::ReadingType instances" do
|
57
|
+
expect(collection.first).to be_a subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should populate attributes" do
|
61
|
+
instance = collection.first
|
62
|
+
expect(instance.id).to eq "11"
|
63
|
+
expect(instance.accumulation_behaviour).to eq accumulation_behaviour
|
64
|
+
expect(instance.commodity).to eq commodity
|
65
|
+
expect(instance.currency).to eq currency
|
66
|
+
expect(instance.data_qualifier).to eq data_qualifier
|
67
|
+
expect(instance.flow_direction).to eq flow_direction
|
68
|
+
expect(instance.interval_length).to eq interval_length
|
69
|
+
expect(instance.kind).to eq kind
|
70
|
+
expect(instance.phase).to eq phase
|
71
|
+
expect(instance.time_attribute).to eq time_attribute
|
72
|
+
expect(instance.scale_factor).to eq scale_factor
|
73
|
+
expect(instance.unit_of_measurement).to eq unit_of_measurement
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".find" do
|
79
|
+
context "valid authorization" do
|
80
|
+
it "is an instance of ReadingType" do
|
81
|
+
expect(reading_type).to be_a subject
|
82
|
+
expect(WebMock).to have_requested(:get, "#{find_url}/")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should populate attributes" do
|
86
|
+
expect(reading_type.id).to eq "11"
|
87
|
+
expect(reading_type.accumulation_behaviour).to eq accumulation_behaviour
|
88
|
+
expect(reading_type.commodity).to eq commodity
|
89
|
+
expect(reading_type.currency).to eq currency
|
90
|
+
expect(reading_type.data_qualifier).to eq data_qualifier
|
91
|
+
expect(reading_type.flow_direction).to eq flow_direction
|
92
|
+
expect(reading_type.interval_length).to eq interval_length
|
93
|
+
expect(reading_type.kind).to eq kind
|
94
|
+
expect(reading_type.phase).to eq phase
|
95
|
+
expect(reading_type.time_attribute).to eq time_attribute
|
96
|
+
expect(reading_type.scale_factor).to eq scale_factor
|
97
|
+
expect(reading_type.unit_of_measurement).to eq unit_of_measurement
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#to_h" do
|
103
|
+
it "should return a Hash" do
|
104
|
+
expect(reading_type.to_h).to be_a Hash
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should populate attributes to Hash key values" do
|
108
|
+
expect(reading_type.to_h).to eq({
|
109
|
+
accumulation_behaviour: accumulation_behaviour,
|
110
|
+
commodity: commodity,
|
111
|
+
consumption_tier: nil,
|
112
|
+
cpp: nil,
|
113
|
+
currency: currency,
|
114
|
+
data_qualifier: data_qualifier,
|
115
|
+
default_quality: nil,
|
116
|
+
flow_direction: flow_direction,
|
117
|
+
kind: kind,
|
118
|
+
measuring_period: nil,
|
119
|
+
phase: phase,
|
120
|
+
scale_factor: scale_factor,
|
121
|
+
time_attribute: time_attribute,
|
122
|
+
tou: nil,
|
123
|
+
unit_of_measurement: unit_of_measurement
|
124
|
+
})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GreenButtonData::UsagePoint do
|
4
|
+
let(:all_url) { GreenButtonData.configuration.usage_point_url subscription_id: 5 }
|
5
|
+
let :find_url do
|
6
|
+
"#{all_url}2"
|
7
|
+
end
|
8
|
+
let(:token) { "53520584-d640-4812-a721-8a1afa459ff7" }
|
9
|
+
|
10
|
+
subject { GreenButtonData::UsagePoint }
|
11
|
+
|
12
|
+
let(:usage_point) { subject.find(2, subscription_id: 5, token: token) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
GreenButtonData.configure do |config|
|
16
|
+
config.base_url = "https://services.greenbuttondata.org/DataCustodian/" +
|
17
|
+
"espi/1_1/resource"
|
18
|
+
config.subscription_path = "Subscription/"
|
19
|
+
config.usage_point_path = "UsagePoint/"
|
20
|
+
end
|
21
|
+
|
22
|
+
stub_request(:get, all_url).to_return status: 200, body: espi_usage_points
|
23
|
+
|
24
|
+
stub_request(:get, find_url).to_return status: 200, body: espi_usage_point
|
25
|
+
|
26
|
+
stub_request(
|
27
|
+
:get, "#{find_url}/"
|
28
|
+
).to_return status: 200, body: espi_usage_point
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Constructor" do
|
32
|
+
it "should be a valid instance of UsagePoint" do
|
33
|
+
usage_point = subject.new id: "1"
|
34
|
+
expect(usage_point).to be_a GreenButtonData::UsagePoint
|
35
|
+
expect(usage_point.id).to eq "1"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ".all" do
|
40
|
+
context "valid authorization" do
|
41
|
+
let(:collection) { subject.all(subscription_id: 5, token: token) }
|
42
|
+
|
43
|
+
it "should return a ModelCollection" do
|
44
|
+
expect(collection).to be_a GreenButtonData::ModelCollection
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be a collection of GreenButtonData::UsagePoint instances" do
|
48
|
+
expect(collection.first).to be_a GreenButtonData::UsagePoint
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should populate attributes" do
|
52
|
+
expect(collection.first.id).to eq "1"
|
53
|
+
expect(collection.first.local_time_parameters_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/LocalTimeParameters/1"
|
54
|
+
expect(collection.first.meter_reading_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/1/UsagePoint/1/MeterReading"
|
55
|
+
expect(collection.first.electric_power_usage_summary_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/1/UsagePoint/1/ElectricPowerUsageSummary"
|
56
|
+
expect(collection.first.service_category).to eq :electricity
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".find" do
|
62
|
+
context "valid authorization" do
|
63
|
+
it "is an instance of UsagePoint" do
|
64
|
+
expect(usage_point).to be_a GreenButtonData::UsagePoint
|
65
|
+
expect(WebMock).to have_requested(:get, "#{find_url}/")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should populate attributes" do
|
69
|
+
expect(usage_point.id).to eq "2"
|
70
|
+
expect(usage_point.local_time_parameters_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/LocalTimeParameters/1"
|
71
|
+
expect(usage_point.meter_reading_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/MeterReading"
|
72
|
+
expect(usage_point.electric_power_usage_summary_url).to eq "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/ElectricPowerUsageSummary"
|
73
|
+
expect(usage_point.service_category).to eq :electricity
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "relations" do
|
79
|
+
let :meter_readings_url do
|
80
|
+
"https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/MeterReading"
|
81
|
+
end
|
82
|
+
|
83
|
+
let :meter_reading_url do
|
84
|
+
"https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/MeterReading/1"
|
85
|
+
end
|
86
|
+
|
87
|
+
let :usage_summaries_url do
|
88
|
+
"https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/ElectricPowerUsageSummary"
|
89
|
+
end
|
90
|
+
|
91
|
+
let :usage_summary_url do
|
92
|
+
"https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/ElectricPowerUsageSummary/1"
|
93
|
+
end
|
94
|
+
|
95
|
+
let :interval_blocks_url do
|
96
|
+
"https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/Subscription/5/UsagePoint/2/MeterReading/1/IntervalBlock"
|
97
|
+
end
|
98
|
+
|
99
|
+
context "id of related resource is not specified" do
|
100
|
+
before do
|
101
|
+
stub_request(:get, meter_readings_url).
|
102
|
+
to_return status: 200, body: espi_usage_point_meter_readings
|
103
|
+
|
104
|
+
stub_request(:get, usage_summaries_url).
|
105
|
+
to_return status: 200, body: espi_usage_summaries
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should lazy load all related resources" do
|
109
|
+
expect(usage_point.meter_readings).to be_a GreenButtonData::ModelCollection
|
110
|
+
expect(usage_point.meter_readings.size).to eq 1
|
111
|
+
expect(usage_point.meter_readings.first).to be_a GreenButtonData::MeterReading
|
112
|
+
expect(usage_point.meter_readings.first.id).to eq "1"
|
113
|
+
expect(a_request(:get, meter_readings_url)).to have_been_made.once
|
114
|
+
|
115
|
+
expect(usage_point.usage_summaries).to be_a GreenButtonData::ModelCollection
|
116
|
+
expect(usage_point.usage_summaries.first).to be_a GreenButtonData::UsageSummary
|
117
|
+
expect(usage_point.usage_summaries.first.id).to eq "1"
|
118
|
+
expect(a_request(:get, usage_summaries_url)).to have_been_made.once
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should use cached results on subsequent calls" do
|
122
|
+
expect(usage_point.meter_readings).to be_a GreenButtonData::ModelCollection
|
123
|
+
expect(WebMock).not_to have_requested :get, meter_readings_url
|
124
|
+
expect(usage_point.usage_summaries).to be_a GreenButtonData::ModelCollection
|
125
|
+
expect(WebMock).not_to have_requested :get, usage_summaries_url
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "id of related resource is specified" do
|
130
|
+
before do
|
131
|
+
stub_request(:get, meter_reading_url).
|
132
|
+
to_return status: 200, body: espi_usage_point_meter_reading
|
133
|
+
|
134
|
+
stub_request(:get, interval_blocks_url).
|
135
|
+
to_return status: 200, body: espi_interval_block
|
136
|
+
|
137
|
+
stub_request(:get, usage_summary_url).
|
138
|
+
to_return status: 200, body: espi_usage_summary
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should lazy load a related resource that matches id" do
|
142
|
+
expect(usage_point.meter_readings(1)).to be_a GreenButtonData::MeterReading
|
143
|
+
expect(WebMock).to have_requested :get, meter_reading_url
|
144
|
+
expect(usage_point.meter_readings.size).to eq 1
|
145
|
+
expect(usage_point.meter_readings.first).to be_a GreenButtonData::MeterReading
|
146
|
+
expect(usage_point.meter_readings.first.id).to eq "1"
|
147
|
+
|
148
|
+
expect(usage_point.usage_summaries(1)).to be_a GreenButtonData::UsageSummary
|
149
|
+
expect(WebMock).to have_requested :get, usage_summary_url
|
150
|
+
expect(usage_point.usage_summaries.size).to eq 1
|
151
|
+
expect(usage_point.usage_summaries.first).to be_a GreenButtonData::UsageSummary
|
152
|
+
expect(usage_point.usage_summaries.first.id).to eq "1"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should use cached results on subsequent calls" do
|
156
|
+
expect(usage_point.meter_readings(1)).to be_a GreenButtonData::MeterReading
|
157
|
+
expect(usage_point.meter_readings(1)).to be_a GreenButtonData::MeterReading
|
158
|
+
expect(a_request(:get, meter_reading_url)).to have_been_made.once
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should lazy load a related resource two levels deep" do
|
162
|
+
expect(usage_point.meter_readings(1).interval_blocks).to be_a GreenButtonData::ModelCollection
|
163
|
+
expect(usage_point.meter_readings(1).interval_blocks.first).to be_a GreenButtonData::IntervalBlock
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|