The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add quickstart guide for Rails and Sinatra framework
Kiran K99f3d4a68651
diff --git a/apps/docs/mint.json b/apps/docs/mint.jsonindex b821f39e30..7b5170bc11 100644--- a/apps/docs/mint.json+++ b/apps/docs/mint.json@@ -89,7 +89,7 @@{"group": "Ruby","icon": "gem",- "pages": ["quickstart/ruby"]+ "pages": ["quickstart/ruby", "quickstart/rails", "quickstart/sinatra"]}]},diff --git a/apps/docs/quickstart/rails.mdx b/apps/docs/quickstart/rails.mdxnew file mode 100644index 0000000000..423817ea93--- /dev/null+++ b/apps/docs/quickstart/rails.mdx@@ -0,0 +1,163 @@+---+title: "Ruby on Rails"+description: "Learn how to create a short link using Ruby on Rails and the Dub Ruby SDK."+---++import Prerequisites from "/snippets/sdk-prerequisites.mdx";+import LinkArguments from "/snippets/link-arguments.mdx";++<Prerequisites />++## 2. Install and initialize the Dub Ruby SDK++<Steps titleSize="h3">++<Step title="Install">++To install the [Dub Ruby SDK](https://d.to/ruby), run the following command:++```bash bash+gem install dub+```++</Step>++<Step title="Initialize">++Initialize the Dub Ruby SDK by creating a new instance of the `Dub` struct.++```ruby+class LinksController < ApplicationController+ require 'dub'++ before_action :initialize_dub++ # Make sure to set the DUB_API_KEY in your environment++ def initialize_dub+ @dub = ::OpenApiSDK::Dub.new+ @dub.config_security(+ ::OpenApiSDK::Shared::Security.new(+ token: ENV['DUB_API_KEY']+ )+ )+ end+end+```++</Step>++</Steps>++## 3. Create link++Let's create a short link using the [Dub Ruby SDK](https://d.to/ruby).++```ruby links_controller.rb+def create+ req = ::OpenApiSDK::Operations::CreateLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new(+ url: 'https://google.com'+ )+ )++ res = @dub.links.create(req)++ render json: res.raw_response.body+end+```++<Accordion title="Full list of available attributes for the Link model">+ <LinkArguments />+</Accordion>++## 3a. Create link with `externalId`++Optionally, you can also pass an `externalId` field which is a unique identifier for the link in your own database to associate it with the link in Dub's system.++```ruby links_controller.rb+def create+ req = ::OpenApiSDK::Operations::CreateLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new(+ url: 'https://google.com',+ external_id: '12345'+ )+ )++ res = @dub.links.create(req)++ render json: res.raw_response.body+end+```++## 4. Upsert link++Dub Ruby SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.++```ruby links_controller.rb+def upsert+ req = ::OpenApiSDK::Operations::UpsertLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::UpsertLinkRequestBody.new(+ url: "https://google.com",+ ),+ )++ res = @dub.links.upsert(req)++ render json: res.raw_response.body+end+```++## 5. Update link++Let's update an existing link using the Dub Ruby SDK.++You can do that in two ways:++- Using the link's `linkId` in Dub's system.+- Using the link's `externalId` in your own database (prefixed with `ext_`).++```ruby links_controller.rb+def update+ req = ::OpenApiSDK::Operations::UpdateLinkRequest.new(+ link_id: 'clx1gvi9o0005hf5momm6f7hj',+ request_body: ::OpenApiSDK::Operations::UpdateLinkRequestBody.new(+ url: 'https://google.uk'+ )+ )++ res = @dub.links.update(req)++ render json: res.raw_response.body+end+```++## 6. Retrieve analytics for link++Let's retrieve analytics for a link using the Dub Ruby SDK.++```ruby index.rb+def analytics+ req = ::OpenApiSDK::Operations::RetrieveAnalyticsRequest.new(+ link_id: "clx1gvi9o0005hf5momm6f7hj",+ interval: ::OpenApiSDK::Operations::Interval::SEVEND,+ group_by: ::OpenApiSDK::Operations::GroupBy::TIMESERIES+ )++ res = @dub.analytics.retrieve(req)++ render json: res.raw_response.body+end+```++## 7. Examples++<CardGroup cols={2}>+ <Card+ title="Rails Example"+ icon="arrow-up-right-from-square"+ href="https://github.com/dubinc/examples/tree/main/ruby/rails/example"+ >+ See the full example on GitHub.+ </Card>+</CardGroup>diff --git a/apps/docs/quickstart/ruby.mdx b/apps/docs/quickstart/ruby.mdxindex 1bf7476868..2cd83d536a 100644--- a/apps/docs/quickstart/ruby.mdx+++ b/apps/docs/quickstart/ruby.mdx@@ -26,14 +26,14 @@ gem install dubInitialize the Dub Ruby SDK by creating a new instance of the `Dub` struct.-```go+```rubyrequire 'dub's = ::OpenApiSDK::Dub.news.config_security(::OpenApiSDK::Shared::Security.new(- token: "<DUB_API_KEY>",+ token: ENV['DUB_API_KEY'], # Use your Dub API key))```diff --git a/apps/docs/quickstart/sinatra.mdx b/apps/docs/quickstart/sinatra.mdxnew file mode 100644index 0000000000..4eacb4b02a--- /dev/null+++ b/apps/docs/quickstart/sinatra.mdx@@ -0,0 +1,162 @@+---+title: "Sinatra"+description: "Learn how to create a short link using Sinatra and the Dub Ruby SDK."+---++import Prerequisites from "/snippets/sdk-prerequisites.mdx";+import LinkArguments from "/snippets/link-arguments.mdx";++<Prerequisites />++## 2. Install and initialize the Dub Ruby SDK++<Steps titleSize="h3">++<Step title="Install">++To install the [Dub Ruby SDK](https://d.to/ruby), run the following command:++```bash bash+gem install dub+```++</Step>++<Step title="Initialize">++Initialize the Dub Ruby SDK by creating a new instance of the `Dub` struct.++```ruby+require 'dub'++before do+ $dub = ::OpenApiSDK::Dub.new+ $dub.config_security(+ ::OpenApiSDK::Shared::Security.new(+ token: ENV['DUB_API_KEY'] # Use your Dub API key+ )+ )+end+```++</Step>++</Steps>++## 3. Create link++Let's create a short link using the [Dub Ruby SDK](https://d.to/ruby).++```ruby index.rb+post "/links" do+ req = ::OpenApiSDK::Operations::CreateLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new(+ url: 'https://google.com'+ )+ )++ res = $dub.links.create(req)++ content_type :json+ res.raw_response.body+end+```++<Accordion title="Full list of available attributes for the Link model">+ <LinkArguments />+</Accordion>++## 3a. Create link with `externalId`++Optionally, you can also pass an `externalId` field which is a unique identifier for the link in your own database to associate it with the link in Dub's system.++```ruby index.rb+post "/links" do+ req = ::OpenApiSDK::Operations::CreateLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new(+ url: 'https://google.com',+ external_id: '12345'+ )+ )++ res = $dub.links.create(req)++ content_type :json+ res.raw_response.body+end+```++## 4. Upsert link++Dub Ruby SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.++```ruby index.rb+put "/links" do+ req = ::OpenApiSDK::Operations::UpsertLinkRequest.new(+ request_body: ::OpenApiSDK::Operations::UpsertLinkRequestBody.new(+ url: "https://google.com",+ ),+ )++ res = $dub.links.upsert(req)++ content_type :json+ res.raw_response.body+end+```++## 5. Update link++Let's update an existing link using the Dub Ruby SDK.++You can do that in two ways:++- Using the link's `linkId` in Dub's system.+- Using the link's `externalId` in your own database (prefixed with `ext_`).++```ruby index.rb+patch "/links" do+ req = ::OpenApiSDK::Operations::UpdateLinkRequest.new(+ link_id: "clyci5h0w000511sjmu0tyjv9",+ request_body: ::OpenApiSDK::Operations::UpdateLinkRequestBody.new(+ url: 'https://google.uk'+ )+ )++ res = $dub.links.update(req)++ content_type :json+ res.raw_response.body+end+```++## 6. Retrieve analytics for link++Let's retrieve analytics for a link using the Dub Ruby SDK.++```ruby index.rb+get "/analytics" do+ req = ::OpenApiSDK::Operations::RetrieveAnalyticsRequest.new(+ link_id: "clx1gvi9o0005hf5momm6f7hj",+ interval: ::OpenApiSDK::Operations::Interval::SEVEND,+ group_by: ::OpenApiSDK::Operations::GroupBy::TIMESERIES+ )++ res = $dub.analytics.retrieve(req)++ content_type :json+ res.raw_response.body+end+```++## 7. Examples++<CardGroup cols={2}>+ <Card+ title="Sinatra Example"+ icon="arrow-up-right-from-square"+ href="https://github.com/dubinc/examples/tree/main/ruby/sinatra"+ >+ See the full example on GitHub.+ </Card>+</CardGroup>\ No newline at end of file