Sha256: eb3bca20061b13089006a838167bbacbaffe7c4f2123668c4f73291ca0917fa7

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

require 'httparty'

require 'appstore_kit_fork/exceptions'

module AppstoreKitFork
  # Simple HTTP client wrapper for HTTParty
  class HTTPClient
    include HTTParty

    def initialize(target_uri)
      self.class.base_uri(target_uri)
    end

    def get(url, response_mapper)
      response = self.class.get(url)

      raise make_api_error(response) unless response.code == 200

      response_mapper.map(response.parsed_response['data'])
    end

    private

    def make_api_error(response)
      # For the time being, the first error received is enough
      error = response.parsed_response['errors'].first
      APIError.new(error['title'], error['detail'], error['status'])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appstore_kit_fork-0.0.6 lib/appstore_kit_fork/httpclient.rb