Ruby on Rails
Integrate Repull into a Rails application.
1
Prerequisites
Ruby 3.0+ installed on your machine.
You also need a Repull API key. Get one from your dashboard.
2
Install
gem 'repull'
3
Set up environment variables
Add your credentials to a .env file in your project root:
REPULL_API_KEY=sk_live_YOUR_KEY
There is one key type — sk_live_ — created from /dashboard/keys. It acts on whatever channels your workspace has connected.
4
Make your first API call
Configure the client with your API key, then call any endpoint. The example below lists properties and fetches reservations.
# config/initializers/repull.rb
require 'repull'
config = Repull::Configuration.new
config.access_token = ENV.fetch('REPULL_API_KEY')
config.host = 'api.repull.dev'
REPULL = Repull::ApiClient.new(config)
# app/controllers/reservations_controller.rb
class ReservationsController < ApplicationController
# How do I list reservations in Rails?
def index
opts = { status: params[:status], platform: params[:platform] }.compact
result = Repull::ReservationsApi.new(REPULL).list_reservations(opts)
render json: result
end
# How do I get Airbnb reservations in Rails?
def airbnb
result = Repull::ReservationsApi.new(REPULL).list_reservations(platform: 'airbnb')
render json: result
end
# How do I update availability in Rails? Pushes to every connected channel.
def update_availability
result = Repull::AvailabilityApi.new(REPULL).update_availability(
params[:property_id].to_i,
Repull::AvailabilityWriteRequest.new(
dates: params[:dates].map { |d| Date.parse(d) },
price: params[:price].to_f
)
)
render json: result
end
end
# config/routes.rb
Rails.application.routes.draw do
resources :reservations, only: [:index]
get 'reservations/airbnb', to: 'reservations#airbnb'
put 'properties/:property_id/availability', to: 'reservations#update_availability'
end5
Next steps
You are all set. Explore the rest of the platform:
AI