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.
Files changed (54) hide show
  1. checksums.yaml +13 -5
  2. data/README.md +116 -8
  3. data/green-button-data.gemspec +6 -1
  4. data/lib/green-button-data.rb +26 -1
  5. data/lib/green-button-data/application_information.rb +112 -0
  6. data/lib/green-button-data/authorization.rb +35 -0
  7. data/lib/green-button-data/configuration.rb +133 -0
  8. data/lib/green-button-data/core_ext.rb +1 -0
  9. data/lib/green-button-data/core_ext/string.rb +35 -0
  10. data/lib/green-button-data/dst.rb +57 -0
  11. data/lib/green-button-data/entry.rb +87 -0
  12. data/lib/green-button-data/feed.rb +5 -0
  13. data/lib/green-button-data/fetchable.rb +242 -0
  14. data/lib/green-button-data/interval_block.rb +38 -0
  15. data/lib/green-button-data/local_time_parameters.rb +31 -0
  16. data/lib/green-button-data/meter_reading.rb +4 -0
  17. data/lib/green-button-data/model_collection.rb +33 -0
  18. data/lib/green-button-data/parser/application_information.rb +2 -11
  19. data/lib/green-button-data/parser/authorization.rb +0 -4
  20. data/lib/green-button-data/parser/interval.rb +8 -4
  21. data/lib/green-button-data/parser/interval_reading.rb +4 -1
  22. data/lib/green-button-data/parser/local_time_parameters.rb +0 -57
  23. data/lib/green-button-data/parser/summary_measurement.rb +12 -0
  24. data/lib/green-button-data/reading_type.rb +82 -0
  25. data/lib/green-button-data/relations.rb +24 -0
  26. data/lib/green-button-data/usage_point.rb +27 -0
  27. data/lib/green-button-data/usage_summary.rb +36 -0
  28. data/lib/green-button-data/utilities.rb +27 -0
  29. data/lib/green-button-data/version.rb +1 -1
  30. data/spec/fixtures.rb +5 -0
  31. data/spec/fixtures/ESPIReadingType.xml +23 -535
  32. data/spec/fixtures/ESPIReadingTypes.xml +535 -0
  33. data/spec/fixtures/ESPIUsagePoint.xml +3 -3
  34. data/spec/fixtures/ESPIUsagePointMeterReading.xml +13 -0
  35. data/spec/fixtures/ESPIUsagePointMeterReadings.xml +21 -0
  36. data/spec/fixtures/ESPIUsagePoints.xml +822 -0
  37. data/spec/lib/green-button-data/application_information_spec.rb +389 -0
  38. data/spec/lib/green-button-data/authorization_spec.rb +91 -0
  39. data/spec/{green-button-data → lib/green-button-data}/core_ext/date_spec.rb +0 -0
  40. data/spec/{green-button-data → lib/green-button-data}/core_ext/fixnum_spec.rb +0 -0
  41. data/spec/lib/green-button-data/local_time_parameters_spec.rb +106 -0
  42. data/spec/{green-button-data → lib/green-button-data}/parser/application_information_spec.rb +4 -4
  43. data/spec/{green-button-data → lib/green-button-data}/parser/authorization_spec.rb +0 -12
  44. data/spec/{green-button-data → lib/green-button-data}/parser/entry_spec.rb +1 -1
  45. data/spec/{green-button-data → lib/green-button-data}/parser/interval_block_spec.rb +4 -4
  46. data/spec/{green-button-data → lib/green-button-data}/parser/local_time_parameter_spec.rb +0 -0
  47. data/spec/{green-button-data → lib/green-button-data}/parser/reading_type_spec.rb +0 -0
  48. data/spec/{green-button-data → lib/green-button-data}/parser/usage_point_spec.rb +0 -0
  49. data/spec/{green-button-data → lib/green-button-data}/parser/usage_summary_spec.rb +0 -0
  50. data/spec/lib/green-button-data/reading_type_spec.rb +127 -0
  51. data/spec/lib/green-button-data/usage_point_spec.rb +167 -0
  52. data/spec/{green-button-data → lib/green-button-data}/utilities_spec.rb +1 -1
  53. data/spec/spec_helper.rb +5 -0
  54. metadata +70 -17
