Learn more about the Dub.co Ruby SDK in the official documentation.
Dub.co API: Dub is link management infrastructure for companies to create marketing campaigns, link sharing features, and referral programs.
- SDK Installation
- SDK Example Usage
- Authentication
- Available Resources and Operations
- Error Handling
- Server Selection
- Development
The SDK can be installed using RubyGems:
gem install dub
require 'dub'
s = ::OpenApiSDK::Dub.new(
security: ::OpenApiSDK::Shared::Security.new(
token: "DUB_API_KEY",
),
)
req = ::OpenApiSDK::Operations::CreateLinkRequestBody.new(
url: "https://google.com",
external_id: "123456",
tag_ids: [
"clux0rgak00011...",
],
test_variants: [
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-1",
percentage: 50.0,
),
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-2",
percentage: 50.0,
),
],
)
res = s.links.create(req)
if ! res.link_schema.nil?
# handle response
end
require 'dub'
s = ::OpenApiSDK::Dub.new(
security: ::OpenApiSDK::Shared::Security.new(
token: "DUB_API_KEY",
),
)
req = ::OpenApiSDK::Operations::UpsertLinkRequestBody.new(
url: "https://google.com",
external_id: "123456",
tag_ids: [
"clux0rgak00011...",
],
test_variants: [
::OpenApiSDK::Operations::UpsertLinkTestVariants.new(
url: "https://example.com/variant-1",
percentage: 50.0,
),
::OpenApiSDK::Operations::UpsertLinkTestVariants.new(
url: "https://example.com/variant-2",
percentage: 50.0,
),
],
)
res = s.links.upsert(req)
if ! res.link_schema.nil?
# handle response
end
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
token |
http | HTTP Bearer |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. For example:
require 'dub'
s = ::OpenApiSDK::Dub.new(
security: ::OpenApiSDK::Shared::Security.new(
token: "DUB_API_KEY",
),
)
req = ::OpenApiSDK::Operations::CreateLinkRequestBody.new(
url: "https://google.com",
external_id: "123456",
tag_ids: [
"clux0rgak00011...",
],
test_variants: [
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-1",
percentage: 50.0,
),
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-2",
percentage: 50.0,
),
],
)
res = s.links.create(req)
if ! res.link_schema.nil?
# handle response
end
Available methods
- retrieve - Retrieve analytics for a link, a domain, or the authenticated workspace.
- list - Retrieve a list of customers
create- Create a customer⚠️ Deprecated- get - Retrieve a customer
- update - Update a customer
- delete - Delete a customer
- create - Create a domain
- list - Retrieve a list of domains
- update - Update a domain
- delete - Delete a domain
- referrals - Create a new referrals embed token
- list - Retrieve a list of events
- create - Create a new folder
- list - Retrieve a list of folders
- update - Update a folder
- delete - Delete a folder
- create - Create a new link
- list - Retrieve a list of links
- count - Retrieve links count
- get - Retrieve a link
- update - Update a link
- delete - Delete a link
- create_many - Bulk create links
- update_many - Bulk update links
- delete_many - Bulk delete links
- upsert - Upsert a link
- create - Create a new partner
- create_link - Create a link for a partner
- retrieve_links - Retrieve a partner's links.
- upsert_link - Upsert a link for a partner
- analytics - Retrieve analytics for a partner
- update_sale - Update a sale for a partner.
- get - Retrieve a QR code
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error.
By default an API error will raise a Errors::APIError
, which has the following properties:
Property | Type | Description |
---|---|---|
message |
string | The error message |
status_code |
int | The HTTP status code |
raw_response |
Faraday::Response | The raw HTTP response |
body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the create
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Models::Errors::BadRequest | 400 | application/json |
Models::Errors::Unauthorized | 401 | application/json |
Models::Errors::Forbidden | 403 | application/json |
Models::Errors::NotFound | 404 | application/json |
Models::Errors::Conflict | 409 | application/json |
Models::Errors::InviteExpired | 410 | application/json |
Models::Errors::UnprocessableEntity | 422 | application/json |
Models::Errors::RateLimitExceeded | 429 | application/json |
Models::Errors::InternalServerError | 500 | application/json |
Errors::APIError | 4XX, 5XX | */* |
require 'dub'
s = ::OpenApiSDK::Dub.new(
security: Models::Shared::Security.new(
token: "DUB_API_KEY",
),
)
begin
req = Models::Operations::CreateLinkRequestBody.new(
url: "https://google.com",
external_id: "123456",
tag_ids: [
"clux0rgak00011...",
],
test_variants: [
Models::Operations::TestVariants.new(
url: "https://example.com/variant-1",
percentage: 50.0,
),
Models::Operations::TestVariants.new(
url: "https://example.com/variant-2",
percentage: 50.0,
),
],
)
res = s.links.create(req)
if ! res.link_schema.nil?
# handle response
end
rescue Models::Errors::BadRequest => e
# handle $e->$container data
throw $e;
rescue Models::Errors::Unauthorized => e
# handle $e->$container data
throw $e;
rescue Models::Errors::Forbidden => e
# handle $e->$container data
throw $e;
rescue Models::Errors::NotFound => e
# handle $e->$container data
throw $e;
rescue Models::Errors::Conflict => e
# handle $e->$container data
throw $e;
rescue Models::Errors::InviteExpired => e
# handle $e->$container data
throw $e;
rescue Models::Errors::UnprocessableEntity => e
# handle $e->$container data
throw $e;
rescue Models::Errors::RateLimitExceeded => e
# handle $e->$container data
throw $e;
rescue Models::Errors::InternalServerError => e
# handle $e->$container data
throw $e;
rescue Errors::APIError => e
# handle default exception
raise e
end
The default server can be overridden globally by passing a URL to the server_url (String)
optional parameter when initializing the SDK client instance. For example:
require 'dub'
s = ::OpenApiSDK::Dub.new(
server_url: "https://api.dub.co",
security: ::OpenApiSDK::Shared::Security.new(
token: "DUB_API_KEY",
),
)
req = ::OpenApiSDK::Operations::CreateLinkRequestBody.new(
url: "https://google.com",
external_id: "123456",
tag_ids: [
"clux0rgak00011...",
],
test_variants: [
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-1",
percentage: 50.0,
),
::OpenApiSDK::Operations::TestVariants.new(
url: "https://example.com/variant-2",
percentage: 50.0,
),
],
)
res = s.links.create(req)
if ! res.link_schema.nil?
# handle response
end
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!