green-button-data 0.1.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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +11 -0
  5. data/Guardfile +50 -0
  6. data/LICENSE.txt +26 -0
  7. data/README.md +72 -0
  8. data/Rakefile +5 -0
  9. data/green-button-data.gemspec +24 -0
  10. data/lib/green-button-data/core_ext/date.rb +9 -0
  11. data/lib/green-button-data/core_ext/fixnum.rb +10 -0
  12. data/lib/green-button-data/core_ext.rb +2 -0
  13. data/lib/green-button-data/dst.rb +49 -0
  14. data/lib/green-button-data/enumerations.rb +523 -0
  15. data/lib/green-button-data/feed.rb +7 -0
  16. data/lib/green-button-data/parser/application_information.rb +180 -0
  17. data/lib/green-button-data/parser/authorization.rb +45 -0
  18. data/lib/green-button-data/parser/content.rb +36 -0
  19. data/lib/green-button-data/parser/entry.rb +47 -0
  20. data/lib/green-button-data/parser/feed.rb +47 -0
  21. data/lib/green-button-data/parser/interval.rb +32 -0
  22. data/lib/green-button-data/parser/interval_block.rb +32 -0
  23. data/lib/green-button-data/parser/interval_reading.rb +30 -0
  24. data/lib/green-button-data/parser/local_time_parameters.rb +105 -0
  25. data/lib/green-button-data/parser/rational_number.rb +22 -0
  26. data/lib/green-button-data/parser/reading_type.rb +134 -0
  27. data/lib/green-button-data/parser/service_category.rb +17 -0
  28. data/lib/green-button-data/parser/usage_point.rb +20 -0
  29. data/lib/green-button-data/parser.rb +2 -0
  30. data/lib/green-button-data/utilities.rb +106 -0
  31. data/lib/green-button-data/version.rb +3 -0
  32. data/lib/green-button-data.rb +24 -0
  33. data/spec/fixtures/ESPIApplicationInformation.xml +49 -0
  34. data/spec/fixtures/ESPIAuthorization.xml +25 -0
  35. data/spec/fixtures/ESPIIntervalBlock.xml +3814 -0
  36. data/spec/fixtures/ESPILocalTimeParameters.xml +16 -0
  37. data/spec/fixtures/ESPIReadingType.xml +535 -0
  38. data/spec/fixtures/ESPIUsagePoint.xml +18 -0
  39. data/spec/fixtures.rb +22 -0
  40. data/spec/green-button-data/core_ext/date_spec.rb +18 -0
  41. data/spec/green-button-data/core_ext/fixnum_spec.rb +13 -0
  42. data/spec/green-button-data/parser/application_information_spec.rb +154 -0
  43. data/spec/green-button-data/parser/authorization_spec.rb +52 -0
  44. data/spec/green-button-data/parser/interval_block_spec.rb +39 -0
  45. data/spec/green-button-data/parser/local_time_parameter_spec.rb +56 -0
  46. data/spec/green-button-data/parser/reading_type_spec.rb +76 -0
  47. data/spec/green-button-data/parser/usage_point_spec.rb +22 -0
  48. data/spec/green-button-data/utilities_spec.rb +63 -0
  49. data/spec/spec_helper.rb +20 -0
  50. data/spec/support/custom_expectations/warn_expectation.rb +31 -0
  51. metadata +148 -0
