Module: UkVehicleData

Defined in:
lib/uk_vehicle_data.rb,
lib/uk_vehicle_data/version.rb,
lib/uk_vehicle_data/api_resource.rb,
lib/uk_vehicle_data/battery_data.rb,
lib/uk_vehicle_data/vehicle_data.rb,
lib/uk_vehicle_data/mot_history_data.rb,
lib/uk_vehicle_data/api_operations/retrieve.rb,
lib/uk_vehicle_data/mot_history_and_tax_status_data.rb

Defined Under Namespace

Modules: APIOperations Classes: ApiResource, AuthenticationError, BatteryData, ConfigurationError, MotHistoryAndTaxStatusData, MotHistoryData, UkVehicleDataError, VehicleData

Constant Summary collapse

API_BASE =
"https://uk1.ukvehicledata.co.uk/api/datapackage/"
VERSION =
"0.4.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_key=(value) ⇒ Object (writeonly)

Sets the attribute api_key

Parameters:

  • value

    the value to set the attribute api_key to.



23
24
25
# File 'lib/uk_vehicle_data.rb', line 23

def api_key=(value)
  @api_key = value
end

Class Method Details

.request(method, resource, params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/uk_vehicle_data.rb', line 25

def request method, resource, params={}
    vd_api_key = params[:auth_apikey] || UkVehicleData.api_key
    vd_api_nullitems = params[:api_nullitems] || 1
    vd_version = params[:v] || 2

    params.merge!({api_nullitems: vd_api_nullitems, v: vd_version, auth_apikey: vd_api_key})

    defined? vd_api_key or raise(
        ConfigurationError, "UkVehicleData api key not configured"
    )
    defined? method or raise(
        ArgumentError, "Request method has not been specified"
    )
    defined? resource or raise(
        ArgumentError, "Request resource has not been specified"
    )

    headers = { accept: :json, content_type: :json }.merge({params: params})

    RestClient::Request.new({
        method: method,
        url: API_BASE + resource,
        headers: headers
    }).execute do |response, request, result|
        str_response = response.to_str        
        str_response.blank? ? '' : JSON.parse(str_response)
    end
end