class BlueBank::Client

Attributes

subscriber_key[R]

Public Class Methods

new(subscriber_key:) click to toggle source
# File lib/blue_bank/client.rb, line 6
def initialize(subscriber_key:)
  @subscriber_key = subscriber_key
end

Public Instance Methods

customer() click to toggle source
# File lib/blue_bank/client.rb, line 18
def customer
  @customer ||= Customer.new(client: self)
end
get(path) click to toggle source
# File lib/blue_bank/client.rb, line 10
def get(path)
  JSON.parse(adapter.get(base_url + path, request_headers))
end
post(path:, json:) click to toggle source
# File lib/blue_bank/client.rb, line 14
def post(path:, json:)
  JSON.parse(adapter.post(base_url + path, JSON.dump(json), request_headers))
end

Private Instance Methods

adapter() click to toggle source
# File lib/blue_bank/client.rb, line 28
def adapter
  RestClient
end
base_url() click to toggle source
# File lib/blue_bank/client.rb, line 24
def base_url
  "https://bluebank.azure-api.net/api/v0.6.3"
end
bearer() click to toggle source
# File lib/blue_bank/client.rb, line 40
def bearer
  @bearer ||= jwt_from_cloudlevel.fetch("bearer")
end
jwt_from_cloudlevel() click to toggle source
# File lib/blue_bank/client.rb, line 44
def jwt_from_cloudlevel
  JSON.parse(adapter.get("https://cloudlevel.io/token", { "Ocp-Apim-Subscription-Key" => subscriber_key }))
end
request_headers() click to toggle source
# File lib/blue_bank/client.rb, line 32
def request_headers
  {
    "Content-Type" => "application/json",
    "Ocp-Apim-Subscription-Key" => subscriber_key,
    "Bearer" => bearer,
  }
end