Sha256: bf3a1db149bea31cbb222fdfc78148f962346a4eee36a7e5f8d1473ade9ac7cf

Contents?: true

Size: 629 Bytes

Versions: 11

Compression:

Stored size: 629 Bytes

Contents

# frozen_string_literal: true

require 'companies_house_hub/errors'

module CompaniesHouseHub
  class BaseModel
    def self.get(path, params)
      result = CompaniesHouseHub.connection.get(path, params)

      raise APIKeyError, result.body[:error] if result.status == 401

      result
    end

    def get(path, params)
      self.class.get(path.strip, params)
    end

    def self.format_url(url, params)
      formatted = url.dup.strip

      params.each { |key, value| formatted.sub!(":#{key}", value) }

      formatted
    end

    def format_url(url, params)
      self.class.format_url(url, params)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
companies_house_hub-0.1.12 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.11 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.10 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.9 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.8 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.7 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.6 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.5 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.4 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.3 lib/companies_house_hub/base_model.rb
companies_house_hub-0.1.2 lib/companies_house_hub/base_model.rb