Skip to content

Latest commit

 

History

History
408 lines (320 loc) · 12.5 KB

README.md

File metadata and controls

408 lines (320 loc) · 12.5 KB
Dub.co Ruby SDK to interact with APIs.

Dub.co Ruby SDK


Learn more about the Dub.co Ruby SDK in the official documentation.

Summary

Dub.co API: Dub is link management infrastructure for companies to create marketing campaigns, link sharing features, and referral programs.

Table of Contents

SDK Installation

The SDK can be installed using RubyGems:

gem install dub

SDK Example Usage

Example 1

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

Example 2

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

Authentication

Per-Client Security Schemes

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 Resources and Operations

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
  • get - Retrieve a QR code
  • lead - Track a lead
  • sale - Track a sale
  • get - Retrieve a workspace
  • update - Update a workspace

Error Handling

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 */*

Example

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

Server Selection

Override Server URL Per-Client

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

Development

Contributions

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!

SDK Created by Speakeasy