A Ruby wrapper for the bit.ly API
A Ruby gem for using the version 4 Bitly API to shorten links, expand short links and view metrics across users, links and organizations.
Add this line to your application's Gemfile:
gem 'bitly'And then execute:
$ bundle installOr install it yourself as:
$ gem install bitlyFor a quick introduction, read this blog post on how to use the Bitly API in Ruby.
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.
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
With an authenticated client you can shorten a link like so:
bitlink = client.shorten(long_url: "http://example.com")
bitlink.link
# => http://bit.ly/2OUJim0With an authorised you can expand any Bitlink.
bitlink = client.expand(bitlink: "bit.ly/2OUJim0")
bitlink.long_url
# => http://example.comThis gem supports the following active v4 API endpoints for theBitly API.
GET /v4/groups)GET /v4/groups/{group_guid})PATCH /v4/groups/{group_guid})GET /v4/groups/{group_guid}/tags)GET /v4/groups/{group_guid}/preferences)PATCH /v4/groups/{group_guid}/preferences)GET /v4/groups/{group_guid}/bitlinks)GET /v4/groups/{group_guid}/bitlinks/{sort})GET /v4/groups/{group_guid}/shorten_counts)GET /v4/groups/{group_guid}/referring_networks)GET /v4/groups/{group_guid}/countries)GET /v4/groups/{group_guid}/qr-codes)GET /v4/groups/{group_guid}/cities)GET /v4/groups/{group_guid}/overrides)GET /v4/organizations)GET /v4/organizations/{organization_guid})GET /v4/organizations/{organization_guid}/shorten_counts)POST /v4/shorten)POST /v4/expand)GET /v4/bitlinks/{bitlink})POST /v4/bitlinks)PATCH /v4/bitlinks/{bitlink})DELETE /v4/bitlinks/{bitlink})GET /v4/bitlinks/{bitlink}/clicks)GET /v4/bitlinks/{bitlink}/clicks/summary)GET /v4/bitlinks/{bitlink}/countries)GET /v4/bitlinks/{bitlink}/referrers)GET /v4/bitlinks/{bitlink}/referring_domains)GET /v4/bitlinks/{bitlink}/referrers_by_domains)GET /v4/bitlinks/{bitlink}/cities)GET /v4/bitlinks/{bitlink}/devices)GET /v4/qr-codes/{qrcode_id})GET /v4/qr-codes/{qrcode_id}/scans/summary)GET /v4/qr-codes/{qrcode_id}/image)POST /v4/custom_bitlinks)GET /v4/custom_bitlinks/{custom_bitlink})PATCH /v4/custom_bitlinks/{custom_bitlink})GET /v4/custom_bitlinks/{custom_bitlink}/clicks_by_destination)GET /v4/custom_bitlinks/{custom_bitlink}/clicks)GET /v4/campaigns)POST /v4/campaigns)GET /v4/campaigns/{campaign_guid})PATCH /v4/campaigns/{campaign_guid})GET /v4/channels)POST /v4/channels)GET /v4/channels/{channel_guid})PATCH /v4/channels/{channel_guid})Branded Short Domains documentation
GET /v4/organizations/{organization_guid}/webhooks)POST /v4/webhooks)GET /v4/webhooks/{webhook_guid})POST /v4/webhooks/{webhook_guid)DELETE /v4/webhooks/{webhook_guid})POST /v4/webhooks/{webhook_guid}/verify)This gem comes with an HTTP client that can use different adapters. It ships with a Net::HTTP adapter that it uses by default.
If you want to control the connection, you can create your own instance of the Net::HTTP adapter and pass it options for an HTTP proxy or options that control the request. For example, to control the read_timeout you can do this:
adapter = Bitly::HTTP::Adapters::NetHTTP.new(request_options: { read_timeout: 1 })
http_client = Bitly::HTTP::Client.new(adapter)
api_client = Bitly::API::Client.new(http: http_client, token: token)Similarly, you can use an HTTP proxy with the adapter by passing the proxy variables to the adapter's constructor.
adapter = Bitly::HTTP::Adapters::NetHTTP.new(proxy_addr: "example.com", proxy_port: 80, proxy_user: "username", proxy_pass: "password")
http_client = Bitly::HTTP::Client.new(adapter)
api_client = Bitly::API::Client.new(http: http_client, token: token)If you want even more control over the request, you can build your own adapter. An HTTP adapter within this gem must have a request instance method that receives a Bitly::HTTP::Request object and ret
No open issues yet, or sync has not completed.