class VehicleData::Base

Attributes

app_key[RW]
data[RW]
options[RW]
request[RW]
response[RW]
secret[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/vehicle_data.rb, line 24
def initialize(options={})
  @app_key = VehicleData.configuration.app_key
  @secret  = VehicleData.configuration.secret
  @data    = options.merge!({ :app => @app_key, :v => 0.2, :t => Time.now.to_i })
end

Public Instance Methods

send_request() click to toggle source
# File lib/vehicle_data.rb, line 30
def send_request
  response = Typhoeus.get("#{base_uri}/?#{build_params(@data)}&hash=#{calculate_signature}")
  JSON.parse(response.body)
end

Private Instance Methods

base_uri() click to toggle source
# File lib/vehicle_data.rb, line 41
def base_uri
  "http://api.vehicledata.co"
end
build_params(params) click to toggle source
# File lib/vehicle_data.rb, line 45
def build_params(params)
   params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
end
calculate_signature() click to toggle source
# File lib/vehicle_data.rb, line 36
def calculate_signature
  signature = Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret, build_params(@data)))
  URI.encode(signature)
end