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/vehicle_data.rb,
lib/uk_vehicle_data/api_operations/retrieve.rb
Defined Under Namespace
Modules: APIOperations
Classes: ApiResource, AuthenticationError, ConfigurationError, UkVehicleDataError, VehicleData
Constant Summary
collapse
- API_BASE =
"https://uk1.ukvehicledata.co.uk/api/datapackage/"
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_key ⇒ Object
19
20
21
22
23
|
# File 'lib/uk_vehicle_data.rb', line 19
def api_key
defined? @api_key and @api_key or raise(
ConfigurationError, "UkVehicleData api key not configured"
)
end
|
Class Method Details
.request(method, resource, params = {}) ⇒ Object
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
|
# File 'lib/uk_vehicle_data.rb', line 26
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? method or raise(
ArgumentError, "Request method has not been specified"
)
defined? resource or raise(
ArgumentError, "Request resource has not been specified"
)
= { accept: :json, content_type: :json }.merge({params: params})
RestClient::Request.new({
method: method,
url: API_BASE + resource,
headers:
}).execute do |response, request, result|
str_response = response.to_str
str_response.blank? ? '' : JSON.parse(str_response)
end
end
|