<commit_before>require 'faraday'
require 'json'

STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + '/styles'
BASE_API_URL = Edmunds::Vehicle::API_URL_V2

module Edmunds
  module Vehicle
    module Specification
      module Style
        class Style
          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)
            @id       = attributes['id']
            @name     = attributes['name']
            @year     = attributes["year"]["year"]
            @make     = Edmunds::Vehicle::Specification::Make::Make.new(attributes['make'])
            @model    = Edmunds::Vehicle::Specification::Model::Model.new(attributes['model'])
            @trim     = attributes['trim']
            @body     = attributes['submodel']['body']

            if view == 'full'
              @engine             = Edmunds::Vehicle::Specification::Engine::Engine.new(attributes['engine'])
              @transmission       = Edmunds::Vehicle::Specification::Transmission::Transmission.new(attributes['transmission'])
              @driven_wheels      = Edmunds::Vehicle::Specification::Drivetrain::Drivetrain.new(attributes['drivenWheels'])
              @doors              = attributes['numOfDoors']
              @options            = Edmunds::Vehicle::Specification::Option::OptionsByStyle.new(attributes)
              @colors             = Edmunds::Vehicle::Specification::Color::ColorsByStyle.new(attributes)
              @manufacturer_code  = attributes['manufacturerCode']
              @price              = attributes['price']
              @categories         = attributes['categories']
              @states             = attributes['states']
              @squish_vins        = attributes['squishVins']
              @mpg                = attributes['MPG']
            end
          end

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

              request.allowed_parameters = {
                view: %w[basic full],
                fmt:  %w[json]
              }

              request.default_parameters = { view: 'basic', fmt: 'json' }

              request.required_parameters = %w[fmt]
            end
<commit_msg>Now it does not fail when edmunds pulls with missing data<commit_after>require 'faraday'
require 'json'

STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + '/styles'
BASE_API_URL = Edmunds::Vehicle::API_URL_V2

module Edmunds
  module Vehicle
    module Specification
      module Style
        class Style
          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)
            @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 = {})
            response = Edmunds::Api.get("#{STYLE_API_URL}/#{id}") do |request|
              request.raw_parameters = api_params

              request.allowed_parameters = {
                view: %w[basic full],
                fmt:  %w[json]
              }

              request.default_parameters = { view: 'basic', fmt: 'json' }

              request.required_parameters = %w[fmt]
            end

{'fraction_non_alphanumeric': 0.1443961443961444, 'fraction_numerical': 0.000756000756000756, 'mean_word_length': 2.2248628884826327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1875385', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1482, 'n_words': 262}