Sha256: 6f50450c2d4f944de624ef3a6b28eb479f80a86efb0903ded0136302d897c196
Contents?: true
Size: 716 Bytes
Versions: 1
Compression:
Stored size: 716 Bytes
Contents
# frozen_string_literal: true module Cardknox class Agent def initialize(endpoint) @conn = Faraday.new(endpoint) do |config| config.response(:raise_error) config.request(:json) end end def get(path, params = {}) parse(@conn.get(path, params)) end def post(path, body = {}) parse(@conn.post(path, body)) end private def parse(response) JSON.parse(response.body, symbolize_names: true).tap do |payload| unless ["Approved", "Success"].include?(payload[:xStatus]) raise Error::TransactionFailure.new(payload[:xError], response) end end rescue JSON::ParserError response.body end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cardknox-0.3.0 | lib/cardknox/agent.rb |