Class: Edmunds::Vehicle::Specification::Model::Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Model

Returns a new instance of Model.



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

def initialize(attributes)
  @id = attributes['id']
  @name = attributes['name']
  @years = attributes['years'].map { |json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json) } if attributes.key?('years')
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#yearsObject (readonly)

Returns the value of attribute years.



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

def years
  @years
end

Class Method Details

.find(make_name, model_name, api_params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/edmunds/vehicle/specification/model.rb', line 19

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

    request.allowed_parameters = {
      submodel: Edmunds::Vehicle::SUBMODEL_REGEX,
      category: Edmunds::Vehicle::VEHICLE_CATEGORIES,
      state: %w[new used future],
      year: ((1990.to_s)..(Date.current.year.to_s)),
      view: %w[basic full],
      fmt:  %w[json]
    }

    request.default_parameters = { view: 'basic', fmt: 'json' }

    request.required_parameters = %w[fmt]
  end

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