Class: AEMO::MSATS Abstract

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/aemo/msats.rb

Overview

This class is abstract.

AEMO::MSATS

Author:

  • Joel Courtney

Since:

  • 0.1.0

Constant Summary collapse

HEADERS =

Globally set request headers

Since:

  • 0.1.0

{
  'User-Agent' => 'Ruby.AEMO.MSATS.Api',
  'Accept' => 'text/xml',
  'Content-Type' => 'text/xml'
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MSATS

Instance Methods

Since:

  • 0.1.0



273
274
275
276
277
278
279
# File 'lib/aemo/msats.rb', line 273

def initialize(options = {})
  @auth = { username: nil, password: nil }

  @auth[:username]  = options[:username]        if options[:username].is_a?(String)
  @auth[:password]  = options[:password]        if options[:password].is_a?(String)
  @participant_id   = options[:participant_id]  if options[:participant_id].is_a?(String)
end

Class Attribute Details

.authObject

Since:

  • 0.1.0



34
35
36
# File 'lib/aemo/msats.rb', line 34

def auth
  @auth
end

.participant_idObject

Since:

  • 0.1.0



34
35
36
# File 'lib/aemo/msats.rb', line 34

def participant_id
  @participant_id
end

Class Method Details

.authorize(participant_id, username, password) ⇒ Hash

Sets the authentication credentials in a class variable.

Parameters:

  • email (String)

    cl.ly email

  • password (String)

    cl.ly password

Returns:

  • (Hash)

    authentication credentials

Since:

  • 0.1.0



252
253
254
255
# File 'lib/aemo/msats.rb', line 252

def authorize(participant_id, username, password)
  @participant_id  = participant_id
  @auth            = { username:, 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

Parameters:

  • nmi (String, AEMO::NMI)

    the NMI to run the master report against

  • from_date (Date, String)

    the from date for the master report

  • to_date (Date, String)

    the from date for the master report

Returns:

  • (Hash)

    A hashed view of the NMI Standing Data for a given NMI

Since:

  • 0.1.0



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
69
70
71
72
# File 'lib/aemo/msats.rb', line 43

def c4(nmi, from_date, to_date, as_at_date, options = {})
  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)

  options[:participantId]   ||= nil
  options[:roleId]          ||= nil
  options[: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: options[:role_id],
    inittransId: options[:init_trans_id]
  }

  response = get("/C4/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query:,
                                           verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
  else
    response
  end
end

.can_authenticate?Boolean

Check if credentials are available to use

Returns:

  • (Boolean)

    true/false if credentials are available

Since:

  • 0.1.0



260
261
262
# File 'lib/aemo/msats.rb', line 260

def can_authenticate?
  !(@participant_id.nil? || @auth[:username].nil? || @auth[:password].nil?)
end

.msats_limits(options = {}) ⇒ Hash

MSATS Limits /MSATSLimits/PARTICIPANT_IDENTIFIER?transactionId=XXX

Returns:

  • (Hash)

    The report results from the MSATS Limits web service query

Since:

  • 0.1.0



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/aemo/msats.rb', line 78

def msats_limits(options = {})
  query = {
    transactionId: transaction_id
  }
  response = get("/MSATSLimits/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query:,
                                                    verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
  else
    response
  end
end

.nmi_detail(nmi, options = {}) ⇒ Hash

NMI Detail /NMIDetail/PARTICIPANT_IDENTIFIER?transactionId=XXX&nmi=XXX&checksum=X&type=XXX&reason=XXX

Returns:

  • (Hash)

    A hashed view of the NMI Standing Data for a given NMI

Since:

  • 0.1.0



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/aemo/msats.rb', line 207

def nmi_detail(nmi, options = {})
  nmi = AEMO::NMI.new(nmi) if nmi.is_a?(String)

  options[:type]    ||= nil
  options[:reason]  ||= nil

  query = {
    transactionId: transaction_id,
    nmi: nmi.nmi,
    checksum: nmi.checksum,
    type: options[:type],
    reason: options[:reason]
  }

  response = get("/NMIDetail/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query:,
                                                  verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['NMIStandingDataResponse']['NMIStandingData']
  else
    response
  end
end

.nmi_discovery_by_address(jurisdiction_code, options = {}) ⇒ Hash

NMI Discovery - By Address

Parameters:

  • jurisdiction_code (String)

    The Jurisdiction Code

  • meter_serial_number (Integer)

    The meter’s serial number

Returns:

  • (Hash)

    The response

Raises:

  • (ArgumentError)

Since:

  • 0.1.0



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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/aemo/msats.rb', line 153

def nmi_discovery_by_address(jurisdiction_code, options = {})
  raise ArgumentError, 'jurisdiction_code is not valid' unless %w[ACT NEM NSW QLD SA VIC
                                                                  TAS].include?(jurisdiction_code)

  options[:building_or_property_name] ||= nil
  options[:location_descriptor] ||= nil
  options[:lot_number] ||= nil
  options[:flat_or_unit_number] ||= nil
  options[:flat_or_unit_type] ||= nil
  options[:floor_or_level_number] ||= nil
  options[:floor_or_level_type] ||= nil
  options[:house_number] ||= nil
  options[:house_number_suffix] ||= nil
  options[:street_name] ||= nil
  options[:street_suffix] ||= nil
  options[:street_type] ||= nil
  options[:suburb_or_place_or_locality] ||= nil
  options[:postcode] ||= nil
  options[:state_or_territory] ||= jurisdiction_code

  query = {
    transactionId: transaction_id,
    jurisdictionCode: jurisdiction_code,
    buildingOrPropertyName: options[:building_or_property_name],
    locationDescriptor: options[:location_descriptor],
    lotNumber: options[:lot_number],
    flatOrUnitNumber: options[:flat_or_unit_number],
    flatOrUnitType: options[:flat_or_unit_type],
    floorOrLevelNumber: options[:floor_or_level_number],
    floorOrLevelType: options[:floor_or_level_type],
    houseNumber: options[:house_number],
    houseNumberSuffix: options[:house_number_suffix],
    streetName: options[:street_name],
    streetSuffix: options[:street_suffix],
    streetType: options[:street_type],
    suburbOrPlaceOrLocality: options[:suburb_or_place_or_locality],
    postcode: options[:postcode],
    stateOrTerritory: options[:state_or_territory]
  }

  response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query:,
                                                     verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    myresponse = response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
    myresponse.is_a?(Hash) ? [myresponse] : myresponse
  else
    response
  end
end

.nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, options = {}) ⇒ Hash

NMI Discovery - By Delivery Point Identifier

Parameters:

  • jurisdiction_code (String)

    The Jurisdiction Code

  • delivery_point_identifier (Integer)

    Delivery Point Identifier

Returns:

  • (Hash)

    The response

Raises:

  • (ArgumentError)

Since:

  • 0.1.0



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/aemo/msats.rb', line 96

def nmi_discovery_by_delivery_point_identifier(jurisdiction_code, delivery_point_identifier, options = {})
  raise ArgumentError, 'jurisdiction_code is not valid' unless %w[ACT NEM NSW QLD SA VIC
                                                                  TAS].include?(jurisdiction_code)

  unless delivery_point_identifier.respond_to?('to_i')
    raise ArgumentError,
          'delivery_point_identifier is not valid'
  end
  if delivery_point_identifier.to_i < 10_000_000 || delivery_point_identifier.to_i > 99_999_999
    raise ArgumentError,
          'delivery_point_identifier is not valid'
  end

  query = {
    transactionId: transaction_id,
    jurisdictionCode: jurisdiction_code,
    deliveryPointIdentifier: delivery_point_identifier.to_i
  }

  response = get("/NMIDiscovery/#{@participant_id}", basic_auth: @auth, headers: HEADERS, query:,
                                                     verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
  else
    response
  end
end

.nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, options = {}) ⇒ Hash

NMI Discovery - By Meter Serial Numner

Parameters:

  • jurisdiction_code (String)

    The Jurisdiction Code

  • meter_serial_number (Integer)

    The meter’s serial number

Returns:

  • (Hash)

    The response

Raises:

  • (ArgumentError)

Since:

  • 0.1.0



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/aemo/msats.rb', line 129

def nmi_discovery_by_meter_serial_number(jurisdiction_code, meter_serial_number, options = {})
  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:,
                                                     verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['NMIDiscoveryResponse']['NMIStandingData']
  else
    response
  end
end

.system_status(options = {}) ⇒ Hash

Participant System Status /ParticipantSystemStatus/PARTICIPANT_IDENTIFIER?transactionId=XXX

Returns:

  • (Hash)

    The report results from the Participant System Status web service query

Since:

  • 0.1.0



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/aemo/msats.rb', line 234

def system_status(options = {})
  query = {
    transactionId: transaction_id
  }
  response = get("/ParticipantSystemStatus/#{@participant_id}", basic_auth: @auth, headers: HEADERS,
                                                                query:, verify: (options[:verify_ssl] != false))
  if response.response.code == '200'
    response.parsed_response['aseXML']['Transactions']['Transaction']['ReportResponse']['ReportResults']
  else
    response
  end
end

.transaction_idString

Method for creating a unique transaction id

Returns:

  • (String)

    the transaction id

Since:

  • 0.1.0



267
268
269
# File 'lib/aemo/msats.rb', line 267

def transaction_id
  Digest::SHA1.hexdigest(::Time.now.to_s)[0..35]
end