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

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) ⇒ Models

Returns a new instance of Models.



45
46
47
48
# File 'lib/edmunds/vehicle/specification/model.rb', line 45

def initialize(attributes)
  @count = attributes['modelsCount']
  @models = attributes['models'].map { |json| Model.new(json) } if attributes.key?('models')
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



43
44
45
# File 'lib/edmunds/vehicle/specification/model.rb', line 43

def count
  @count
end

#modelsObject (readonly)

Returns the value of attribute models.



43
44
45
# File 'lib/edmunds/vehicle/specification/model.rb', line 43

def models
  @models
end

Class Method Details

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/edmunds/vehicle/specification/model.rb', line 50

def self.find(make_name, api_params = {})
  response = Edmunds::Api.get("#{MODEL_API_URL}/#{make_name}/models") 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