Ruby & Rails

Start integrating any APIs with the Bearer client for Ruby & Rails

Installing & initializing

Ruby
Rails
gem install bearer-rails
gem install bearer-rails
Ruby
Rails
Bearer::Configuration.setup do |config|
config.api_key = BEARER_API_KEY
end
# in config/initializers/bearer.rb
Bearer::Configuration.setup do |config|
config.api_key = BEARER_API_KEY
config.secret = BEARER_ENCRYPTION_KEY ## Used for the WebHook
end
# in config/routes.rb
Rails.application.routes.draw do
mount BearerRails::Webhooks.new, at: '/bearer-webhooks'
end

Replace the BEARER_API_KEY and BEARER_ENCRYPTION_KEY respectively with your API Key and Encryption Key that can be found on your Developer Keys page.

Calling APIs

Ruby
Rails
# GET call
bearer.integration('github')
.get('/repositories', { query: { since: 364 } })
# GET cll with a custom SetupId
bearer.integration('github')
.setup(SETUP_ID)
.get('/repositories', { query: { since: 364 } })
# POST call with OAuth
bearer.integration('github')
.auth(authId)
.post('/user/repos', { body: { name: 'Just setting up my Bearer.sh' } })
# GET call with a custom header
bearer.integration('github')
.setup(SETUP_ID)
.get('/repositories', { headers: { accept: "application/json" }, query: { since: 364 } })
# GET Call
bearer.integration('github')
.get('/repositories', { query: { since: 364 } })
# GET Call with a custom SetupId
bearer.integration('github')
.setup(SETUP_ID)
.get('/repositories', { query: { since: 364 } })
# POST Call with OAuth
bearer.integration('github')
.auth(authId)
.post('/user/repos', { body: { name: 'Just setting up my Bearer.sh' } })

Receiving Webhooks

Rails
# in app/webhooks/my_handler.rb
class MyHandler
include BearerRails::Webhook
integration_handler "github"
def call
consume_webhook_service(body)
end
end

Check-out the source of the Ruby & Rails clients.