Sha256: 27738a8c1010021dddbcaa5b30ea9592ca0b41e04b642b721d7357ad02404a7f

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
require 'dry-struct'
require 'json'
require 'faraday'
require 'faraday_middleware'
require_relative 'api/types'
require_relative 'api/signature'
require_relative 'api/requester'
require_relative 'api/transport'
require_relative 'api/callback_data'
require_relative 'api/currencies_list'
require_relative 'api/take_address'
require_relative 'api/withdrawal'

module CoinsPaid
  module API
    module_function

    Error = Class.new RuntimeError
    ProcessingError = Class.new Error
    ConnectionError = Class.new Error
    InvalidSignatureError = Class.new Error

    URL = 'https://app.coinspaid.com/api/v2/'

    class << self
      attr_accessor :public_key
      attr_accessor :secret_key
    end

    @public_key = ENV['COINS_PAID_PUBLIC_KEY']
    @secret_key = ENV['COINS_PAID_SECRET_KEY']

    def configure
      yield self
    end

    def take_address(foreign_id:, currency:, convert_to:)
      Requester.call(
        TakeAddress,
        foreign_id: foreign_id, currency: currency, convert_to: convert_to
      )
    end

    def withdraw(foreign_id:, amount:, currency:, convert_to:, address:)
      Requester.call(
        Withdrawal,
        foreign_id: foreign_id, amount: amount, currency: currency, convert_to: convert_to, address: address
      )
    end

    def currencies_list
      CurrenciesList.call
    end

    def callback(request_body, headers)
      Signature.check!(
        request_body: request_body,
        key: headers['X-Processing-Key'],
        signature: headers['X-Processing-Signature']
      )

      CallbackData.from_json(JSON.parse(request_body, symbolize_names: true))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coins_paid_api-1.0.5 lib/coins_paid/api.rb
coins_paid_api-1.0.4 lib/coins_paid/api.rb
coins_paid_api-1.0.3 lib/coins_paid/api.rb
coins_paid_api-1.0.2 lib/coins_paid/api.rb
coins_paid_api-1.0.1 lib/coins_paid/api.rb