Class: Edmunds::Vehicle::Specification::Color::ColorsByStyle

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ColorsByStyle

Returns a new instance of ColorsByStyle.



15
16
17
18
# File 'lib/edmunds/vehicle/specification/color.rb', line 15

def initialize(attributes)
  @colors = attributes['colors'].map { |json| ColorsDetails.new(json) } if attributes.key?('colors')
  @count = attributes['colorsCount']
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



13
14
15
# File 'lib/edmunds/vehicle/specification/color.rb', line 13

def colors
  @colors
end

#countObject (readonly)

Returns the value of attribute count.



13
14
15
# File 'lib/edmunds/vehicle/specification/color.rb', line 13

def count
  @count
end

Class Method Details

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



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

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

    request.allowed_parameters = {
        category: %w[Interior Exterior],
        fmt: %w[json]
    }

    request.default_parameters = { fmt: 'json' }

    request.required_parameters = %w[fmt]
  end

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