Class: Booqable::Client
- Inherits:
-
Object
- Object
- Booqable::Client
- 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.
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
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
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new Client.
-
#inspect ⇒ String
String representation of the client with sensitive information masked.
-
#parse_resource(payload) ⇒ Sawyer::Resource?
(also: #deserialize_resource)
Parse a JSON:API payload into a Sawyer::Resource.
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
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( = {}) = normalize_aliases() unknown_keys = .keys.map(&:to_sym) - Booqable::Configurable.keys raise ArgumentError, (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 = [key].nil? ? Booqable.instance_variable_get(:"@#{key}") : [key] instance_variable_set(:"@#{key}", value) end end |
Instance Method Details
#inspect ⇒ String
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.
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.
84 85 86 |
# File 'lib/booqable/client.rb', line 84 def parse_resource(payload) Booqable::ResourceParser.parse(payload) end |