aemo 0.1.27 → 0.1.28
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 +4 -4
- data/lib/aemo/dispatchable.rb +4 -4
- data/lib/aemo/market.rb +30 -27
- data/lib/aemo/market/interval.rb +27 -23
- data/lib/aemo/msats.rb +218 -210
- data/lib/aemo/nem12.rb +165 -160
- data/lib/aemo/nem13.rb +1 -2
- data/lib/aemo/nmi.rb +91 -85
- data/lib/aemo/region.rb +12 -11
- data/lib/aemo/version.rb +3 -3
- data/lib/data/xml_to_json.rb +62 -0
- data/spec/aemo_spec.rb +1 -2
- data/spec/lib/aemo/market/interval_spec.rb +13 -13
- data/spec/lib/aemo/market_spec.rb +8 -6
- data/spec/lib/aemo/msats_spec.rb +14 -15
- data/spec/lib/aemo/nem12_spec.rb +8 -10
- data/spec/lib/aemo/nmi_spec.rb +79 -71
- data/spec/lib/aemo/region_spec.rb +5 -6
- data/spec/spec_helper.rb +38 -35
- metadata +16 -2
- data/lib/data/xml-to-json.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7cfd209892c3e31b002bd98258c0f45c86a703d
|
4
|
+
data.tar.gz: 89da4a8819f3e2f23bb0df135012b021d9e7104e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae9be88e2ce60f53d7742b4f6b93b154b043c5ccc0e43808e597fa9d6ddc2e1d44dac951662ba1d0c87f207d982b6443c68ce19e2f873517ae97b3e08b2b697c
|
7
|
+
data.tar.gz: c8723d45670118e9fc7b6e94de0c43cef8b66a3d5795de6a9bb29cbf164f4d9fe3d2261ae6c9557ba8b9b7f53c898c404b49d05a6efb51d6589a90a0c679a5dc
|
data/lib/aemo/dispatchable.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module AEMO
|
2
2
|
class Region
|
3
|
-
DISPATCH_TYPE = ['Generator','Load Norm Off','Network Service Provider']
|
4
|
-
CATEGORY = ['Market','Non-Market']
|
5
|
-
CLASSIFICATION = ['Scheduled','Semi-Scheduled','Non-Scheduled']
|
3
|
+
DISPATCH_TYPE = ['Generator', 'Load Norm Off', 'Network Service Provider'].freeze
|
4
|
+
CATEGORY = ['Market', 'Non-Market'].freeze
|
5
|
+
CLASSIFICATION = ['Scheduled', 'Semi-Scheduled', 'Non-Scheduled'].freeze
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
data/lib/aemo/market.rb
CHANGED
@@ -1,42 +1,45 @@
|
|
1
1
|
module AEMO
|
2
|
+
# AEMO::Market
|
3
|
+
#
|
4
|
+
# @author Joel Courtney
|
5
|
+
# @abstract
|
6
|
+
# @since 0.1.0
|
2
7
|
module Market
|
3
8
|
include HTTParty
|
4
9
|
base_uri 'www.nemweb.com.au'
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
# Class Methods
|
12
|
+
class << self
|
13
|
+
def current_dispatch(region)
|
14
|
+
response = get "/mms.GRAPHS/GRAPHS/GRAPH_5#{region}1.csv"
|
15
|
+
values = parse_response(response)
|
16
|
+
values
|
17
|
+
end
|
11
18
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
def current_trading(region)
|
20
|
+
response = get "/mms.GRAPHS/GRAPHS/GRAPH_30#{region}1.csv"
|
21
|
+
values = parse_response(response)
|
22
|
+
values
|
23
|
+
end
|
17
24
|
|
18
|
-
# ######### #
|
19
25
|
protected
|
20
|
-
# ######### #
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def parse_response(response)
|
28
|
+
values = []
|
29
|
+
if response.response.code == '200'
|
30
|
+
CSV.parse(response.body, headers: true, converters: :numeric) do |row|
|
31
|
+
if row.respond_to?(:to_h)
|
32
|
+
row = row.to_h
|
33
|
+
elsif row.respond_to?(:to_hash)
|
34
|
+
row = row.to_hash
|
35
|
+
else
|
36
|
+
raise NoMethodError, "cannot convert #{row.class} to Hash"
|
37
|
+
end
|
38
|
+
values.push ::AEMO::Market::Interval.new(row['SETTLEMENTDATE'], row)
|
33
39
|
end
|
34
|
-
values.push AEMO::Market::Interval.new(row['SETTLEMENTDATE'],row)
|
35
40
|
end
|
41
|
+
values
|
36
42
|
end
|
37
|
-
values
|
38
43
|
end
|
39
|
-
|
40
44
|
end
|
41
|
-
|
42
45
|
end
|
data/lib/aemo/market/interval.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
module AEMO
|
2
2
|
module Market
|
3
|
+
# AEMO::Market::Interval
|
4
|
+
#
|
5
|
+
# @author Joel Courtney
|
6
|
+
# @abstract
|
7
|
+
# @since 0.1.0
|
3
8
|
class Interval
|
4
9
|
INTERVALS = {
|
5
|
-
:
|
6
|
-
:
|
7
|
-
}
|
8
|
-
|
10
|
+
trading: 'Trading',
|
11
|
+
dispatch: 'Dispatch'
|
12
|
+
}.freeze
|
13
|
+
|
9
14
|
attr_accessor :datetime, :region, :total_demand, :rrp, :period_type
|
10
|
-
|
11
|
-
# @param datetime [Time]
|
15
|
+
|
16
|
+
# @param datetime [Time]
|
12
17
|
# @param options [Hash] Hash of optional data values
|
13
18
|
# @return [AEMO::Market::Interval]
|
14
|
-
def initialize(datetime,options={})
|
19
|
+
def initialize(datetime, options = {})
|
15
20
|
@datetime = Time.parse("#{datetime} +1000")
|
16
21
|
@region = options['REGION']
|
17
22
|
@total_demand = options['TOTALDEMAND']
|
18
23
|
@rrp = options['RRP']
|
19
24
|
@period_type = options['PERIODTYPE']
|
20
25
|
end
|
21
|
-
|
26
|
+
|
22
27
|
# Instance Variable Getters
|
23
|
-
|
28
|
+
|
24
29
|
# All AEMO Data operates in Australian Eastern Standard Time
|
25
30
|
# All AEMO Data aggregates to the trailing edge of the period (this makes it difficult to do daily aggregations :( )
|
26
31
|
# @param trailing_edge [Boolean] selection of either the trailing edge of the period or the rising edge of the period for the date time
|
@@ -30,35 +35,35 @@ module AEMO
|
|
30
35
|
# If the datetime requested is the trailing edge, offset as per interval requirement
|
31
36
|
unless trailing_edge
|
32
37
|
# This is for dispatch intervals of five minutes
|
33
|
-
if
|
38
|
+
if dispatch?
|
34
39
|
t -= 5 * 60
|
35
|
-
elsif
|
40
|
+
elsif trading?
|
36
41
|
t -= 30 * 60
|
37
42
|
end
|
38
43
|
end
|
39
44
|
t
|
40
45
|
end
|
41
|
-
|
42
|
-
# @return [Time] the time of the
|
46
|
+
|
47
|
+
# @return [Time] the time of the
|
43
48
|
def interval_length
|
44
49
|
Time.at(300)
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
# @return [Symbol] :dispatch or :trading
|
48
53
|
def interval_type
|
49
|
-
|
54
|
+
dispatch? ? :dispatch : :trading
|
50
55
|
end
|
51
|
-
|
56
|
+
|
52
57
|
# @return [Boolean] returns true if the interval type is dispatch
|
53
|
-
def
|
58
|
+
def dispatch?
|
54
59
|
@period_type.nil? || @period_type.empty?
|
55
60
|
end
|
56
|
-
|
61
|
+
|
57
62
|
# @return [Boolean] returns true if the interval type is trading
|
58
|
-
def
|
59
|
-
!
|
63
|
+
def trading?
|
64
|
+
!dispatch?
|
60
65
|
end
|
61
|
-
|
66
|
+
|
62
67
|
# @return [Float] the value of the interval in Australian Dollars
|
63
68
|
def value
|
64
69
|
@value ||= Float::NAN
|
@@ -67,7 +72,6 @@ module AEMO
|
|
67
72
|
end
|
68
73
|
@value
|
69
74
|
end
|
70
|
-
|
71
75
|
end
|
72
76
|
end
|
73
|
-
end
|
77
|
+
end
|
data/lib/aemo/msats.rb
CHANGED
@@ -5,14 +5,18 @@ require 'nokogiri'
|
|
5
5
|
require 'digest/sha1'
|
6
6
|
|
7
7
|
module AEMO
|
8
|
-
|
8
|
+
# AEMO::MSATS
|
9
|
+
#
|
10
|
+
# @author Joel Courtney
|
11
|
+
# @abstract
|
12
|
+
# @since 0.1.0
|
9
13
|
class MSATS
|
10
14
|
# Globally set request headers
|
11
15
|
HEADERS = {
|
12
|
-
'User-Agent' =>
|
16
|
+
'User-Agent' => 'Ruby.AEMO.MSATS.Api',
|
13
17
|
'Accept' => 'text/xml',
|
14
18
|
'Content-Type' => 'text/xml'
|
15
|
-
}
|
19
|
+
}.freeze
|
16
20
|
|
17
21
|
# We like to party
|
18
22
|
include HTTParty
|
@@ -25,233 +29,237 @@ module AEMO
|
|
25
29
|
# Where we like to party
|
26
30
|
base_uri 'https://msats.prod.nemnet.net.au/msats/ws/'
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
|
32
|
+
# Class Methods
|
33
|
+
class << self
|
34
|
+
attr_accessor :auth
|
35
|
+
attr_accessor :participant_id
|
36
|
+
|
37
|
+
# Single NMI Master (C4) Report
|
38
|
+
# /C4/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX
|
39
|
+
#
|
40
|
+
# @param [String, AEMO::NMI] nmi the NMI to run the master report against
|
41
|
+
# @param [Date, String] from_date the from date for the master report
|
42
|
+
# @param [Date, String] to_date the from date for the master report
|
43
|
+
# @return [Hash] A hashed view of the NMI Standing Data for a given NMI
|
44
|
+
def c4(nmi, from_date, to_date, as_at_date, options = {})
|
45
|
+
nmi = AEMO::NMI.new(nmi) if nmi.is_a?(String)
|
46
|
+
from_date = Date.parse(from_date) if from_date.is_a?(String)
|
47
|
+
to_date = Date.parse(to_date) if to_date.is_a?(String)
|
48
|
+
as_at_date = Date.parse(as_at_date) if as_at_date.is_a?(String)
|
49
|
+
|
50
|
+
options[:participantId] ||= nil
|
51
|
+
options[:roleId] ||= nil
|
52
|
+
options[:inittransId] ||= nil
|
53
|
+
|
54
|
+
query = {
|
55
|
+
transactionId: transaction_id,
|
56
|
+
# Note: AEMO has case sensitivity but no consistency across requests.
|
57
|
+
NMI: nmi.nmi,
|
58
|
+
fromDate: from_date,
|
59
|
+
toDate: to_date,
|
60
|
+
asatDate: as_at_date,
|
61
|
+
participantId: @participant_id,
|
62
|
+
roleId: options[:role_id],
|
63
|
+
inittransId: options[:init_trans_id]
|
64
|
+
}
|
65
|
+
|
66
|
+
response = get("/C4/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
67
|
+
if response.response.code != '200'
|
68
|
+
response
|
69
|
+
else
|
70
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
|
71
|
+
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
74
|
+
# MSATS Limits
|
75
|
+
# /MSATSLimits/PARTICIPANT_IDENTIFIER?transactionId=XXX
|
76
|
+
#
|
77
|
+
# @return [Hash] The report results from the MSATS Limits web service query
|
78
|
+
def msats_limits(options = {})
|
79
|
+
query = {
|
80
|
+
transactionId: transaction_id
|
81
|
+
}
|
82
|
+
response = get("/MSATSLimits/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
83
|
+
if response.response.code != '200'
|
84
|
+
response
|
85
|
+
else
|
86
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
|
87
|
+
end
|
86
88
|
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# NMI Discovery - By Delivery Point Identifier
|
90
|
-
#
|
91
|
-
# @param [String] jurisdiction_code The Jurisdiction Code
|
92
|
-
# @param [Integer] delivery_point_identifier Delivery Point Identifier
|
93
|
-
# @return [Hash] The response
|
94
|
-
def self.nmi_discovery_by_delivery_point_identifier(jurisdiction_code,delivery_point_identifier,options={})
|
95
|
-
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
96
|
-
raise ArgumentError, 'delivery_point_identifier is not valid' unless delivery_point_identifier.respond_to?("to_i")
|
97
|
-
raise ArgumentError, 'delivery_point_identifier is not valid' if( delivery_point_identifier.to_i < 10000000 || delivery_point_identifier.to_i > 99999999)
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
90
|
+
# NMI Discovery - By Delivery Point Identifier
|
91
|
+
#
|
92
|
+
# @param [String] jurisdiction_code The Jurisdiction Code
|
93
|
+
# @param [Integer] delivery_point_identifier Delivery Point Identifier
|
94
|
+
# @return [Hash] The response
|
95
|
+
def nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, options = {})
|
96
|
+
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
97
|
+
raise ArgumentError, 'delivery_point_identifier is not valid' unless delivery_point_identifier.respond_to?('to_i')
|
98
|
+
raise ArgumentError, 'delivery_point_identifier is not valid' if delivery_point_identifier.to_i < 10_000_000 || delivery_point_identifier.to_i > 99_999_999
|
99
|
+
|
100
|
+
query = {
|
101
|
+
transactionId: transaction_id,
|
102
|
+
jurisdictionCode: jurisdiction_code,
|
103
|
+
deliveryPointIdentifier: delivery_point_identifier.to_i
|
104
|
+
}
|
105
|
+
|
106
|
+
response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
107
|
+
if response.response.code != '200'
|
108
|
+
response
|
109
|
+
else
|
110
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
|
111
|
+
end
|
110
112
|
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# NMI Discovery - By Meter Serial Numner
|
114
|
-
#
|
115
|
-
# @param [String] jurisdiction_code The Jurisdiction Code
|
116
|
-
# @param [Integer] meter_serial_number The meter's serial number
|
117
|
-
# @return [Hash] The response
|
118
|
-
def self.nmi_discovery_by_meter_serial_number(jurisdiction_code,meter_serial_number,options={})
|
119
|
-
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
120
113
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
114
|
+
# NMI Discovery - By Meter Serial Numner
|
115
|
+
#
|
116
|
+
# @param [String] jurisdiction_code The Jurisdiction Code
|
117
|
+
# @param [Integer] meter_serial_number The meter's serial number
|
118
|
+
# @return [Hash] The response
|
119
|
+
def nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, options = {})
|
120
|
+
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
121
|
+
|
122
|
+
query = {
|
123
|
+
transactionId: transaction_id,
|
124
|
+
jurisdictionCode: jurisdiction_code,
|
125
|
+
meterSerialNumber: meter_serial_number.to_i
|
126
|
+
}
|
127
|
+
|
128
|
+
response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
129
|
+
if response.response.code != '200'
|
130
|
+
response
|
131
|
+
else
|
132
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
|
133
|
+
end
|
132
134
|
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# NMI Discovery - By Address
|
136
|
-
#
|
137
|
-
# @param [String] jurisdiction_code The Jurisdiction Code
|
138
|
-
# @param [Integer] meter_serial_number The meter's serial number
|
139
|
-
# @return [Hash] The response
|
140
|
-
def self.nmi_discovery_by_address(jurisdiction_code,options = {})
|
141
|
-
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
142
|
-
|
143
|
-
options[:building_or_property_name] ||= nil
|
144
|
-
options[:location_descriptor] ||= nil
|
145
|
-
options[:lot_number] ||= nil
|
146
|
-
options[:flat_or_unit_number] ||= nil
|
147
|
-
options[:flat_or_unit_type] ||= nil
|
148
|
-
options[:floor_or_level_number] ||= nil
|
149
|
-
options[:floor_or_level_type] ||= nil
|
150
|
-
options[:house_number] ||= nil
|
151
|
-
options[:house_number_suffix] ||= nil
|
152
|
-
options[:street_name] ||= nil
|
153
|
-
options[:street_suffix] ||= nil
|
154
|
-
options[:street_type] ||= nil
|
155
|
-
options[:suburb_or_place_or_locality] ||= nil
|
156
|
-
options[:postcode] ||= nil
|
157
|
-
options[:state_or_territory] ||= jurisdiction_code
|
158
135
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
136
|
+
# NMI Discovery - By Address
|
137
|
+
#
|
138
|
+
# @param [String] jurisdiction_code The Jurisdiction Code
|
139
|
+
# @param [Integer] meter_serial_number The meter's serial number
|
140
|
+
# @return [Hash] The response
|
141
|
+
def nmi_discovery_by_address(jurisdiction_code, options = {})
|
142
|
+
raise ArgumentError, 'jurisdiction_code is not valid' unless %w(ACT NEM NSW QLD SA VIC TAS).include?(jurisdiction_code)
|
143
|
+
|
144
|
+
options[:building_or_property_name] ||= nil
|
145
|
+
options[:location_descriptor] ||= nil
|
146
|
+
options[:lot_number] ||= nil
|
147
|
+
options[:flat_or_unit_number] ||= nil
|
148
|
+
options[:flat_or_unit_type] ||= nil
|
149
|
+
options[:floor_or_level_number] ||= nil
|
150
|
+
options[:floor_or_level_type] ||= nil
|
151
|
+
options[:house_number] ||= nil
|
152
|
+
options[:house_number_suffix] ||= nil
|
153
|
+
options[:street_name] ||= nil
|
154
|
+
options[:street_suffix] ||= nil
|
155
|
+
options[:street_type] ||= nil
|
156
|
+
options[:suburb_or_place_or_locality] ||= nil
|
157
|
+
options[:postcode] ||= nil
|
158
|
+
options[:state_or_territory] ||= jurisdiction_code
|
159
|
+
|
160
|
+
query = {
|
161
|
+
transactionId: transaction_id,
|
162
|
+
jurisdictionCode: jurisdiction_code,
|
163
|
+
buildingOrPropertyName: options[:building_or_property_name],
|
164
|
+
locationDescriptor: options[:location_descriptor],
|
165
|
+
lotNumber: options[:lot_number],
|
166
|
+
flatOrUnitNumber: options[:flat_or_unit_number],
|
167
|
+
flatOrUnitType: options[:flat_or_unit_type],
|
168
|
+
floorOrLevelNumber: options[:floor_or_level_number],
|
169
|
+
floorOrLevelType: options[:floor_or_level_type],
|
170
|
+
houseNumber: options[:house_number],
|
171
|
+
houseNumberSuffix: options[:house_number_suffix],
|
172
|
+
streetName: options[:street_name],
|
173
|
+
streetSuffix: options[:street_suffix],
|
174
|
+
streetType: options[:street_type],
|
175
|
+
suburbOrPlaceOrLocality: options[:suburb_or_place_or_locality],
|
176
|
+
postcode: options[:postcode],
|
177
|
+
stateOrTerritory: options[:state_or_territory]
|
178
|
+
}
|
179
|
+
|
180
|
+
response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
181
|
+
if response.response.code != '200'
|
182
|
+
response
|
183
|
+
else
|
184
|
+
myresponse = response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
|
185
|
+
myresponse.is_a?(Hash) ? [myresponse] : myresponse
|
186
|
+
end
|
185
187
|
end
|
186
|
-
end
|
187
188
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
189
|
+
# NMI Detail
|
190
|
+
# /NMIDetail/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX
|
191
|
+
#
|
192
|
+
# @return [Hash] A hashed view of the NMI Standing Data for a given NMI
|
193
|
+
def nmi_detail(nmi, options = {})
|
194
|
+
nmi = AEMO::NMI.new(nmi) if nmi.is_a?(String)
|
195
|
+
|
196
|
+
options[:type] ||= nil
|
197
|
+
options[:reason] ||= nil
|
198
|
+
|
199
|
+
query = {
|
200
|
+
transactionId: transaction_id,
|
201
|
+
nmi: nmi.nmi,
|
202
|
+
checksum: nmi.checksum,
|
203
|
+
type: options[:type],
|
204
|
+
reason: options[:reason]
|
205
|
+
}
|
206
|
+
|
207
|
+
response = get("/NMIDetail/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
208
|
+
if response.response.code != '200'
|
209
|
+
response
|
210
|
+
else
|
211
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['NMIStandingDataResponse']['NMIStandingData']
|
212
|
+
end
|
195
213
|
end
|
196
|
-
options[:type] ||= nil
|
197
|
-
options[:reason] ||= nil
|
198
|
-
|
199
|
-
query = {
|
200
|
-
transactionId: transaction_id,
|
201
|
-
nmi: nmi.nmi,
|
202
|
-
checksum: nmi.checksum,
|
203
|
-
type: options[:type],
|
204
|
-
reason: options[:reason]
|
205
|
-
}
|
206
214
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
215
|
+
# Participant System Status
|
216
|
+
# /ParticipantSystemStatus/PARTICIPANT_IDENTIFIER?transactionId=XXX
|
217
|
+
#
|
218
|
+
# @return [Hash] The report results from the Participant System Status web service query
|
219
|
+
def system_status(options = {})
|
220
|
+
query = {
|
221
|
+
transactionId: transaction_id
|
222
|
+
}
|
223
|
+
response = get("/ParticipantSystemStatus/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: (options[:verify_ssl] != false))
|
224
|
+
if response.response.code != '200'
|
225
|
+
response
|
226
|
+
else
|
227
|
+
response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
|
228
|
+
end
|
212
229
|
end
|
213
|
-
end
|
214
230
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
response = self.get( "/ParticipantSystemStatus/#{@@participant_id}", basic_auth: @@auth, headers: { 'Accept' => 'text/xml', 'Content-Type' => 'text/xml'}, query: query, verify: (options[:verify_ssl] != false) )
|
224
|
-
if response.response.code != '200'
|
225
|
-
response
|
226
|
-
else
|
227
|
-
response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
|
231
|
+
# Sets the authentication credentials in a class variable.
|
232
|
+
#
|
233
|
+
# @param [String] email cl.ly email
|
234
|
+
# @param [String] password cl.ly password
|
235
|
+
# @return [Hash] authentication credentials
|
236
|
+
def authorize(participant_id, username, password)
|
237
|
+
@participant_id = participant_id
|
238
|
+
@auth = { username: username, password: password }
|
228
239
|
end
|
229
|
-
end
|
230
240
|
|
241
|
+
# Check if credentials are available to use
|
242
|
+
#
|
243
|
+
# @return [Boolean] true/false if credentials are available
|
244
|
+
def can_authenticate?
|
245
|
+
!(@participant_id.nil? || @auth[:username].nil? || @auth[:password].nil?)
|
246
|
+
end
|
231
247
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
@@participant_id = participant_id
|
239
|
-
@@auth = {username: username, password: password}
|
248
|
+
# Method for creating a unique transaction id
|
249
|
+
#
|
250
|
+
# @return [String] the transaction id
|
251
|
+
def transaction_id
|
252
|
+
Digest::SHA1.hexdigest(Time.now.to_s)[0..35]
|
253
|
+
end
|
240
254
|
end
|
241
255
|
|
242
|
-
#
|
243
|
-
|
244
|
-
|
245
|
-
def self.can_authenticate?
|
246
|
-
!(@@participant_id.nil? || @@auth[:username].nil? || @@auth[:password].nil?)
|
247
|
-
end
|
256
|
+
# Instance Methods
|
257
|
+
def initialize(options = {})
|
258
|
+
@auth = { username: nil, password: nil }
|
248
259
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
def self.transaction_id
|
253
|
-
Digest::SHA1.hexdigest(Time.now.to_s)[0..35]
|
260
|
+
@auth[:username] = options[:username] if options[:username].is_a?(String)
|
261
|
+
@auth[:password] = options[:password] if options[:password].is_a?(String)
|
262
|
+
@participant_id = options[:participant_id] if options[:participant_id].is_a?(String)
|
254
263
|
end
|
255
|
-
|
256
264
|
end
|
257
265
|
end
|