Sha256: 2fb28ad52ef4aeacd4d76c3e766699aaab0a118bc63a7456b6a668dd47082296

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Methods
  def assert_required_keys!(options, *keys)
    keys.each do |key|
      raise 'Required key missing!' if options[key].nil?
    end
  end

  def assert_one_of!(options, *keys)
    raise 'Missing one of required keys!' unless (options.keys & keys).any?
  end

  def generate_uri(*path)
    encoded_uri = URI.encode(OnlinePaymentPlatform.configuration.base_uri + path.join('/'))
    URI.parse encoded_uri
  end

  def post(uri, payload = {})
    config = OnlinePaymentPlatform.configuration

    req = Net::HTTP::Post.new(uri, { 'Content-Type': 'text/json' })
    req['Authorization'] = "Bearer #{config.api_key}"
    req.body = payload.to_json

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request req
    end

    JSON.parse response.body
  end

  def fetch(uri)
    config = OnlinePaymentPlatform.configuration

    req = Net::HTTP::Get.new(uri)
    req['Authorization'] = "Bearer #{config.api_key}"

    byebug
    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request req
    end

    JSON.parse response.body
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
online_payment_platform-0.0.2 lib/online_payment_platform/methods.rb