bitly

philnashMIT更新放缓

Ruby 封装的 bit.ly API 客户端,用来在 Ruby 项目里方便地生成短链接、管理 bit.ly 短链资源,省去自己拼 HTTP 请求的麻烦。

🗜 A Ruby wrapper for the bit.ly API

v2.0.0.beta.1发布于 2020-02-15 04:02 UTC448star135fork同步于 2026-11-07 07:32 UTC

怎么上手

由 README 提炼,执行前请确认
gem 'bitly'
bundle install
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Ruby 封装的 Bitly v4 API 客户端,用来在 Ruby 项目里缩短、展开短链并查询点击指标

Ruby 封装的 bit.ly API 客户端,用来在 Ruby 项目里方便地生成短链接、管理 bit.ly 短链资源,省去自己拼 HTTP 请求的麻烦。

核心能力

  • 封装 Bitly v4 的 shorten 与 expand 接口
  • 覆盖 Groups、Organizations、Users、Bitlinks 等端点
  • 支持查询短链点击量与按国家、来源的指标
  • 可自定义 HTTP 请求适配器替换默认实现
  • 通过 OAuth token 初始化 Bitly::API::Client

容易踩的坑

所有接口都需要先在 Bitly 控制台生成 OAuth token;部分端点(如按城市统计、group overrides)标注为 premium 且未实现;删除 Bitlink 的接口尚未支持

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本v2.0.0.beta.1
  1. v2.0.0.beta.1Version 2 beta 1pre-release最新正式版2020-02-15 · 2020-02-15 04:02 UTC

    It's been a long time coming, but this gem has had a full overhaul and now supports the Bitly API version 4.

    Please see the README for the latest documentation on installation and usage.

    Please test and send any feedback as issues. Thank you.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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.

    Gem version Build status Maintainability Maintainability Rating Inline docs

    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

    Groups documentation

    Organizations

    Organizations documentation

    Users

    Users documentation

    Bitlinks

    Bitlinks documentation

    QR codes

    QR codes documentation

    Custom Bitlinks

    Campaigns

    BSDs (Branded Short Domains)

    Branded Short Domains documentation

    Webhooks

    Customising HTTP requests

    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)
    

    Build your own adapter

    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 returns an array of four objects:

    1. The response status code
    2. The body of the response as a string
    3. The response headers as a hash
    4. A boolean denoting whether the response was a success or not

    See ./src/bitly/http/adapters/net_http.rb for an example.

    Development

    After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

    To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

    Contributing

    Bug reports and pull requests are welcome on GitHub at https://github.com/philnash/bitly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

    License

    The gem is available as open source under the terms of the MIT License.

    Code of Conduct

    Everyone interacting in the Bitly project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.