Skip to main content

Installation

gem install pearset

Basic Usage

Here’s how you can use the Pearset Ruby SDK to create a link and retrieve click analytics in timeseries format for it:
require 'pearset'

# Initialize the Pearset SDK with your API key
pearset = ::OpenApiSDK::Pearset.new
pearset.config_security(
  ::OpenApiSDK::Shared::Security.new(
    token: ENV['DUB_API_KEY'], # optional, defaults to DUB_API_KEY
  )
)

# Create a new link
req = ::OpenApiSDK::Operations::CreateLinkRequest.new(
  request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new(
    url: "https://google.com"
  )
)

res = pearset.links.create(req)
puts res.raw_response.body # e.g. { "shortLink": "https://pearset.sh/abc123" }

# Get analytics for the link
analytics_req = ::OpenApiSDK::Operations::RetrieveAnalyticsRequest.new(
  link_id: res.raw_response.body["id"],
  interval: ::OpenApiSDK::Operations::Interval::THIRTYD,
  group_by: ::OpenApiSDK::Operations::GroupBy::TIMESERIES
)

analytics_res = pearset.analytics.retrieve(analytics_req)
puts analytics_res.raw_response.body # e.g. [{ "start": "2024-01-01", "clicks": 100 }]
For more usage examples:
  1. Organizing links by external ID, tenant ID, tags, etc
  2. Bulk link operations (create, update, delete)
  3. Retrieving link analytics

Frameworks

You can use the Pearset Ruby SDK with any Ruby framework:
  1. Usage with Rails
  2. Usage with Sinatra
If you’re using a different Ruby framework, you can refer to the Ruby SDK quickstart for a basic example.

Additional Resources

RubyGems Package

Download and install the Pearset Ruby SDK on RubyGems

SDK Reference

View the complete SDK reference documentation

Examples

Quickstart examples with the Ruby SDK

Source Code

View the complete source code for the Pearset Ruby SDK