-
Notifications
You must be signed in to change notification settings - Fork 5
Full decoding now pulls more data #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
88eaa8e
ffcb15b
62ac2c5
ecdbe17
cddb6f6
2ca3312
f9a725e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,16 @@ module Specification | |
| module Color | ||
|
|
||
| class ColorsByStyle | ||
| attr_reader :colors, :count | ||
| attr_reader :exterior, :interior #, :colors, :count | ||
|
|
||
| def initialize(attributes) | ||
| @colors = attributes['colors'].map { |json| ColorsDetails.new(json) } if attributes.key?('colors') | ||
| @count = attributes['colorsCount'] | ||
| # @colors = attributes['colors'].map { |json| ColorsDetails.new(json) } if attributes.key?('colors') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fabrouy Sorry for the dumb question but is this the result of a more recent API change?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it was different in the past. Right now doing .map over colors just loops over a couple of keys (interior and exterior) not the actual colors.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I'm fine with that as long as the test works out fine. |
||
| # ['colors'] is actually a size 2 Array that contains interior colors in position 0 and exterior colors in position 1 | ||
| @interior, @exterior = [], [] | ||
| @interior = attributes['colors'][0]['options'].map { |json| InteriorColor.new(json) } if attributes['colors'][0].present? | ||
| @exterior = attributes['colors'][1]['options'].map { |json| ExteriorColor.new(json) } if attributes['colors'][1].present? | ||
|
|
||
| # @count = attributes['colorsCount'] # Could not find this key in response | ||
| end | ||
|
|
||
| def self.find(style_id, api_params = {}) | ||
|
|
@@ -24,17 +29,15 @@ def self.find(style_id, api_params = {}) | |
| end | ||
| end | ||
|
|
||
| class ColorsDetails | ||
| class Color | ||
| attr_reader :id, | ||
| :name, | ||
| :equipment_type, | ||
| :availability, | ||
| :manufacture_option_name, | ||
| :manufacture_option_code, | ||
| :category, | ||
| :attributes, #not implemented | ||
| :color_chips, #not_implemented | ||
| :fabric_Types #not implemented | ||
| :manufacture_option_code, | ||
| :color_chips, | ||
| :attributes #not implemented | ||
|
|
||
| def initialize(attributes) | ||
| @id = attributes['id'] | ||
|
|
@@ -43,7 +46,7 @@ def initialize(attributes) | |
| @availability = attributes['availability'] | ||
| @manufacture_option_name = attributes['manufactureOptionName'] | ||
| @manufacture_option_code = attributes['manufactureOptionCode'] | ||
| @category = attributes['category'] | ||
| @color_chips = attributes['colorChips'] | ||
| end | ||
|
|
||
| def self.find(color_id, api_params = {}) | ||
|
|
@@ -53,6 +56,21 @@ def self.find(color_id, api_params = {}) | |
| end | ||
| end | ||
|
|
||
| class InteriorColor < Color | ||
| attr_reader :fabric_types | ||
|
|
||
| def initialize(attributes) | ||
| super(attributes) | ||
| @fabric_types = attributes['fabricTypes'] | ||
| end | ||
| end | ||
|
|
||
| class ExteriorColor < Color | ||
| def initialize(attributes) | ||
| super(attributes) | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module Edmunds | ||
| module Vehicle | ||
| module Specification | ||
| module Drivetrain | ||
| class Drivetrain | ||
|
|
||
| def initialize(name) | ||
| @name = name | ||
| end | ||
|
|
||
| def name(view = :long) | ||
| if view == :short | ||
| case @name | ||
| when "front wheel drive" then "FWD" | ||
| when "rear wheel drive" then "RWD" | ||
| when "all wheel drive" then "AWD" | ||
| when "four wheel drive" then "4WD" | ||
| end | ||
| else | ||
| @name | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,11 +38,28 @@ def self.find(style_id, api_params = {}) | |
| end | ||
|
|
||
| class Engine | ||
| attr_reader :id | ||
| attr_reader :code, :compression_ratio, :compressor_type, :configuration, :cylinder, :displacement, :equipment_type, :fuel_type, | ||
| :horsepower, :id, :manufacturer_engine_code, :name, :rpm, :size, :torque, :total_valves, :type, :valve | ||
|
|
||
| def initialize(attributes) | ||
| @code = attributes['code'] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for finishing this for me. |
||
| @compression_ratio = attributes['compressionRatio'] | ||
| @compressor_type = attributes['compressorType'] | ||
| @configuration = attributes['configuration'] | ||
| @cylinder = attributes['cylinder'] | ||
| @displacement = attributes['displacement'] | ||
| @equipment_type = attributes['equipmentType'] | ||
| @fuel_type = attributes['fuelType'] | ||
| @horsepower = attributes['horsepower'] | ||
| @id = attributes['id'] | ||
| #TODO | ||
| @manufacturer_engine_code = attributes['manufacturerEngineCode'] | ||
| @name = attributes['name'] | ||
| @rpm = attributes['rpm'] | ||
| @size = attributes['size'] | ||
| @torque = attributes['torque'] | ||
| @total_valves = attributes['totalValves'] | ||
| @type = attributes['type'] | ||
| @valve = attributes['valve'] | ||
| end | ||
|
|
||
| def self.find(engine_id, api_params = {}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,27 @@ module Specification | |
| module Option | ||
|
|
||
| class OptionsByStyle | ||
| attr_reader :options, | ||
| :count | ||
| attr_reader :interior, :exterior, :roof, :interior_trim, :mechanical, :package, :additional_fees, :other | ||
|
|
||
| def initialize(attributes) | ||
| @options = attributes['options'].map { |json| Option.new(json) } if attributes.key?('options') | ||
| @count = attributes['optionsCount'] | ||
| @interior, @exterior, @roof, @interior_trim = [], [], [], [] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks reasonable. |
||
| @mechanical, @package, @aditional_fees, @other = [], [], [], [] | ||
|
|
||
| attributes['options'].each do |category_with_option| | ||
| category = category_with_option['category'] | ||
| options = category_with_option['options'] | ||
| if category == "Interior" then @interior = options.map { |json| Option.new(json) } | ||
| elsif category == "Exterior" then @exterior = options.map { |json| Option.new(json) } | ||
| elsif category == "Roof" then @roof = options.map { |json| Option.new(json) } | ||
| elsif category == "Interior Trim" then @interior_trim = options.map { |json| Option.new(json) } | ||
| elsif category == "Mechanical" then @mechanical = options.map { |json| Option.new(json) } | ||
| elsif category == "Package" then @package = options.map { |json| Option.new(json) } | ||
| elsif category == "Additional Fees" then @additional_fees = options.map { |json| Option.new(json) } | ||
| elsif category == "Other" then @other = options.map { |json| Option.new(json) } | ||
| end | ||
| end | ||
| # @options = attributes['options'].map { |json| Option.new(json) } if attributes.key?('options') | ||
| # @count = attributes['optionsCount'] | ||
| end | ||
|
|
||
| def self.find(style_id, api_params = {}) | ||
|
|
@@ -46,9 +61,10 @@ def initialize(attributes) | |
| @availability = attributes['availability'] | ||
| @manufacture_option_name = attributes['manufactureOptionName'] | ||
| @manufacture_option_code = attributes['manufactureOptionCode'] | ||
| @equipment = attributes['equipment'] | ||
| @category = attributes['category'] | ||
| @attributes = attributes['attributes'] | ||
| @equipment = attributes['equipment'] | ||
| @price = attributes['price'] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| end | ||
|
|
||
| def self.find(option_id, api_params = {}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,17 +9,32 @@ module Vehicle | |
| module Specification | ||
| module Style | ||
| class Style | ||
| attr_reader :id, :name, :trim, :body, :year, :make_name, :model_name | ||
|
|
||
| def initialize(attributes) | ||
| @id = attributes['id'] | ||
| @name = attributes['name'] | ||
| @trim = attributes['trim'] | ||
| @body = attributes['submodel']['body'] | ||
| # TODO: Not sure whether this is valuable or not to expose... | ||
| # @year = attributes["year"]["year"] | ||
| # @make_name = attributes["make"]["name"] | ||
| # @model_name = attributes["model"]["name"] | ||
| attr_reader :id, :name, :year, :make, :model, :trim, :body, :engine, :transmission, :driven_wheels, | ||
| :doors, :colors, :options, :manufacturer_code, :price, :categories, :states, :squish_vins, :mpg | ||
|
|
||
| def initialize(attributes, view = nil) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you refactor this to use the new params style?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, what would be the new params style? Like adding that 'view' option inside the attributes hash?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/Sovietaced/edmunds/blob/master/lib/edmunds/vehicle/specification/make.rb#L19-L36 I have completed the refactor that supported optional params. In this case "view" is an optional parameter. Instead of instantiating the object and storing the "view" enum I would just handle engine, transmission, driven_wheels if there are found in the hash.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh gotcha! 👍 |
||
| @id = attributes.try(:[], 'id') | ||
| @name = attributes.try(:[], 'name') | ||
| @year = attributes.try(:[], 'year').try(:[], 'year') | ||
| @make = Edmunds::Vehicle::Specification::Make::Make.new(attributes.try(:[], 'make')) if attributes.try(:[], 'make') | ||
| @model = Edmunds::Vehicle::Specification::Model::Model.new(attributes.try(:[], 'model')) if attributes.try(:[], 'model') | ||
| @trim = attributes.try(:[], 'trim') | ||
| @body = attributes.try(:[], 'submodel').try(:[], 'body') | ||
|
|
||
| if view == 'full' | ||
| @engine = Edmunds::Vehicle::Specification::Engine::Engine.new(attributes.try(:[], 'engine')) if attributes.try(:[], 'engine') | ||
| @transmission = Edmunds::Vehicle::Specification::Transmission::Transmission.new(attributes.try(:[], 'transmission')) if attributes.try(:[], 'transmission') | ||
| @driven_wheels = Edmunds::Vehicle::Specification::Drivetrain::Drivetrain.new(attributes.try(:[], 'drivenWheels')) if attributes.try(:[], 'drivenWheels') | ||
| @doors = attributes.try(:[], 'numOfDoors') | ||
| @options = Edmunds::Vehicle::Specification::Option::OptionsByStyle.new(attributes) | ||
| @colors = Edmunds::Vehicle::Specification::Color::ColorsByStyle.new(attributes) | ||
| @manufacturer_code = attributes.try(:[], 'manufacturerCode') | ||
| @price = attributes.try(:[], 'price') | ||
| @categories = attributes.try(:[], 'categories') | ||
| @states = attributes.try(:[], 'states') | ||
| @squish_vins = attributes.try(:[], 'squishVins') | ||
| @mpg = attributes.try(:[], 'MPG') | ||
| end | ||
| end | ||
|
|
||
| def self.find(id, api_params = {}) | ||
|
|
@@ -37,7 +52,7 @@ def self.find(id, api_params = {}) | |
| end | ||
|
|
||
| attributes = JSON.parse(response.body) | ||
| new(attributes) | ||
| new(attributes, api_params[:view]) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| module Edmunds | ||
| module Vehicle | ||
| module Specification | ||
| module Transmission | ||
| class Transmission | ||
| attr_reader :id, :name, :equipment_type, :availability, :automatic_type, :transmission_type, :number_of_speeds | ||
|
|
||
| def initialize(attributes) | ||
| @id = attributes['id'] | ||
| @name = attributes['name'] | ||
| @equipment_type = attributes['equipmentType'] | ||
| @availability = attributes['availability'] | ||
| @automatic_type = attributes['automaticType'] | ||
| @transmission_type = attributes['transmissionType'] | ||
| @number_of_speeds = attributes['numberOfSpeeds'] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is used in the request.rb class
require 'active_support/core_ext/hash'When I bundle it fails to install but I know I have it... I'm confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this up on master.