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
]
OPTION_ALIASES =

Accepted aliases for configuration options, mapping the alias to its canonical Booqable::Configurable key.

{
  skip_retries: :no_retries
}.freeze

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, #around_refresh_token, #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

Raises:

  • (ArgumentError)

See Also:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/booqable/client.rb', line 55

def initialize(options = {})
  options = normalize_aliases(options)

  unknown_keys = options.keys.map(&:to_sym) - Booqable::Configurable.keys
  raise ArgumentError, unknown_options_message(unknown_keys) unless unknown_keys.empty?

  # 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



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/booqable/client.rb', line 99

def inspect
  inspected = super

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

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

  inspected
end

#parse_resource(payload) ⇒ Sawyer::Resource? Also known as: deserialize_resource

Parse a JSON:API payload into a Sawyer::Resource

Converts JSON:API formatted data (from webhooks or API responses) into Ruby objects with dot-notation access for convenient attribute access.

Examples:

customer = client.parse_resource(webhook_payload)
customer.name # => "John"

Parameters:

  • payload (String, Hash)

    JSON:API payload (string or parsed hash)

Returns:

  • (Sawyer::Resource, nil)

    Parsed resource object, or nil for empty input



84
85
86
# File 'lib/booqable/client.rb', line 84

def parse_resource(payload)
  Booqable::ResourceParser.parse(payload)
end