Class: Api::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, Configurable, Connection
Defined in:
lib/api/client.rb

Overview

Client for an API

Constant Summary collapse

CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to Api::Connection#get

Set.new([:accept, :content_type])

Instance Attribute Summary

Attributes included from Configurable

#access_token, #access_token_prefix, #api_endpoint, #api_version, #auto_paginate, #basic_login, #basic_password, #connection_options, #per_page, #sawyer_options, #user_agent

Instance Method Summary collapse

Methods included from Connection

#agent, #delete, #get, #head, #last_response, #paginate, #patch, #post, #put, #root

Methods included from Configurable

#configure, keys, #reset!, #same_options?

Methods included from Authentication

#basic_authenticated?, #token_authenticated?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
# File 'lib/api/client.rb', line 17

def initialize(options = {})
  reset!(options)
end

Instance Method Details

#inspectString

Text representation of the client, masking tokens and passwords

Returns:

  • (String)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/api/client.rb', line 24

def inspect
  inspected = super

  # mask password
  inspected = inspected.gsub! @basic_password, "*******" if @basic_password
  # Only show last 4 of token, secret
  if @access_token
    inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
  end

  inspected
end