@@ -0,0 +1,523 @@
1
+ module GreenButtonData
2
+ module Enumerations
3
+ ACCUMULATION = {
4
+ 0 => :none,
5
+ 1 => :bulk_quantity,
6
+ 2 => :continuous_cumulative,
7
+ 3 => :cumulative,
8
+ 4 => :delta_data,
9
+ 6 => :indicating,
10
+ 9 => :summation,
11
+ 10 => :time_delay,
12
+ 12 => :instantaneous,
13
+ 13 => :latching_quantity,
14
+ 14 => :bounded_quantity
15
+ }
16
+
17
+ AUTHORIZATION_STATUS = {
18
+ 0 => :revoked,
19
+ 1 => :active,
20
+ 2 => :denied
21
+ }
22
+
23
+ COMMODITY = {
24
+ 0 => :none, # NA
25
+ 1 => :electricity_secondary_metered, # Secondary electricity meter
26
+ 2 => :electricity_primary_metered, # Primary electricity meter
27
+ 3 => :communication, # A measurement of the communication infrastructure itself
28
+ 4 => :air, # Air
29
+ 5 => :insulative_gas, # SF6 is found below (ID: 22)
30
+ 6 => :insulative_oil, # Oil for insulation
31
+ 7 => :natural_gas, # Natural gas (LNG)
32
+ 8 => :propane, # Propane gas (LPG)
33
+ 9 => :potable_water, # Drinkable water (drinking fountains)
34
+ 10 => :steam, # Water in steam form; usually for heating
35
+ 11 => :waste_water, # Sewerage
36
+ 12 => :heating_fluid, # Fluid for heating in liquid form
37
+ 13 => :cooling_fluid, # Cooling fluid; returns warmer than sent
38
+ 14 => :nonpotable_water, # Reclaimed water
39
+ 15 => :nox, # Nitrous Oxides
40
+ 16 => :so2, # Sulfur Dioxide SO₂
41
+ 17 => :ch4, # Methane CH₄
42
+ 18 => :co2, # Carbon Dioxide CO₂
43
+ 19 => :carbon, # Carbon
44
+ 20 => :hch, # Hexachlorocyclohexane HCH
45
+ 21 => :pfc, # Perfluorocarbons PFC
46
+ 22 => :sf6, # Sulfurhexafluoride SF₆
47
+ 23 => :tv_license, # Television
48
+ 24 => :internet, # Internet service
49
+ 25 => :refuse # Trash
50
+ }
51
+
52
+ CURRENCY = {
53
+ 0 => :other,
54
+ 36 => :aud,
55
+ 124 => :cad,
56
+ 156 => :cny,
57
+ 208 => :dkk,
58
+ 356 => :inr,
59
+ 392 => :jpy,
60
+ 578 => :nok,
61
+ 643 => :rub,
62
+ 752 => :sek,
63
+ 756 => :chf,
64
+ 826 => :gbp,
65
+ 840 => :usd,
66
+ 978 => :eur
67
+ }
68
+
69
+ DATA_CUSTODIAN_APPLICATION_STATUS = {
70
+ 1 => :review,
71
+ 2 => :production,
72
+ 3 => :on_hold,
73
+ 4 => :revoked
74
+ }
75
+
76
+ DATA_QUALIFIER = {
77
+ 0 => :none,
78
+ 2 => :average,
79
+ 4 => :excess,
80
+ 5 => :high_threshold,
81
+ 7 => :low_threshold,
82
+ 8 => :maximum,
83
+ 9 => :minimum,
84
+ 11 => :nominal,
85
+ 12 => :normal,
86
+ 16 => :second_maximum,
87
+ 17 => :second_minimum,
88
+ 23 => :third_maximum,
89
+ 24 => :fourth_maximum,
90
+ 25 => :fifth_maximum,
91
+ 26 => :sum
92
+ }
93
+
94
+ ESPI_SERVICE_STATUS = {
95
+ 0 => :unavailable,
96
+ 1 => :normal
97
+ }
98
+
99
+ FLOW_DIRECTION = {
100
+ 0 => :none,
101
+ 1 => :forward,
102
+ 2 => :lagging,
103
+ 3 => :leading,
104
+ 4 => :net,
105
+ 5 => :q1plus_q2,
106
+ 7 => :q1plus_q3,
107
+ 8 => :q1plus_q4,
108
+ 9 => :q1minus_q4,
109
+ 10 => :q2plus_q3,
110
+ 11 => :q2plus_q4,
111
+ 12 => :q2minus_q3,
112
+ 13 => :q3plus_q4,
113
+ 14 => :q3minus_q2,
114
+ 15 => :quadrant1,
115
+ 16 => :quadrant2,
116
+ 17 => :quadrant3,
117
+ 18 => :quadrant4,
118
+ 19 => :reverse,
119
+ 20 => :total,
120
+ 21 => :total_by_phase
121
+ }
122
+
123
+ MEASUREMENT = {
124
+ 0 => :none,
125
+ 2 => :apparent_power_factor,
126
+ 3 => :currency,
127
+ 4 => :current,
128
+ 5 => :current_angle,
129
+ 6 => :current_imbalance,
130
+ 7 => :date,
131
+ 8 => :demand,
132
+ 9 => :distance,
133
+ 10 => :distortion_volt_amperes,
134
+ 11 => :energization,
135
+ 12 => :energy,
136
+ 13 => :energization_load_side,
137
+ 14 => :fan,
138
+ 15 => :frequency,
139
+ 16 => :funds,
140
+ 17 => :ieee1366asai,
141
+ 18 => :ieee1366asidi,
142
+ 19 => :ieee1366asifi,
143
+ 20 => :ieee1366caidi,
144
+ 21 => :ieee1366caifi,
145
+ 22 => :ieee1366cemin,
146
+ 23 => :ieee1366cemsmin,
147
+ 24 => :ieee1366ctaidi,
148
+ 25 => :ieee1366maifi,
149
+ 26 => :ieee1366maifie,
150
+ 27 => :ieee1366saidi,
151
+ 28 => :ieee1366saifi,
152
+ 31 => :line_losses,
153
+ 32 => :losses,
154
+ 33 => :negative_sequence,
155
+ 34 => :phasor_power_factor,
156
+ 35 => :phasor_reactive_power,
157
+ 36 => :positive_sequence,
158
+ 37 => :power,
159
+ 38 => :power_factor,
160
+ 40 => :quantity_power,
161
+ 41 => :sag,
162
+ 42 => :swell,
163
+ 43 => :switch_position,
164
+ 44 => :tap_position,
165
+ 45 => :tariff_rate,
166
+ 46 => :temperature,
167
+ 47 => :total_harmonic_distortion,
168
+ 48 => :transformer_losses,
169
+ 49 => :unipede_voltage_dip_10_to_15,
170
+ 50 => :unipede_voltage_dip_15_to_30,
171
+ 51 => :unipede_voltage_dip_30_to_60,
172
+ 52 => :unipede_voltage_dip_60_to_90,
173
+ 53 => :unipede_voltage_dip_90_to_100,
174
+ 54 => :voltage,
175
+ 55 => :voltage_angle,
176
+ 56 => :voltage_excursion,
177
+ 57 => :voltage_imbalance,
178
+ 58 => :volume,
179
+ 59 => :zero_flow_duration,
180
+ 60 => :zero_sequence,
181
+ 64 => :distortion_power_factor,
182
+ 81 => :frequency_excursion,
183
+ 90 => :application_context,
184
+ 91 => :ap_title,
185
+ 92 => :asset_number,
186
+ 93 => :bandwidth,
187
+ 94 => :battery_voltage,
188
+ 95 => :broadcast_address,
189
+ 96 => :device_address_type_1,
190
+ 97 => :device_address_type_2,
191
+ 98 => :device_address_type_3,
192
+ 99 => :device_address_type_4,
193
+ 100 => :device_class,
194
+ 101 => :electronic_serial_number,
195
+ 102 => :end_device_id,
196
+ 103 => :group_address_type_1,
197
+ 104 => :group_address_type_2,
198
+ 105 => :group_address_type_3,
199
+ 106 => :group_address_type_4,
200
+ 107 => :ip_address,
201
+ 108 => :mac_address,
202
+ 109 => :mfg_assigned_configuration_id,
203
+ 110 => :mfg_assigned_physical_serial_number,
204
+ 111 => :mfg_assigned_product_number,
205
+ 112 => :mfg_assigned_unique_communication_address,
206
+ 113 => :multi_cast_address,
207
+ 114 => :one_way_address,
208
+ 115 => :signal_strength,
209
+ 116 => :two_way_address,
210
+ 117 => :signal_to_noise_ratio,
211
+ 118 => :alarm,
212
+ 119 => :battery_carry_over,
213
+ 120 => :data_overflow_alarm,
214
+ 121 => :demand_limit,
215
+ 122 => :demand_reset,
216
+ 123 => :diagnostic,
217
+ 124 => :emergency_limit,
218
+ 125 => :encoder_tamper,
219
+ 126 => :ieee1366_momentary_interruption,
220
+ 127 => :ieee1366_momentary_interruption_event,
221
+ 128 => :ieee1366_sustained_interruption,
222
+ 129 => :interruption_behaviour,
223
+ 130 => :inversion_tamper,
224
+ 131 => :load_interrupt,
225
+ 132 => :load_shed,
226
+ 133 => :maintenance,
227
+ 134 => :physical_tamper,
228
+ 135 => :power_loss_tamper,
229
+ 136 => :power_outage,
230
+ 137 => :power_quality,
231
+ 138 => :power_restoration,
232
+ 139 => :programmed,
233
+ 140 => :push_button,
234
+ 141 => :relay_activation,
235
+ 142 => :relay_cycle,
236
+ 143 => :removal_tamper,
237
+ 144 => :reprogramming_tamper,
238
+ 145 => :reverse_rotation_tamper,
239
+ 146 => :switch_armed,
240
+ 147 => :switch_disabled,
241
+ 148 => :tamper,
242
+ 150 => :bill_last_period,
243
+ 151 => :bill_to_date,
244
+ 152 => :bill_carryover,
245
+ 153 => :connection_fee,
246
+ 154 => :audible_volume,
247
+ 155 => :volumetric_flow
248
+ }
249
+
250
+ QUALITY_OF_READING = {
251
+ 0 => :valid,
252
+ 7 => :manually_edited,
253
+ 8 => :estimated_using_reference_day,
254
+ 9 => :estimated_using_linear_interpolation,
255
+ 10 => :questionable,
256
+ 11 => :derived,
257
+ 12 => :projected_forecast,
258
+ 13 => :mixed,
259
+ 14 => :raw,
260
+ 15 => :normalized_for_weather,
261
+ 16 => :other,
262
+ 17 => :validated,
263
+ 18 => :verified,
264
+ 19 => :revenue_quality
265
+ }
266
+
267
+ PHASE_CODE = {
268
+ 0 => :none,
269
+ 16 => :n,
270
+ 17 => :n_g,
271
+ 32 => :c,
272
+ 33 => :c_n,
273
+ 40 => :c_av,
274
+ 41 => :ca_n,
275
+ 64 => :b,
276
+ 65 => :b_n,
277
+ 66 => :b_c,
278
+ 72 => :b_av,
279
+ 97 => :b_c_n, # TODO: Check with GB XML schema maintainers? https://github.com/energyos/OpenESPI-Common-java/blob/master/etc/espiDerived.xsd
280
+ 97 => :a_c_n,
281
+ 128 => :a,
282
+ 129 => :a_n,
283
+ 132 => :a_b,
284
+ 136 => :a_to_av,
285
+ 193 => :a_b_n,
286
+ 224 => :a_b_c,
287
+ 225 => :a_b_c_n,
288
+ 272 => :s2_n,
289
+ 512 => :s1,
290
+ 528 => :s1_n,
291
+ 768 => :s1_2,
292
+ 769 => :s12_n,
293
+ 784 => :s1_2_n
294
+ }
295
+
296
+ SERVICE = {
297
+ 0 => :electricity,
298
+ 1 => :gas,
299
+ 2 => :water,
300
+ 3 => :time,
301
+ 4 => :heat,
302
+ 5 => :refuse,
303
+ 6 => :sewerage,
304
+ 7 => :rates,
305
+ 8 => :tv_license,
306
+ 9 => :internet
307
+ }
308
+
309
+ THIRD_PARTY_APPLICATION_STATUS = {
310
+ 1 => :development,
311
+ 2 => :review_test,
312
+ 3 => :production,
313
+ 4 => :retired
314
+ }
315
+
316
+ THIRD_PARTY_APPLICATION_TYPE = {
317
+ 1 => :web,
318
+ 2 => :desktop,
319
+ 3 => :mobile,
320
+ 4 => :device
321
+ }
322
+
323
+ THIRD_PARTY_APPLICATION_USE = {
324
+ 1 => :energy_management,
325
+ 2 => :comparisons,
326
+ 3 => :government,
327
+ 4 => :academic,
328
+ 5 => :law_enforcement
329
+ }
330
+
331
+ TIME_ATTRIBUTE = {
332
+ 0 => :none,
333
+ 1 => :ten_minute,
334
+ 2 => :fifteen_minute,
335
+ 3 => :one_minute,
336
+ 4 => :twenty_four_hour,
337
+ 5 => :thirty_minute,
338
+ 6 => :five_minute,
339
+ 7 => :sixty_minute,
340
+ 10 => :two_minute,
341
+ 14 => :three_minute,
342
+ 15 => :present,
343
+ 16 => :previous,
344
+ 31 => :twenty_minute,
345
+ 50 => :fixed_block_60_min,
346
+ 51 => :fixed_block_30_min,
347
+ 52 => :fixed_block_20_min,
348
+ 53 => :fixed_block_15_min,
349
+ 54 => :fixed_block_10_min,
350
+ 55 => :fixed_block_5_min,
351
+ 56 => :fixed_block_1_min,
352
+ 57 => :rolling_block_60_min_interval_30_min_sub_interval,
353
+ 58 => :rolling_block_60_min_interval_20_min_sub_interval,
354
+ 59 => :rolling_block_60_min_interval_15_min_sub_interval,
355
+ 60 => :rolling_block_60_min_interval_12_min_sub_interval,
356
+ 61 => :rolling_block_60_min_interval_10_min_sub_interval,
357
+ 62 => :rolling_block_60_min_interval_6_min_sub_interval,
358
+ 63 => :rolling_block_60_min_interval_5_min_sub_interval,
359
+ 64 => :rolling_block_60_min_interval_4_min_sub_interval,
360
+ 65 => :rolling_block_30_min_interval_15_min_sub_interval,
361
+ 66 => :rolling_block_30_min_interval_10_min_sub_interval,
362
+ 67 => :rolling_block_30_min_interval_6_min_sub_interval,
363
+ 68 => :rolling_block_30_min_interval_5_min_sub_interval,
364
+ 69 => :rolling_block_30_min_interval_3_min_sub_interval,
365
+ 70 => :rolling_block_30_min_interval_2_min_sub_interval,
366
+ 71 => :rolling_block_15_min_interval_5_min_sub_interval,
367
+ 72 => :rolling_block_15_min_interval_3_min_sub_interval,
368
+ 73 => :rolling_block_15_min_interval_1_min_sub_interval,
369
+ 74 => :rolling_block_10_min_interval_5_min_sub_interval,
370
+ 75 => :rolling_block_10_min_interval_2_min_sub_interval,
371
+ 76 => :rolling_block_10_min_interval_1_min_sub_interval,
372
+ 77 => :rolling_block_5_min_interval_1_min_sub_interval
373
+ }
374
+
375
+ TIME_PERIOD_OF_INTEREST = {
376
+ 0 => :none,
377
+ 8 => :billing_period,
378
+ 11 => :daily,
379
+ 13 => :monthly,
380
+ 22 => :seasonal,
381
+ 24 => :weekly,
382
+ 32 => :specified_period
383
+ }
384
+
385
+ UNIT_MULTIPLIER = {
386
+ -12 => :p, # Pico: 10^-12
387
+ -9 => :n, # Nano: 10^-9
388
+ -6 => :micro, # Micro: 10^-6
389
+ -3 => :m, # Milli: 10^-3
390
+ -1 => :d, # Deci: 10^-1
391
+ 0 => :none, # N/A
392
+ 1 => :da, # Deca: 10^1
393
+ 2 => :h, # Hecto: 10^2
394
+ 3 => :k, # Kilo: 10^3
395
+ 6 => :M, # Mega: 10^6
396
+ 9 => :G, # Giga: 10^9
397
+ 12 => :T, # Tera: 10^12
398
+ }
399
+
400
+ UNIT_SYMBOL = {
401
+ 0 => :none,
402
+ 2 => :m,
403
+ 3 => :g,
404
+ 4 => :rev_per_sec,
405
+ 5 => :A,
406
+ 6 => :K,
407
+ 7 => :mol,
408
+ 8 => :cd,
409
+ 9 => :deg,
410
+ 10 => :rad,
411
+ 11 => :sr,
412
+ 21 => :gy,
413
+ 22 => :bq,
414
+ 23 => :deg_C,
415
+ 24 => :sv,
416
+ 25 => :F,
417
+ 27 => :sec,
418
+ 28 => :H,
419
+ 29 => :V,
420
+ 30 => :ohm,
421
+ 31 => :J,
422
+ 33 => :Hz,
423
+ 34 => :lx,
424
+ 35 => :lm,
425
+ 36 => :wb,
426
+ 37 => :t,
427
+ 38 => :W,
428
+ 41 => :m2,
429
+ 42 => :m3,
430
+ 43 => :m_per_sec,
431
+ 44 => :m_per_sec2,
432
+ 45 => :m3_per_sec,
433
+ 46 => :m_per_m3,
434
+ 47 => :kg_m,
435
+ 48 => :kg_per_m3,
436
+ 49 => :m2_per_sec,
437
+ 50 => :w_per_mK,
438
+ 51 => :J_per_kg,
439
+ 53 => :siemens,
440
+ 54 => :rad_per_sec,
441
+ 61 => :VA,
442
+ 63 => :VAr,
443
+ 66 => :Vs,
444
+ 67 => :V2,
445
+ 68 => :As,
446
+ 69 => :A2,
447
+ 70 => :A2s,
448
+ 71 => :VAh,
449
+ 72 => :Wh,
450
+ 74 => :V_per_Hz,
451
+ 75 => :Hz_per_sec,
452
+ 76 => :char,
453
+ 77 => :char_per_sec,
454
+ 78 => :gM2,
455
+ 79 => :b,
456
+ 80 => :money,
457
+ 81 => :W_per_sec,
458
+ 82 => :litre_per_sec,
459
+ 100 => :q,
460
+ 101 => :qh,
461
+ 102 => :ohm_m,
462
+ 103 => :A_per_m,
463
+ 104 => :V2h,
464
+ 105 => :A2h,
465
+ 106 => :Ah,
466
+ 107 => :Wh_per_m3,
467
+ 108 => :time_stamp,
468
+ 109 => :status,
469
+ 111 => :count,
470
+ 113 => :bm,
471
+ 114 => :code,
472
+ 115 => :Wh_per_rev,
473
+ 116 => :VArh_per_rev,
474
+ 117 => :VAh_per_rev,
475
+ 118 => :me_code,
476
+ 119 => :ft3,
477
+ 120 => :ft3_compensated,
478
+ 123 => :ft3_compensated_per_h,
479
+ 125 => :m3_per_h,
480
+ 126 => :m3_compensated_per_h,
481
+ 127 => :m3_uncompensated_per_h,
482
+ 128 => :us_gal,
483
+ 129 => :us_gal_per_h,
484
+ 130 => :imperial_gal,
485
+ 131 => :imperial_gal_per_h,
486
+ 132 => :btu,
487
+ 133 => :btu_per_h,
488
+ 134 => :litre,
489
+ 137 => :litre_per_h,
490
+ 138 => :litre_compensated_per_h,
491
+ 139 => :litre_uncompensated_per_h,
492
+ 140 => :paG,
493
+ 141 => :psiA,
494
+ 142 => :psiG,
495
+ 143 => :litre_per_litre,
496
+ 144 => :g_per_G,
497
+ 145 => :mol_per_m3,
498
+ 146 => :mol_per_mol,
499
+ 147 => :mol_per_kg,
500
+ 148 => :m_per_m,
501
+ 149 => :sec_per_sec,
502
+ 150 => :Hz_per_Hz,
503
+ 151 => :V_per_V,
504
+ 152 => :A_per_A,
505
+ 153 => :W_per_VA,
506
+ 154 => :rev,
507
+ 155 => :paA,
508
+ 156 => :litre_uncompensated,
509
+ 157 => :litre_compensated,
510
+ 158 => :kat,
511
+ 159 => :min,
512
+ 160 => :h,
513
+ 161 => :q45,
514
+ 162 => :q60,
515
+ 163 => :q45h,
516
+ 164 => :q60h,
517
+ 166 => :m3_uncompensated,
518
+ 167 => :m3_compensated,
519
+ 168 => :W_per_W,
520
+ 169 => :them
521
+ }
522
+ end
523
+ end
@@ -0,0 +1,7 @@
1
+ module GreenButtonData
2
+ class Feed
3
+ def self.parse(xml)
4
+ GreenButtonData::Parser::Feed.parse xml
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,180 @@
1
+ module GreenButtonData
2
+ module Parser
3
+ class ApplicationInformation
4
+ include SAXMachine
5
+ include Enumerations
6
+ include Utilities
7
+
8
+ # Data Custodian
9
+ element :dataCustodianId, as: :data_custodian_id
10
+ element :dataCustodianApplicationStatus, class: Integer,
11
+ as: :data_custodian_application_status
12
+ element :dataCustodianScopeSelectionScreenURI,
13
+ as: :data_custodian_scope_selection_screen_uri
14
+ element :dataCustodianBulkRequestURI,
15
+ as: :data_custodian_bulk_request_uri
16
+ element :dataCustodianResourceEndpoint,
17
+ as: :data_custodian_resource_endpoint
18
+
19
+ # Third Party
20
+ element :thirdPartyApplicationType, class: Integer,
21
+ as: :third_party_application_type
22
+ element :thirdPartyApplicationUse, class: Integer,
23
+ as: :third_party_application_use
24
+ element :thirdPartyApplicationDescription,
25
+ as: :third_party_application_description
26
+ element :thirdPartyPhone, as: :third_party_phone
27
+ element :thirdPartyScopeSelectionScreenURI,
28
+ as: :third_party_scope_selection_screen_uri
29
+ element :thirdPartyUserPortalScreenURI,
30
+ as: :third_party_user_portal_screen_uri
31
+ element :thirdPartyNotifyUri, as: :third_party_notify_uri
32
+
33
+ # Authorization Information
34
+ element :authorizationServerUri, as: :authorization_server_uri
35
+ element :authorizationServerAuthorizationEndpoint,
36
+ as: :authorization_server_authorization_endpoint
37
+ element :authorizationServerRegistrationEndpoint,
38
+ as: :authorization_server_registration_endpoint
39
+ element :authorizationServerTokenEndpoint,
40
+ as: :authorization_server_token_endpoint
41
+ element :token_endpoint_auth_method
42
+
43
+ # Client Information
44
+ element :client_name
45
+ element :client_id
46
+ element :client_secret
47
+ element :client_id_issued_at, class: Integer do |epoch|
48
+ Time.at(normalize_epoch(epoch)).utc.to_datetime
49
+ end
50
+ element :client_secret_expires_at, class: Integer do |epoch|
51
+ if epoch == 0
52
+ # 0 means don't expire; set it to distant future
53
+ DateTime.new 9999, 12, 31, 23, 59, 59
54
+ else
55
+ Time.at(normalize_epoch(epoch)).utc.to_datetime
56
+ end
57
+ end
58
+ element :redirect_uri
59
+ element :software_id
60
+ element :software_version
61
+ element :contacts
62
+
63
+ elements :scope, as: :scopes
64
+
65
+ elements :grant_types
66
+ elements :response_types
67
+
68
+ element :registration_client_uri
69
+ element :registration_access_token
70
+
71
+ def application_status
72
+ DATA_CUSTODIAN_APPLICATION_STATUS[@data_custodian_application_status]
73
+ end
74
+
75
+ def application_type
76
+ THIRD_PARTY_APPLICATION_TYPE[@third_party_application_type]
77
+ end
78
+
79
+ def application_use
80
+ THIRD_PARTY_APPLICATION_USE[@third_party_application_use]
81
+ end
82
+
83
+ # ESPI Namespacing
84
+ element :'espi:dataCustodianId', as: :data_custodian_id
85
+ element :'espi:dataCustodianApplicationStatus', class: Integer,
86
+ as: :data_custodian_application_status
87
+ element :'espi:dataCustodianScopeSelectionScreenURI',
88
+ as: :data_custodian_scope_selection_screen_uri
89
+ element :'espi:dataCustodianBulkRequestURI',
90
+ as: :data_custodian_bulk_request_uri
91
+ element :'espi:dataCustodianResourceEndpoint',
92
+ as: :data_custodian_resource_endpoint
93
+ element :'espi:thirdPartyApplicationType', class: Integer,
94
+ as: :third_party_application_type
95
+ element :'espi:thirdPartyApplicationUse', class: Integer,
96
+ as: :third_party_application_use
97
+ element :'espi:thirdPartyApplicationDescription',
98
+ as: :third_party_application_description
99
+ element :'espi:thirdPartyPhone', as: :third_party_phone
100
+ element :'espi:thirdPartyScopeSelectionScreenURI',
101
+ as: :third_party_scope_selection_screen_uri
102
+ element :'espi:thirdPartyUserPortalScreenURI',
103
+ as: :third_party_user_portal_screen_uri
104
+ element :'espi:thirdPartyNotifyUri', as: :third_party_notify_uri
105
+ element :'espi:authorizationServerUri', as: :authorization_server_uri
106
+ element :'espi:authorizationServerAuthorizationEndpoint',
107
+ as: :authorization_server_authorization_endpoint
108
+ element :'espi:authorizationServerRegistrationEndpoint',
109
+ as: :authorization_server_registration_endpoint
110
+ element :'espi:authorizationServerTokenEndpoint',
111
+ as: :authorization_server_token_endpoint
112
+ element :'espi:token_endpoint_auth_method',
113
+ as: :token_endpoint_auth_method
114
+ element :'espi:client_name', as: :client_name
115
+ element :'espi:client_id', as: :client_id
116
+ element :'espi:client_secret', as: :client_secret
117
+ element :'espi:client_id_issued_at', class: Integer,
118
+ as: :client_id_issued_at
119
+ element :'espi:client_secret_expires_at', class: Integer,
120
+ as: :client_secret_expires_at
121
+ element :'espi:redirect_uri', as: :redirect_uri
122
+ element :'espi:software_id', as: :software_id
123
+ element :'espi:software_version', as: :software_version
124
+ element :'espi:contacts', as: :contacts
125
+ elements :'espi:scope', as: :scopes
126
+ elements :'espi:grant_types', as: :grant_types
127
+ elements :'espi:response_types', as: :response_types
128
+ element :'espi:registration_client_uri', as: :registration_client_uri
129
+ element :'espi:registration_access_token', as: :registration_access_token
130
+
131
+ # Special case for PG&E which uses generic namespacing
132
+ element :'ns0:dataCustodianId', as: :data_custodian_id
133
+ element :'ns0:dataCustodianApplicationStatus', class: Integer,
134
+ as: :data_custodian_application_status
135
+ element :'ns0:dataCustodianScopeSelectionScreenURI',
136
+ as: :data_custodian_scope_selection_screen_uri
137
+ element :'ns0:dataCustodianBulkRequestURI',
138
+ as: :data_custodian_bulk_request_uri
139
+ element :'ns0:dataCustodianResourceEndpoint',
140
+ as: :data_custodian_resource_endpoint
141
+ element :'ns0:thirdPartyApplicationType', class: Integer,
142
+ as: :third_party_application_type
143
+ element :'ns0:thirdPartyApplicationUse', class: Integer,
144
+ as: :third_party_application_use
145
+ element :'ns0:thirdPartyApplicationDescription',
146
+ as: :third_party_application_description
147
+ element :'ns0:thirdPartyPhone', as: :third_party_phone
148
+ element :'ns0:thirdPartyScopeSelectionScreenURI',
149
+ as: :third_party_scope_selection_screen_uri
150
+ element :'ns0:thirdPartyUserPortalScreenURI',
151
+ as: :third_party_user_portal_screen_uri
152
+ element :'ns0:thirdPartyNotifyUri', as: :third_party_notify_uri
153
+ element :'ns0:authorizationServerUri', as: :authorization_server_uri
154
+ element :'ns0:authorizationServerAuthorizationEndpoint',
155
+ as: :authorization_server_authorization_endpoint
156
+ element :'ns0:authorizationServerRegistrationEndpoint',
157
+ as: :authorization_server_registration_endpoint
158
+ element :'ns0:authorizationServerTokenEndpoint',
159
+ as: :authorization_server_token_endpoint
160
+ element :'ns0:token_endpoint_auth_method',
161
+ as: :token_endpoint_auth_method
162
+ element :'ns0:client_name', as: :client_name
163
+ element :'ns0:client_id', as: :client_id
164
+ element :'ns0:client_secret', as: :client_secret
165
+ element :'ns0:client_id_issued_at', class: Integer,
166
+ as: :client_id_issued_at
167
+ element :'ns0:client_secret_expires_at', class: Integer,
168
+ as: :client_secret_expires_at
169
+ element :'ns0:redirect_uri', as: :redirect_uri
170
+ element :'ns0:software_id', as: :software_id
171
+ element :'ns0:software_version', as: :software_version
172
+ element :'ns0:contacts', as: :contacts
173
+ elements :'ns0:scope', as: :scopes
174
+ elements :'ns0:grant_types', as: :grant_types
175
+ elements :'ns0:response_types', as: :response_types
176
+ element :'ns0:registration_client_uri', as: :registration_client_uri
177
+ element :'ns0:registration_access_token', as: :registration_access_token
178
+ end
179
+ end
180
+ end