Installation

gem install codeqr

Basic Usage

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

require 'codeqr'

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

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

res = codeqr.links.create(req)
puts res.raw_response.body # e.g. { "shortLink": "https://codeqr.link/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 = codeqr.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 CodeQR 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