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

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

Returns a new instance of ModelsCount.



76
77
78
# File 'lib/edmunds/vehicle/specification/model.rb', line 76

def initialize(attributes)
  @count = attributes['modelsCount']
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



74
75
76
# File 'lib/edmunds/vehicle/specification/model.rb', line 74

def count
  @count
end

Class Method Details

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/edmunds/vehicle/specification/model.rb', line 80

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