Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions lib/smartcar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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