Class: Booqable::Client

Inherits:
Object
  • Object
show all
Includes:
Auth, Configurable, HTTP, Resources
Defined in:
lib/booqable/client.rb

Overview

Client for the Booqable API

Provides a Ruby interface to interact with the Booqable rental management API. The client can be configured with various authentication methods including API keys, OAuth, and single-use tokens.

Examples:

Initialize with API key

client = Booqable::Client.new(
  api_key: "your_api_key",
  company_id: "your_company_id"
)

Initialize with OAuth

client = Booqable::Client.new(
  client_id: "your_client_id",
  client_secret: "your_client_secret",
  company_id: "your_company_id"
)

See Also:

Constant Summary collapse

SECRETS =

List of configuration keys that contain sensitive information and should be masked in inspect output

%w[
  client_secret
  client_id
  api_key
  single_use_token
  single_use_token_private_key
  single_use_token_secret
  refresh_token
  access_token
]

Constants included from HTTP

HTTP::CONVENIENCE_HEADERS

Constants included from Resources

Resources::ALL_RESOURCES, Resources::RESOURCES_FILE_PATH

Instance Attribute Summary

Attributes included from Configurable

#api_domain, #api_endpoint, #api_key, #api_version, #auto_paginate, #client_id, #client_secret, #company_id, #connection_options, #debug, #default_media_type, #middleware, #no_retries, #per_page, #proxy, #read_token, #redirect_uri, #single_use_token, #single_use_token_algorithm, #single_use_token_company_id, #single_use_token_expiration_period, #single_use_token_private_key, #single_use_token_secret, #single_use_token_user_id, #ssl_verify_mode, #user_agent, #write_token

Instance Method Summary collapse

Methods included from HTTP

#agent, #api_endpoint, #default_headers, #delete, #faraday, #faraday_builder, #faraday_options, #get, #head, #last_response, #last_response_body, #logger, #normalized_path, #paginate, #parse_options_with_convenience_headers, #patch, #post, #put, #rate_limit, #request, #response_data_with_correct_encoding, #sawyer_options, #sawyer_serializer, #total_present_in_stats?

Methods included from Auth

#api_key_authenticated?, #authenticate_with_code, #inject_auth_middleware, #oauth_authenticated?, #oauth_client, #single_use_token_authenticated?

Methods included from Configurable

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

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize a new Client

Parameters:

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

    Configuration options for the client

See Also:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/booqable/client.rb', line 47

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  #
  # This may look like a `.keys.each` which should be replaced with `#each_key`, but
  # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
  # The class doesn't fulfill the whole `Enumerable` contract.
  Booqable::Configurable.keys.each do |key|
    value = options[key].nil? ? Booqable.instance_variable_get(:"@#{key}") : options[key]
    instance_variable_set(:"@#{key}", value)
  end
end

Instance Method Details

#inspectString

String representation of the client with sensitive information masked

Overrides the default inspect method to hide sensitive configuration values like API keys, client secrets, and tokens by replacing them with asterisks.

Examples:

client = Booqable::Client.new(api_key: "secret123")
client.inspect #=> "#<Booqable::Client:0x... @api_key=\"*********\">"

Returns:

  • (String)

    String representation with secrets masked



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/booqable/client.rb', line 69

def inspect
  inspected = super

  secrets = SECRETS.map { |secret| instance_variable_get("@#{secret}") }

  inspected.gsub!(/"(#{secrets.join("|")})"/) do |match|
    match.gsub!(/./, "*")
  end

  inspected
end