Module: BSB::AusPayNet::Client

Defined in:
lib/bsb/aus_pay_net/client.rb

Defined Under Namespace

Classes: MissingSubscriptionKeyError, Response

Constant Summary collapse

OUTPUT_PARAM_WIDTH =
30
LEADER_WIDTH =
OUTPUT_PARAM_WIDTH + 11

Class Method Summary collapse

Class Method Details

.fetch_all_bsbsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bsb/aus_pay_net/client.rb', line 15

def self.fetch_all_bsbs
  subscription_key = ENV.fetch('AUSPAYNET_SUB_KEY', nil)
  if subscription_key.nil?
    raise MissingSubscriptionKeyError, "the environment variable 'AUSPAYNET_SUB_KEY' must be present"
  end

  conn = Faraday.new(
    url: 'https://auspaynet-bicbsb-api-prod.azure-api.net',
    headers: {
      'Content-Type': 'application/json',
      'Ocp-Apim-Subscription-Key': subscription_key
    }
  ) do |faraday|
    faraday.response :raise_error
  end

  response = conn.post('/bsbquery/manual/paths/invoke') do |req|
    req.body = { outputparam: ' ' * OUTPUT_PARAM_WIDTH }.to_json
  end

  Response.new(body: response.body[LEADER_WIDTH..])
end