Sha256: 712656027ad6b0711f73e7c5cd522ed94e769d56b732a4e5344878ac2085c6f1

Contents?: true

Size: 896 Bytes

Versions: 2

Compression:

Stored size: 896 Bytes

Contents

module UkCompaniesHouse

  class Client
    attr_accessor :api_key

    def initialize(api_key: nil)
      @api_key = api_key || UkCompaniesHouse.api_key
    end

    def connection
      @connection ||= begin
        Faraday.new(:url => 'https://api.companieshouse.gov.uk/') do |faraday|
          faraday.headers['Authorization'] = @api_key
          faraday.response :json, :content_type => /\bjson$/
          faraday.adapter Faraday.default_adapter
        end
      end
    end

    def post(url, data = {})
      connection.post do |req|
        req.url url
        req.headers['Content-Type'] = 'application/json'
        req.body = data.to_json
      end
    end

    def get(url, data = {})
      connection.get do |req|
        req.url url
        req.headers['Content-Type'] = 'application/json'
        req.params = data
        #req.body = data.to_json
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uk_companies_house-0.1.5 lib/uk_companies_house/client.rb
uk_companies_house-0.1.3 lib/uk_companies_house/client.rb