Class: Smartcar::Base

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/smartcar/base.rb

Overview

The Base class for all of the other class. Let other classes inherit from here and put common methods here.

Defined Under Namespace

Classes: InvalidParameterValue

Constant Summary collapse

BEARER =

Constant for Bearer auth type

'BEARER'.freeze
BASIC =

Constant for Basic auth type

'BASIC'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#get_config, #get_error, #initialize

Instance Attribute Details

#errorObject

Returns the value of attribute error.



16
17
18
# File 'lib/smartcar/base.rb', line 16

def error
  @error
end

#metaObject

Returns the value of attribute meta.



16
17
18
# File 'lib/smartcar/base.rb', line 16

def meta
  @meta
end

#tokenObject

Returns the value of attribute token.



16
17
18
# File 'lib/smartcar/base.rb', line 16

def token
  @token
end

Instance Method Details

#fetch(path:, options: {}, auth: 'BEARER') ⇒ Object

This requires a proc 'PATH' to be defined in the class

Parameters:

  • path (String)

    resource path

  • options (Hash) (defaults to: {})

    query params

  • auth (String) (defaults to: 'BEARER')

    type of auth

Returns:

  • (Object)


50
51
52
53
54
# File 'lib/smartcar/base.rb', line 50

def fetch(path: , options: {}, auth: 'BEARER')
  _path = path
  _path += "?#{URI.encode_www_form(options)}" unless options.empty?
  get(_path, {auth: auth})
end