class UkCompaniesHouse::Client

Attributes

api_key[RW]

Public Class Methods

new(api_key: nil) click to toggle source
# File lib/uk_companies_house/client.rb, line 6
def initialize(api_key: nil)
  @api_key = api_key || UkCompaniesHouse.api_key
end

Public Instance Methods

connection() click to toggle source
# File lib/uk_companies_house/client.rb, line 10
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
get(url, data = {}) click to toggle source
# File lib/uk_companies_house/client.rb, line 28
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
post(url, data = {}) click to toggle source
# File lib/uk_companies_house/client.rb, line 20
def post(url, data = {})
  connection.post do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.body = data.to_json
  end
end