Class: Smartcar::User

Inherits:
Base
  • Object
show all
Defined in:
lib/smartcar/user.rb

Overview

Class to get to user API.

Constant Summary collapse

USER_PATH =

Path for hitting user end point

'/user'.freeze

Constants inherited from Base

Base::BASIC, Base::BEARER

Instance Attribute Summary collapse

Attributes inherited from Base

#error, #meta

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#fetch

Methods included from Utils

#get_config, #get_error

Constructor Details

#initialize(token:) ⇒ User

Returns a new instance of User.

Raises:



10
11
12
13
# File 'lib/smartcar/user.rb', line 10

def initialize(token:)
  raise InvalidParameterValue.new, "Access Token(token) is a required field" if token.nil?
  @token = token
end

Instance Attribute Details

#idString

Smartcar user id.

Returns:

  • (String)

    the current value of id



5
6
7
# File 'lib/smartcar/user.rb', line 5

def id
  @id
end

#tokenString

Access token used to connect to Smartcar API.

Returns:

  • (String)

    the current value of token



5
6
7
# File 'lib/smartcar/user.rb', line 5

def token
  @token
end

Class Method Details

.user_id(token:) ⇒ User

Class method Used to get user id EX : Smartcar::User.fetch API - https://smartcar.com/docs/api#get-user

Parameters:

  • token (String)

    Access token

Returns:



21
22
23
# File 'lib/smartcar/user.rb', line 21

def self.user_id(token:)
  new(token: token).get(USER_PATH)['id']
end