Bitly
🗜 A Ruby wrapper for the bit.ly API
Install / Use
/learn @philnash/BitlyREADME
Bitly
A Ruby gem for using the version 4 Bitly API to shorten links, expand short links and view metrics across users, links and organizations.
- Bitly
Installation
Add this line to your application's Gemfile:
gem 'bitly'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install bitly
Usage
For a quick introduction, read this blog post on how to use the Bitly API in Ruby.
Authentication
All API endpoints require authentication with an OAuth token. You can get your own OAuth token from the Bitly console. Click on the account drop down menu, then Profile Settings then Generic Access Token. Fill in your password and you can generate an OAuth access token.
For other methods to generate access tokens for users via OAuth flows, see the Authentication documentation.
Once you have an access token you can use all the API methods.
Creating an API client
All API methods are available through the Bitly::API::Client. Initialise the client with the access token like so:
client = Bitly::API::Client.new(token: token)
You can then use the client to perform actions with the API
Shorten a link
With an authenticated client you can shorten a link like so:
bitlink = client.shorten(long_url: "http://example.com")
bitlink.link
# => http://bit.ly/2OUJim0
Expand a link
With an authorised you can expand any Bitlink.
bitlink = client.expand(bitlink: "bit.ly/2OUJim0")
bitlink.long_url
# => http://example.com
Available API Endpoints
This gem supports the following active v4 API endpoints for theBitly API.
Groups
- [x] Retrieve groups (
GET /v4/groups) - [x] Retrieve group (
GET /v4/groups/{group_guid}) - [x] Update group (
PATCH /v4/groups/{group_guid}) - [x] Retrieve tags by group (
GET /v4/groups/{group_guid}/tags) - [x] Retrieve group preferences (
GET /v4/groups/{group_guid}/preferences) - [x] Update group preferences (
PATCH /v4/groups/{group_guid}/preferences) - [x] Retrieve Bitlinks by group (
GET /v4/groups/{group_guid}/bitlinks) - [x] Retrieve sorted Bitlinks by group (
GET /v4/groups/{group_guid}/bitlinks/{sort}) - [x] Retrieve group shorten counts (
GET /v4/groups/{group_guid}/shorten_counts) - [x] Retrieve click metrics for a group by referring networks (
GET /v4/groups/{group_guid}/referring_networks) - [x] Retrieve click metrics for a group by countries (
GET /v4/groups/{group_guid}/countries) - [X] Retrieve QR codes for a group (
GET /v4/groups/{group_guid}/qr-codes) - [ ] [premium] Retrieve click metrics for a group by city (
GET /v4/groups/{group_guid}/cities) - [ ] [premium] Get group overrides (
GET /v4/groups/{group_guid}/overrides)
Organizations
- [x] Retrieve organizations (
GET /v4/organizations) - [x] Retrieve organization (
GET /v4/organizations/{organization_guid}) - [x] Retrieve organization shorten counts (
GET /v4/organizations/{organization_guid}/shorten_counts)
Users
Bitlinks
- [x] Shorten a link (
POST /v4/shorten) - [x] Expand a Bitlink (
POST /v4/expand) - [x] Retrieve a Bitlink (
GET /v4/bitlinks/{bitlink}) - [x] Create a Bitlink (
POST /v4/bitlinks) - [x] Update a Bitlink (
PATCH /v4/bitlinks/{bitlink}) - [ ] Delete an unedited hash Bitlink (
DELETE /v4/bitlinks/{bitlink}) - [x] Get clicks for a Bitlink (
GET /v4/bitlinks/{bitlink}/clicks) - [x] Get clicks summary for a Bitlink (
GET /v4/bitlinks/{bitlink}/clicks/summary) - [x] Get metrics for a Bitlink by countries (
GET /v4/bitlinks/{bitlink}/countries) - [x] Get metrics for a Bitlink by referrers (
GET /v4/bitlinks/{bitlink}/referrers) - [x] Get metrics for a Bitlink by referring domains (
GET /v4/bitlinks/{bitlink}/referring_domains) - [x] Get metrics for a Bitlink by referrers by domain (
GET /v4/bitlinks/{bitlink}/referrers_by_domains) - [ ] [premium] Get metrics for a Bitlink by city (
GET /v4/bitlinks/{bitlink}/cities) - [ ] [premium] Get metrics for a Bitlink by device type (
GET /v4/bitlinks/{bitlink}/devices)
QR codes
- [x] Retrieve a QR code (
GET /v4/qr-codes/{qrcode_id}) - [x] Retrieve the scans summary for a QR code (
GET /v4/qr-codes/{qrcode_id}/scans/summary) - [x] Retrieve a QR code image (
GET /v4/qr-codes/{qrcode_id}/image)
Custom Bitlinks
- [ ] Add custom Bitlink (
POST /v4/custom_bitlinks) - [ ] [premium] Retrieve custom Bitlink (
GET /v4/custom_bitlinks/{custom_bitlink}) - [ ] [premium] Update custom Bitlink (
PATCH /v4/custom_bitlinks/{custom_bitlink}) - [ ] [premium] Get metrics for a custom Bitlink by destination (
GET /v4/custom_bitlinks/{custom_bitlink}/clicks_by_destination) - [ ] [premium] Get clicks for a custom Bitlin's entire history (
GET /v4/custom_bitlinks/{custom_bitlink}/clicks)
Campaigns
- [ ] [premium] Retrieve campaigns (
GET /v4/campaigns) - [ ] [premium] Create campaign (
POST /v4/campaigns) - [ ] [premium] Retrieve campaign (
GET /v4/campaigns/{campaign_guid}) - [ ] [premium] Update campaign (
PATCH /v4/campaigns/{campaign_guid}) - [ ] [premium] Retrieve channels (
GET /v4/channels) - [ ] [premium] [Create channel (
POST /v4/channels)](https://dev.bitly.com/api-reference/#createChanne
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
