From cb9354ff791c8516db0ad9e667a0c6fe58706bf2 Mon Sep 17 00:00:00 2001 From: Rogers Date: Tue, 7 Feb 2023 18:57:53 -0600 Subject: [PATCH] Remove redundant code --- lib/smartcar.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/smartcar.rb b/lib/smartcar.rb index 2d15b3a..4f3a6b6 100644 --- a/lib/smartcar.rb +++ b/lib/smartcar.rb @@ -109,13 +109,7 @@ def get_compatibility(vin:, scope:, country: 'US', options: {}) # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-user # and a meta attribute with the relevant items from response headers. def get_user(token:, version: Smartcar.get_api_version, options: {}) - base_object = Base.new( - { - token: token, - version: version, - service: options[:service] - } - ) + base_object = base_initializer(token, version, options) base_object.build_response(*base_object.get(PATHS[:user])) end @@ -131,13 +125,7 @@ def get_user(token:, version: Smartcar.get_api_version, options: {}) # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-all-vehicles # and a meta attribute with the relevant items from response headers. def get_vehicles(token:, paging: {}, version: Smartcar.get_api_version, options: {}) - base_object = Base.new( - { - token: token, - version: version, - service: options[:service] - } - ) + base_object = base_initializer(token, version, options) base_object.build_response(*base_object.get( PATHS[:vehicles], paging @@ -193,5 +181,15 @@ def generate_basic_auth(options, base_object) client_secret = options[:client_secret] || base_object.get_config('SMARTCAR_CLIENT_SECRET') Base64.strict_encode64("#{client_id}:#{client_secret}") end + + def base_initializer(token, version, options) + Base.new( + { + token: token, + version: version, + service: options[:service] + } + ) + end end end