@@ -0,0 +1,389 @@
1
+ require "spec_helper"
2
+
3
+ describe GreenButtonData::ApplicationInformation do
4
+ let(:all_url) { GreenButtonData.configuration.application_information_url }
5
+ let(:find_url) { "#{all_url}2" }
6
+ let(:token) { "c66b0854-ea1f-4e24-afb7-afab9e0f6c5e" }
7
+
8
+ subject { GreenButtonData::ApplicationInformation }
9
+
10
+ let(:application_information) { subject.find(2, token: token) }
11
+
12
+ let :authorization_server_authorization_endpoint do
13
+ "https://services.greenbuttondata.org//DataCustodian/oauth/authorize"
14
+ end
15
+
16
+ let :authorization_server_registration_endpoint do
17
+ "https://services.greenbuttondata.org//DataCustodian/espi/1_1/register"
18
+ end
19
+
20
+ let :authorization_server_token_endpoint do
21
+ "https://services.greenbuttondata.org//DataCustodian/oauth/token"
22
+ end
23
+
24
+ let :authorization_server_uri do
25
+ "https://services.greenbuttondata.org//DataCustodian/"
26
+ end
27
+
28
+ let(:client_id) { "third_party" }
29
+ let(:client_id_issued_at) { Time.at(1403190000) }
30
+ let(:client_name) { "Green Button Third Party" }
31
+ let(:client_secret) { "secret" }
32
+ let(:client_secret_expires_at) { Time.at(2 ** (0.size * 8 - 2) - 1) }
33
+
34
+ let :contacts do
35
+ "john.teeter@energyos.org," +
36
+ "martin.burns@nist.gov," +
37
+ "donald.coffin@reminetworks.com"
38
+ end
39
+
40
+ let(:data_custodian_application_status) { :review }
41
+
42
+ let :data_custodian_bulk_request_uri do
43
+ "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/" +
44
+ "Batch/Bulk"
45
+ end
46
+
47
+ let(:data_custodian_id) { "data_custodian" }
48
+
49
+ let :data_custodian_resource_endpoint do
50
+ "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource"
51
+ end
52
+
53
+ let :data_custodian_scope_selection_screen_uri do
54
+ "https://services.greenbuttondata.org//DataCustodian/RetailCustomer/" +
55
+ "ScopeSelectionList?ThirdPartyID=third_party"
56
+ end
57
+
58
+ let :grant_types do
59
+ [
60
+ "authorization_code",
61
+ "client_credentials",
62
+ "refresh_token"
63
+ ]
64
+ end
65
+
66
+ let :redirect_uri do
67
+ "https://services.greenbuttondata.org/ThirdParty/espi/1_1/OAuthCallBack"
68
+ end
69
+
70
+ let(:registration_access_token) { "d89bb056-0f02-4d47-9fd2-ec6a19ba8d0c" }
71
+
72
+ let :registration_client_uri do
73
+ "https://services.greenbuttondata.org//DataCustodian/espi/1_1/resource/" +
74
+ "ApplicationInformation/2"
75
+ end
76
+
77
+ let(:response_types) { ["token"] }
78
+
79
+ let :scopes do
80
+ [
81
+ "FB=1_3_4_5_13_14_39;IntervalDuration=3600;BlockDuration=monthly;" +
82
+ "HistoryLength=13",
83
+ "FB=1_3_4_5_13_14_15_39;IntervalDuration=900;BlockDuration=monthly;" +
84
+ "HistoryLength=13",
85
+ "FB=1_3_4_5_6_7_8_9_10_11_29_12_13_14_15_16_17_18_19_27_28_32_33_34_35_" +
86
+ "37_38_39_40_41_44;IntervalDuration=3600;BlockDuration=monthly;" +
87
+ "HistoryLength=13"
88
+ ]
89
+ end
90
+
91
+ let(:software_id) { "EnergyOS OpenESPI Example Third Party" }
92
+ let(:software_version) { "1.2" }
93
+
94
+ let :third_party_application_description do
95
+ "EnergyOS OpenESPI Example Third Party"
96
+ end
97
+
98
+ let(:third_party_application_type) { :web }
99
+ let(:third_party_application_use) { :energy_management }
100
+
101
+ let :third_party_notify_uri do
102
+ "https://services.greenbuttondata.org/ThirdParty/espi/1_1/Notification"
103
+ end
104
+
105
+ let :third_party_scope_selection_screen_uri do
106
+ "https://services.greenbuttondata.org/ThirdParty/RetailCustomer/" +
107
+ "ScopeSelection"
108
+ end
109
+
110
+ let :third_party_user_portal_screen_uri do
111
+ "https://services.greenbuttondata.org/ThirdParty"
112
+ end
113
+
114
+ let(:token_endpoint_auth_method) { "client_secret_basic" }
115
+
116
+ before do
117
+ GreenButtonData.configure do |config|
118
+ config.base_url = "https://services.greenbuttondata.org/DataCustodian/" +
119
+ "espi/1_1/resource/"
120
+
121
+ config.application_information_path = "ApplicationInformation/"
122
+ end
123
+
124
+ stub_request(
125
+ :get, all_url
126
+ ).to_return status: 200, body: espi_application_information
127
+
128
+ stub_request(
129
+ :get, find_url
130
+ ).to_return status: 200, body: espi_application_information
131
+
132
+ stub_request(
133
+ :get, "#{find_url}/"
134
+ ).to_return status: 200, body: espi_application_information
135
+ end
136
+
137
+ describe "Constructor" do
138
+ it "should be a valid instance of ApplicationInformation" do
139
+ application_information = subject.new id: "1"
140
+ expect(application_information).to be_a subject
141
+ expect(application_information.id).to eq "1"
142
+ end
143
+ end
144
+
145
+ describe ".all" do
146
+ context "valid authorization" do
147
+ let(:collection) { subject.all(token: token) }
148
+
149
+ it "should return a ModelCollection" do
150
+ expect(collection).to be_a GreenButtonData::ModelCollection
151
+ end
152
+
153
+ it "should be a collection of GreenButtonData::ApplicationInformation " +
154
+ "instances" do
155
+
156
+ expect(collection.first).to be_a subject
157
+ end
158
+
159
+ it "should populate attributes" do
160
+ instance = collection.first
161
+ expect(instance.id).to eq "2"
162
+ expect(instance.data_custodian_id).to eq data_custodian_id
163
+
164
+ expect(
165
+ instance.data_custodian_application_status
166
+ ).to eq data_custodian_application_status
167
+
168
+ expect(
169
+ instance.data_custodian_scope_selection_screen_uri
170
+ ).to eq data_custodian_scope_selection_screen_uri
171
+
172
+ expect(
173
+ instance.data_custodian_bulk_request_uri
174
+ ).to eq data_custodian_bulk_request_uri
175
+
176
+ expect(
177
+ instance.data_custodian_resource_endpoint
178
+ ).to eq data_custodian_resource_endpoint
179
+
180
+ expect(
181
+ instance.third_party_application_type
182
+ ).to eq third_party_application_type
183
+
184
+ expect(
185
+ instance.third_party_application_use
186
+ ).to eq third_party_application_use
187
+
188
+ expect(
189
+ instance.third_party_application_description
190
+ ).to eq third_party_application_description
191
+
192
+ expect(
193
+ instance.third_party_scope_selection_screen_uri
194
+ ).to eq third_party_scope_selection_screen_uri
195
+
196
+ expect(
197
+ instance.third_party_user_portal_screen_uri
198
+ ).to eq third_party_user_portal_screen_uri
199
+
200
+ expect(instance.third_party_notify_uri).to eq third_party_notify_uri
201
+ expect(instance.authorization_server_uri).to eq authorization_server_uri
202
+
203
+ expect(
204
+ instance.authorization_server_authorization_endpoint
205
+ ).to eq authorization_server_authorization_endpoint
206
+
207
+ expect(
208
+ instance.authorization_server_registration_endpoint
209
+ ).to eq authorization_server_registration_endpoint
210
+
211
+ expect(
212
+ instance.authorization_server_token_endpoint
213
+ ).to eq authorization_server_token_endpoint
214
+
215
+ expect(
216
+ instance.token_endpoint_auth_method
217
+ ).to eq token_endpoint_auth_method
218
+
219
+ expect(instance.client_name).to eq client_name
220
+ expect(instance.client_id).to eq client_id
221
+ expect(instance.client_secret).to eq client_secret
222
+ expect(instance.client_id_issued_at).to eq client_id_issued_at
223
+ expect(instance.client_secret_expires_at).to eq client_secret_expires_at
224
+ expect(instance.redirect_uri).to eq redirect_uri
225
+ expect(instance.software_id).to eq software_id
226
+ expect(instance.software_version).to eq software_version
227
+ expect(instance.scopes).to eq scopes
228
+ expect(instance.grant_types).to eq grant_types
229
+ expect(instance.response_types).to eq response_types
230
+ expect(instance.registration_client_uri).to eq registration_client_uri
231
+
232
+ expect(
233
+ instance.registration_access_token
234
+ ).to eq registration_access_token
235
+ end
236
+ end
237
+ end
238
+
239
+ describe ".find" do
240
+ context "valid authorization" do
241
+ it "is an instance of ApplicationInformation" do
242
+ expect(application_information).to be_a subject
243
+ expect(WebMock).to have_requested(:get, "#{find_url}/")
244
+ end
245
+
246
+ it "should populate attributes" do
247
+ expect(application_information.id).to eq "2"
248
+ expect(
249
+ application_information.data_custodian_id
250
+ ).to eq data_custodian_id
251
+
252
+ expect(
253
+ application_information.data_custodian_application_status
254
+ ).to eq data_custodian_application_status
255
+
256
+ expect(
257
+ application_information.data_custodian_scope_selection_screen_uri
258
+ ).to eq data_custodian_scope_selection_screen_uri
259
+
260
+ expect(
261
+ application_information.data_custodian_bulk_request_uri
262
+ ).to eq data_custodian_bulk_request_uri
263
+
264
+ expect(
265
+ application_information.data_custodian_resource_endpoint
266
+ ).to eq data_custodian_resource_endpoint
267
+
268
+ expect(
269
+ application_information.third_party_application_type
270
+ ).to eq third_party_application_type
271
+
272
+ expect(
273
+ application_information.third_party_application_use
274
+ ).to eq third_party_application_use
275
+
276
+ expect(
277
+ application_information.third_party_application_description
278
+ ).to eq third_party_application_description
279
+
280
+ expect(
281
+ application_information.third_party_scope_selection_screen_uri
282
+ ).to eq third_party_scope_selection_screen_uri
283
+
284
+ expect(
285
+ application_information.third_party_user_portal_screen_uri
286
+ ).to eq third_party_user_portal_screen_uri
287
+
288
+ expect(
289
+ application_information.third_party_notify_uri
290
+ ).to eq third_party_notify_uri
291
+
292
+ expect(
293
+ application_information.authorization_server_uri
294
+ ).to eq authorization_server_uri
295
+
296
+ expect(
297
+ application_information.authorization_server_authorization_endpoint
298
+ ).to eq authorization_server_authorization_endpoint
299
+
300
+ expect(
301
+ application_information.authorization_server_registration_endpoint
302
+ ).to eq authorization_server_registration_endpoint
303
+
304
+ expect(
305
+ application_information.authorization_server_token_endpoint
306
+ ).to eq authorization_server_token_endpoint
307
+
308
+ expect(
309
+ application_information.token_endpoint_auth_method
310
+ ).to eq token_endpoint_auth_method
311
+
312
+ expect(application_information.client_name).to eq client_name
313
+ expect(application_information.client_id).to eq client_id
314
+ expect(application_information.client_secret).to eq client_secret
315
+
316
+ expect(
317
+ application_information.client_id_issued_at
318
+ ).to eq client_id_issued_at
319
+
320
+ expect(
321
+ application_information.client_secret_expires_at
322
+ ).to eq client_secret_expires_at
323
+
324
+ expect(application_information.redirect_uri).to eq redirect_uri
325
+ expect(application_information.software_id).to eq software_id
326
+ expect(application_information.software_version).to eq software_version
327
+ expect(application_information.scopes).to eq scopes
328
+ expect(application_information.grant_types).to eq grant_types
329
+ expect(application_information.response_types).to eq response_types
330
+
331
+ expect(
332
+ application_information.registration_client_uri
333
+ ).to eq registration_client_uri
334
+
335
+ expect(
336
+ application_information.registration_access_token
337
+ ).to eq registration_access_token
338
+ end
339
+ end
340
+ end
341
+
342
+ describe "#to_h" do
343
+ it "should return a Hash" do
344
+ expect(application_information.to_h).to be_a Hash
345
+ end
346
+
347
+ it "should populate attributes to Hash key values" do
348
+ expect(application_information.to_h).to eq({
349
+ authorization_server_authorization_endpoint:
350
+ authorization_server_authorization_endpoint,
351
+ authorization_server_registration_endpoint:
352
+ authorization_server_registration_endpoint,
353
+ authorization_server_token_endpoint:
354
+ authorization_server_token_endpoint,
355
+ authorization_server_uri: authorization_server_uri,
356
+ client_id: client_id,
357
+ client_id_issued_at: client_id_issued_at,
358
+ client_name: client_name,
359
+ client_secret: client_secret,
360
+ client_secret_expires_at: client_secret_expires_at,
361
+ contacts: contacts,
362
+ data_custodian_application_status: data_custodian_application_status,
363
+ data_custodian_bulk_request_uri: data_custodian_bulk_request_uri,
364
+ data_custodian_id: data_custodian_id,
365
+ data_custodian_resource_endpoint: data_custodian_resource_endpoint,
366
+ data_custodian_scope_selection_screen_uri:
367
+ data_custodian_scope_selection_screen_uri,
368
+ grant_types: grant_types,
369
+ redirect_uri: redirect_uri,
370
+ registration_access_token: registration_access_token,
371
+ registration_client_uri: registration_client_uri,
372
+ response_types: response_types,
373
+ scopes: scopes,
374
+ software_id: software_id,
375
+ software_version: software_version,
376
+ third_party_application_description:
377
+ third_party_application_description,
378
+ third_party_application_type: third_party_application_type,
379
+ third_party_application_use: third_party_application_use,
380
+ third_party_notify_uri: third_party_notify_uri,
381
+ third_party_phone: nil,
382
+ third_party_scope_selection_screen_uri:
383
+ third_party_scope_selection_screen_uri,
384
+ third_party_user_portal_screen_uri: third_party_user_portal_screen_uri,
385
+ token_endpoint_auth_method: token_endpoint_auth_method
386
+ })
387
+ end
388
+ end
389
+ end
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ describe GreenButtonData::Authorization do
4
+ let(:all_url) { GreenButtonData.configuration.authorization_url }
5
+ let :find_url do
6
+ "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Authorization/4"
7
+ end
8
+ let(:token) { "53520584-d640-4812-a721-8a1afa459ff7" }
9
+
10
+ subject { GreenButtonData::Authorization }
11
+
12
+ before do
13
+ GreenButtonData.configure do |config|
14
+ config.base_url = "https://services.greenbuttondata.org/DataCustodian/" +
15
+ "espi/1_1/resource/"
16
+
17
+ config.authorization_path = "Authorization/"
18
+ end
19
+
20
+ stub_request(:get, all_url).to_return status: 200, body: espi_authorization
21
+ stub_request(:get, find_url).to_return status: 200, body: espi_authorization
22
+ stub_request(
23
+ :get, "#{find_url}/"
24
+ ).to_return status: 200, body: espi_authorization
25
+ end
26
+
27
+ describe "Constructor" do
28
+ it "should be a valid instance of Authorization" do
29
+ auth = subject.new id: "1", status: :active, authorization_uri: "http://foo"
30
+ expect(auth).to be_a GreenButtonData::Authorization
31
+ expect(auth.id).to eq "1"
32
+ expect(auth.status).to eq :active
33
+ expect(auth.authorization_uri).to eq "http://foo"
34
+ expect(auth.resource_uri).to be_nil
35
+ end
36
+ end
37
+
38
+ describe ".all" do
39
+ context "valid authorization" do
40
+ let(:collection) { subject.all(token: token) }
41
+
42
+ it "should return a ModelCollection" do
43
+ expect(collection).to be_a GreenButtonData::ModelCollection
44
+ end
45
+
46
+ it "should be a collection of GreenButtonData::Authorization instances" do
47
+ expect(collection.first).to be_a GreenButtonData::Authorization
48
+ end
49
+
50
+ it "should populate attributes" do
51
+ expect(collection.first.id).to eq "4"
52
+ expect(collection.first.status).to eq :active
53
+ expect(collection.first.resource_uri).to eq "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/ApplicationInformation/2"
54
+ expect(collection.first.authorization_uri).to eq "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Authorization/4"
55
+ end
56
+ end
57
+ end
58
+
59
+ describe ".find" do
60
+ context "valid authorization" do
61
+ it "is an instance of Authorization" do
62
+ expect(subject.find(4, token: token)).to be_a GreenButtonData::Authorization
63
+ expect(subject.find("https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Authorization/4", token: token)).to be_a GreenButtonData::Authorization
64
+ end
65
+
66
+ it "should populate attributes" do
67
+ authorization = subject.find(4, token: token)
68
+ expect(authorization.id).to eq "4"
69
+ expect(authorization.status).to eq :active
70
+ expect(authorization.resource_uri).to eq "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/ApplicationInformation/2"
71
+ expect(authorization.authorization_uri).to eq "https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Authorization/4"
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#first" do
77
+ context "valid authorization" do
78
+ it "should return the first Authorization entry" do
79
+ expect(subject.first(all_url, token: token)).to be_a GreenButtonData::Authorization
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#last" do
85
+ context "valid authorization" do
86
+ it "should return the last Authorization entry" do
87
+ expect(subject.last(all_url, token: token)).to be_a GreenButtonData::Authorization
88
+ end
89
+ end
90
+ end
91
+ end