class Edmunds::Vehicle::Specification::Model::Models

Attributes

count[R]
models[R]

Public Class Methods

find(make_name, api_params = {}) click to toggle source
# File lib/edmunds/vehicle/specification/model.rb, line 53
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
new(attributes) click to toggle source
# File lib/edmunds/vehicle/specification/model.rb, line 48
def initialize(attributes)
  @count = attributes['modelsCount']
  @models = attributes['models'].map { |json| Model.new(json) } if attributes.key?('models')
end