Class: AEMO::MSATS Abstract
Overview
AEMO::MSATS
Constant Summary collapse
- HEADERS =
Globally set request headers
{ 'User-Agent' => 'Ruby.AEMO.MSATS.Api', 'Accept' => 'text/xml', 'Content-Type' => 'text/xml' }.freeze
Class Attribute Summary collapse
Class Method Summary collapse
-
.authorize(participant_id, username, password) ⇒ Hash
Sets the authentication credentials in a class variable.
-
.c4(nmi, from_date, to_date, as_at_date, options = {}) ⇒ Hash
Single NMI Master (C4) Report /C4/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX.
-
.can_authenticate? ⇒ Boolean
Check if credentials are available to use.
-
.msats_limits(options = {}) ⇒ Hash
MSATS Limits /MSATSLimits/PARTICIPANT_IDENTIFIER?transactionId=XXX.
-
.nmi_detail(nmi, options = {}) ⇒ Hash
NMI Detail /NMIDetail/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX.
-
.nmi_discovery_by_address(jurisdiction_code, options = {}) ⇒ Hash
NMI Discovery - By Address.
-
.nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, options = {}) ⇒ Hash
NMI Discovery - By Delivery Point Identifier.
-
.nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, options = {}) ⇒ Hash
NMI Discovery - By Meter Serial Numner.
-
.system_status(options = {}) ⇒ Hash
Participant System Status /ParticipantSystemStatus/PARTICIPANT_IDENTIFIER?transactionId=XXX.
-
.transaction_id ⇒ String
Method for creating a unique transaction id.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MSATS
constructor
Instance Methods.
Constructor Details
#initialize(options = {}) ⇒ MSATS
Instance Methods
257 258 259 260 261 262 263 |
# File 'lib/aemo/msats.rb', line 257 def initialize( = {}) @auth = { username: nil, password: nil } @auth[:username] = [:username] if [:username].is_a?(String) @auth[:password] = [:password] if [:password].is_a?(String) @participant_id = [:participant_id] if [:participant_id].is_a?(String) end |
Class Attribute Details
.auth ⇒ Object
34 35 36 |
# File 'lib/aemo/msats.rb', line 34 def auth @auth end |
.participant_id ⇒ Object
35 36 37 |
# File 'lib/aemo/msats.rb', line 35 def participant_id @participant_id end |
Class Method Details
.authorize(participant_id, username, password) ⇒ Hash
Sets the authentication credentials in a class variable.
236 237 238 239 |
# File 'lib/aemo/msats.rb', line 236 def (participant_id, username, password) @participant_id = participant_id @auth = { username: username, password: password } end |
.c4(nmi, from_date, to_date, as_at_date, options = {}) ⇒ Hash
Single NMI Master (C4) Report /C4/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX
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 69 70 71 72 |
# File 'lib/aemo/msats.rb', line 44 def c4(nmi, from_date, to_date, as_at_date, = {}) nmi = AEMO::NMI.new(nmi) if nmi.is_a?(String) from_date = Date.parse(from_date) if from_date.is_a?(String) to_date = Date.parse(to_date) if to_date.is_a?(String) as_at_date = Date.parse(as_at_date) if as_at_date.is_a?(String) [:participantId] ||= nil [:roleId] ||= nil [:inittransId] ||= nil query = { transactionId: transaction_id, # Note: AEMO has case sensitivity but no consistency across requests. NMI: nmi.nmi, fromDate: from_date, toDate: to_date, asatDate: as_at_date, participantId: @participant_id, roleId: [:role_id], inittransId: [:init_trans_id] } response = get("/C4/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults'] end end |
.can_authenticate? ⇒ Boolean
Check if credentials are available to use
244 245 246 |
# File 'lib/aemo/msats.rb', line 244 def can_authenticate? !(@participant_id.nil? || @auth[:username].nil? || @auth[:password].nil?) end |
.msats_limits(options = {}) ⇒ Hash
MSATS Limits /MSATSLimits/PARTICIPANT_IDENTIFIER?transactionId=XXX
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/aemo/msats.rb', line 78 def msats_limits( = {}) query = { transactionId: transaction_id } response = get("/MSATSLimits/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults'] end end |
.nmi_detail(nmi, options = {}) ⇒ Hash
NMI Detail /NMIDetail/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/aemo/msats.rb', line 193 def nmi_detail(nmi, = {}) nmi = AEMO::NMI.new(nmi) if nmi.is_a?(String) [:type] ||= nil [:reason] ||= nil query = { transactionId: transaction_id, nmi: nmi.nmi, checksum: nmi.checksum, type: [:type], reason: [:reason] } response = get("/NMIDetail/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['NMIStandingDataResponse']['NMIStandingData'] end end |
.nmi_discovery_by_address(jurisdiction_code, options = {}) ⇒ Hash
NMI Discovery - By Address
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 185 186 187 |
# File 'lib/aemo/msats.rb', line 141 def nmi_discovery_by_address(jurisdiction_code, = {}) raise ArgumentError, 'jurisdiction_code is not valid' unless %w[ACT NEM NSW QLD SA VIC TAS].include?(jurisdiction_code) [:building_or_property_name] ||= nil [:location_descriptor] ||= nil [:lot_number] ||= nil [:flat_or_unit_number] ||= nil [:flat_or_unit_type] ||= nil [:floor_or_level_number] ||= nil [:floor_or_level_type] ||= nil [:house_number] ||= nil [:house_number_suffix] ||= nil [:street_name] ||= nil [:street_suffix] ||= nil [:street_type] ||= nil [:suburb_or_place_or_locality] ||= nil [:postcode] ||= nil [:state_or_territory] ||= jurisdiction_code query = { transactionId: transaction_id, jurisdictionCode: jurisdiction_code, buildingOrPropertyName: [:building_or_property_name], locationDescriptor: [:location_descriptor], lotNumber: [:lot_number], flatOrUnitNumber: [:flat_or_unit_number], flatOrUnitType: [:flat_or_unit_type], floorOrLevelNumber: [:floor_or_level_number], floorOrLevelType: [:floor_or_level_type], houseNumber: [:house_number], houseNumberSuffix: [:house_number_suffix], streetName: [:street_name], streetSuffix: [:street_suffix], streetType: [:street_type], suburbOrPlaceOrLocality: [:suburb_or_place_or_locality], postcode: [:postcode], stateOrTerritory: [:state_or_territory] } response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else myresponse = response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData'] myresponse.is_a?(Hash) ? [myresponse] : myresponse end end |
.nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, options = {}) ⇒ Hash
NMI Discovery - By Delivery Point Identifier
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/aemo/msats.rb', line 95 def nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, = {}) raise ArgumentError, 'jurisdiction_code is not valid' unless %w[ACT NEM NSW QLD SA VIC TAS].include?(jurisdiction_code) raise ArgumentError, 'delivery_point_identifier is not valid' unless delivery_point_identifier.respond_to?('to_i') 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 query = { transactionId: transaction_id, jurisdictionCode: jurisdiction_code, deliveryPointIdentifier: delivery_point_identifier.to_i } response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData'] end end |
.nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, options = {}) ⇒ Hash
NMI Discovery - By Meter Serial Numner
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/aemo/msats.rb', line 119 def nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, = {}) raise ArgumentError, 'jurisdiction_code is not valid' unless %w[ACT NEM NSW QLD SA VIC TAS].include?(jurisdiction_code) query = { transactionId: transaction_id, jurisdictionCode: jurisdiction_code, meterSerialNumber: meter_serial_number.to_i } response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData'] end end |
.system_status(options = {}) ⇒ Hash
Participant System Status /ParticipantSystemStatus/PARTICIPANT_IDENTIFIER?transactionId=XXX
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/aemo/msats.rb', line 219 def system_status( = {}) query = { transactionId: transaction_id } response = get("/ParticipantSystemStatus/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query: query, verify: ([:verify_ssl] != false)) if response.response.code != '200' response else response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults'] end end |
.transaction_id ⇒ String
Method for creating a unique transaction id
251 252 253 |
# File 'lib/aemo/msats.rb', line 251 def transaction_id Digest::SHA1.hexdigest(Time.now.to_s)[0..35] end |