class QontoOfx::ApiGateway

Call and verify responses for Qonto API

Public Class Methods

new(slug, token) click to toggle source
# File lib/api_gateway.rb, line 9
def initialize(slug, token)
  @slug = slug
  @token = token
  @organization_validator = OrganizationValidator.new
  @transactions_listing_validator = TransactionsListingValidator.new
end

Public Instance Methods

check_against_validator(response, validator) click to toggle source
# File lib/api_gateway.rb, line 37
def check_against_validator(response, validator)
  if response.code != 200
    raise "Qonto API call failed \
      (status: #{response.code}): #{response.body}"
  end

  raise "response does not match schema: \
    #{response.body}" unless validator.valid? response.body
end
fetch_organization() click to toggle source
# File lib/api_gateway.rb, line 16
def fetch_organization
  response = RestClient.get(
    "https://thirdparty.qonto.eu/v2/organizations/#{@slug}",
    Authorization: "#{@slug}:#{@token}"
  )
  check_against_validator response, @organization_validator

  JSON.parse(response.body)
end
fetch_transactions(url) click to toggle source
# File lib/api_gateway.rb, line 26
def fetch_transactions(url)
  response = RestClient.get(
    url,
    Authorization: "#{@slug}:#{@token}"
  )

  check_against_validator response, @transactions_listing_validator

  JSON.parse(response.body)
end