Sha256: be4d80020c497a1a1346f2ece1cb5652e3c666ec67722f43e5cdf83ba7ec8c03

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

module Oschadbank
  class Request
    extend Dry::Initializer::Mixin

    param :request_url
    param :request_params

    def perform
      response = make_request

      unless response.status == 200
        raise InvalidResponse, "Response status: #{response.status}"
      end

      response
    end

    private

    def make_request
      connection = Faraday::Connection.new(request_url, ssl: {
        ca_file: cert_file,
      })
      connection.post(request_url, request_params)
    rescue Faraday::Error => e
      raise RequestError, e.message
    end

    def cert_file
      File.expand_path("../../data/cert.pem", File.dirname(__FILE__))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oschadbank-0.1.10 lib/oschadbank/request.rb
oschadbank-0.1.9 lib/oschadbank/request.rb
oschadbank-0.1.8 lib/oschadbank/request.rb