Class: Edmunds::Vehicle::Specification::VinDecoding::Full

Inherits:
Object
  • Object
show all
Defined in:
lib/edmunds/vehicle/specification/vin_decoding.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Full

Returns a new instance of Full.



13
14
15
16
17
18
19
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 13

def initialize(attributes)
  @make = Edmunds::Vehicle::Specification::Make::Make.new(attributes['make'])
  @model = Edmunds::Vehicle::Specification::Model::Model.new(attributes['model'])
  @years = attributes['years'].map { |json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json) } if attributes.key?('years')
  @mpg_highway = attributes['MPG']['highway']
  @mpg_city = attributes['MPG']['city']
end

Instance Attribute Details

#makeObject (readonly)

Returns the value of attribute make.



11
12
13
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 11

def make
  @make
end

#modelObject (readonly)

Returns the value of attribute model.



11
12
13
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 11

def model
  @model
end

#mpg_cityObject (readonly)

Returns the value of attribute mpg_city.



11
12
13
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 11

def mpg_city
  @mpg_city
end

#mpg_highwayObject (readonly)

Returns the value of attribute mpg_highway.



11
12
13
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 11

def mpg_highway
  @mpg_highway
end

#yearsObject (readonly)

Returns the value of attribute years.



11
12
13
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 11

def years
  @years
end

Class Method Details

.find(vin, api_params = {}) ⇒ Basic

Get all vehicle details from make, model, year and fuel type to list of options, features and standard equipment. All this information is returned by decoding the vehicle’s VIN.

Parameters:

  • vin (String)

    number of the vehicle to search for

Returns:

  • (Basic)

    object holding the results of the query



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/edmunds/vehicle/specification/vin_decoding.rb', line 25

def self.find(vin, api_params = {})
  response = Edmunds::Api.get("#{FULL_API_URL}/#{vin}") do |request|
    request.raw_parameters = api_params

    request.allowed_parameters = {
      # OEM CODE
      fmt:  %w[json]
    }

    request.default_parameters = {fmt: 'json' }

    request.required_parameters = %w[fmt]
  end

  attributes = JSON.parse(response.body)
  new(attributes)
end