Skip to content

About

Official Bagdock API client for Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

  ----++                                ----++                    ---+++     
  ---+++                                ---++                     ---++      
 ----+---     -----     ---------  --------++ ------     -----   ----++----- 
 ---------+ --------++----------++--------+++--------+ --------++---++---++++
 ---+++---++ ++++---++---+++---++---+++---++---+++---++---++---++------++++  
----++ ---++--------++---++----++---++ ---++---++ ---+---++     -------++    
----+----+---+++---++---++----++---++----++---++---+++--++ --------+---++   
---------++--------+++--------+++--------++ -------+++ -------++---++----++  
 +++++++++   +++++++++- +++---++   ++++++++    ++++++    ++++++  ++++  ++++  
                     --------+++                                             
                       +++++++                                               

bagdock-ruby

The official Ruby SDK for the Bagdock API — manage facilities, contacts, tenancies, invoices, marketplace listings, and loyalty programs with Faraday-powered HTTP.

Gem Version License: MIT

Install

gem install bagdock

Or add to your Gemfile:

gem "bagdock"

Quick start

require "bagdock"

client = Bagdock.new(api_key: "sk_live_...")

# List operator facilities
facilities = client.operator.facilities.list

# Create a contact
contact = client.operator.contacts.create(
  email: "jane@example.com",
  first_name: "Jane",
  last_name: "Doe"
)

# Search marketplace
results = client.marketplace.search(city: "London", size: "medium")

API reference

client.operator

Method Description
facilities.list(**params) List facilities
facilities.get(id) Get a facility
contacts.list(**params) List contacts
contacts.create(data) Create a contact
listings.list(**params) List listings
tenancies.list(**params) List tenancies
units.list(**params) List units
invoices.list(**params) List invoices
payments.list(**params) List payments

client.marketplace

Method Description
search(**params) Search marketplace locations
get_listing(id) Get a listing
create_rental(data) Create a rental
get_rental(id) Get a rental

client.loyalty

Method Description
create_member(data) Create a loyalty member
get_member(id) Get a member
award_points(data) Award points
list_rewards(**params) List rewards

Error handling

begin
  client.operator.contacts.get("con_nonexistent")
rescue Bagdock::ApiError => e
  puts "API error #{e.status}: #{e.code} — #{e.message}"
  puts "Request ID: #{e.request_id}"
end

Authentication

The SDK supports three authentication modes: API keys, OAuth access tokens, and OAuth2 client credentials.

API key

client = Bagdock::Client.new(api_key: "sk_live_...")
# or set BAGDOCK_API_KEY env var
client = Bagdock::Client.new

OAuth access token

client = Bagdock::Client.new(access_token: "eyJhbGciOiJSUzI1NiIs...")

Client credentials

client = Bagdock::Client.new(
  client_id: "oac_your_client_id",
  client_secret: "bdok_secret_your_secret",
  scopes: ["facilities:read", "contacts:read"]
)

OAuth2 helpers

These helpers support authorization code (with PKCE) and device code flows. They are also useful for connect webviews in external integrations—such as access control, security, and insurance—where you need to obtain tokens without embedding long-lived secrets in user-facing code.

pkce = Bagdock::OAuth.generate_pkce
url = Bagdock::OAuth.build_authorize_url(
  client_id: "oac_...",
  redirect_uri: "https://your-app.com/callback",
  code_challenge: pkce.code_challenge,
  scope: "openid contacts:read"
)

tokens = Bagdock::OAuth.exchange_code(
  client_id: "oac_...",
  code: "authorization_code_from_callback",
  redirect_uri: "https://your-app.com/callback",
  code_verifier: pkce.code_verifier
)

device = Bagdock::OAuth.device_authorize(client_id: "bagdock-cli", scope: "developer:read")
puts "Open #{device.verification_uri} and enter: #{device.user_code}"
device_tokens = Bagdock::OAuth.poll_device_token(client_id: "bagdock-cli", device_code: device.device_code)

Configuration

Option Type Default Description
api_key String BAGDOCK_API_KEY env Your Bagdock API key (omit if using access_token or client credentials)
access_token String — OAuth access token (Bearer)
client_id String — OAuth2 client ID (with client_secret and scopes for client credentials)
client_secret String — OAuth2 client secret
scopes Array<String> — OAuth2 scopes for client credentials
base_url String https://api.bagdock.com/api/v1 API base URL
timeout Integer 30 Request timeout in seconds
max_retries Integer 3 Max retry attempts for transient errors (capped at 5)

Documentation

License

MIT — see LICENSE

About

Official Bagdock API client for Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages