class CustomGateway::Base

Constants

API_INTERNAL_GRAPHQL
API_INTERNAL_LOGIN

Attributes

g3d_cppoms[RW]
http_client[RW]

Public Class Methods

new() click to toggle source
# File lib/custom_gateway/services/base.rb, line 10
def initialize
  self.http_client = Faraday.new('https://cpp.custom-gateway.net/v2') do |b|
    b.request :json
    b.response :json, content_type: 'application/json'
    b.adapter Faraday.default_adapter
  end

  auth!
end

Protected Instance Methods

auth!() click to toggle source
# File lib/custom_gateway/services/base.rb, line 22
def auth!
  username = CustomGateway.configuration.username
  password = CustomGateway.configuration.password

  response = http_client.post(API_INTERNAL_LOGIN, { 'username': username, 'password' => password })
  if response.status == 200
    self.g3d_cppoms = response.headers['set-cookie']
    http_client.headers['Cookie'] = g3d_cppoms
  else
    raise CustomGateway::AuthError, "Auth failed: #{response.body['error']['message']}"
  end
end
auth_failure?(response) click to toggle source
# File lib/custom_gateway/services/base.rb, line 35
def auth_failure?(response)
  response.body.key?('error') && response.body['error']['message'] == 'Authentication required'
end