This is the official Convoy Ruby SDK. This SDK contains methods for easily interacting with Convoy's API. Below are examples to get you started. For the full API reference, please take a look at our docs.
Add this line to your application's Gemfile:
gem 'convoy.rb'And then execute:
$ bundle install
Or install it yourself as:
$ gem install convoy.rb
To configure your client, provide your base_uri, api_key and project_id, see below:
require 'convoy'
Convoy.ssl = true
Convoy.base_uri = "https://us.getconvoy.cloud/api"
Convoy.api_key = "CO.M0aBe..."
Convoy.project_id = "23b1..."Your instance URL depends on where your project lives:
- Convoy Cloud (US):
https://us.getconvoy.cloud/api - Convoy Cloud (EU):
https://eu.getconvoy.cloud/api - Self-hosted:
https://your-instance/api
An endpoint represents a target URL to receive webhook events. You should create one endpoint per user/business or whatever scope works well for you.
endpoint = Convoy::Endpoint.new(
data: {
"name": "default-endpoint",
"description": "Endpoint One",
"url": "https://example.com/webhooks/convoy"
}
)
endpoint_response = endpoint.saveAfter creating an endpoint, we need to susbcribe the endpoint to events.
subscription = Convoy::Subscription.new(
data: {
endpoint_id: endpoint_id,
name: 'ruby subscription'
}
)
subscription_response = subscription.saveTo send an event, you'll need to pass the uid from the endpoint we created earlier.
event = Convoy::Event.new(
data: {
endpoint_id: endpoint_id,
event_type: "wallet.created",
data: {
status: "completed",
event_type: "wallet.created",
description: "transaction successful"
}
}
)
event_response = event.saveTo fan an event out to all endpoints with the same owner_id, or broadcast to every endpoint in the project:
fanout_response = Convoy::Event.new(
data: {
owner_id: "owner-1",
event_type: "wallet.created",
data: { status: "completed" }
}
).fanout
broadcast_response = Convoy::Event.new(
data: {
event_type: "wallet.created",
data: { status: "completed" }
}
).broadcastVerify with the raw request body, before parsing it. verify returns true or false for simple signatures, and raises Convoy::SignatureVerificationError for invalid advanced signatures.
webhook = Convoy::Webhook.new("endpoint-secret")
begin
valid = webhook.verify(request.raw_post, request.headers["X-Convoy-Signature"])
rescue Convoy::SignatureVerificationError
valid = false
end
head :bad_request and return unless validAfter checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/convoy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The MIT License (MIT). Please see License File for more information.