Sha256: be1644fe2c5b52dd7fd2ea7c18212dbde0be703cc6f92fa22ecede90fb7a42f2

Contents?: true

Size: 975 Bytes

Versions: 1

Compression:

Stored size: 975 Bytes

Contents

module RestClient
  BASE_URL = 'https://service.blackbookcloud.com'.freeze

  def headers
    token = Base64.encode64("#{username}:#{password}")
    { Authorization: "Basic #{token}" }
  end

  def process_response(response, transformer = nil)
    status = 200

    if response['error_count'].positive?
      response = { error: response['message_list'][0]['description'] }
      status = 400
    elsif transformer
      response = send(transformer, response)
    end

    [response, status]
  end

  def map_fields(response)
    return {} unless response && response['used_vehicles'] && response['used_vehicles']['used_vehicle_list']
    vehicle_range = response['used_vehicles']['used_vehicle_list'][0]

    return {
      range: {
        xclean: vehicle_range['adjusted_whole_xclean'],
        clean: vehicle_range['adjusted_whole_clean'],
        average: vehicle_range['adjusted_whole_avg'],
        rough: vehicle_range['adjusted_whole_rough']
      }
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blackbook_client-0.1.6 lib/rest_client.rb