Module: UkVehicleData
- Defined in:
- lib/uk_vehicle_data.rb,
lib/uk_vehicle_data/version.rb,
lib/uk_vehicle_data/vehicle_data.rb,
lib/uk_vehicle_data/api_operations/retrieve.rb
Defined Under Namespace
Modules: APIOperations
Classes: AuthenticationError, ConfigurationError, UkVehicleDataError, VehicleData
Constant Summary
collapse
- API_BASE =
"https://uk1.ukvehicledata.co.uk/api/datapackage/"
- VERSION =
"0.0.1"
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
51
|
# File 'lib/uk_vehicle_data.rb', line 26
def request method, resource, params={}
vd_api_key = params[:auth_api_key] || UkVehicleData.api_key
defined? method or raise(
ArgumentError, "Request method has not been specified"
)
defined? resource or raise(
ArgumentError, "Request resource has not been specified"
)
if method == :get
= { accept: :json, content_type: :json }.merge({params: params})
payload = nil
else
= { accept: :json, content_type: :json }
payload = params
end
RestClient::Request.new({
method: method,
url: API_BASE + resource,
payload: payload ? payload.to_json : nil,
headers:
}).execute do |response, request, result|
str_response = response.to_str
str_response.blank? ? '' : JSON.parse(str_response)
end
end
|