Bitly Exporter
This gem exports a user's links from the Bitly V3 API. It requires a generic OAuth access token that you can obtain from Bitly. It makes use of the User Link History API.
Installation
Add this line to your applications Gemfile:
gem 'bitly_exporter'
Or install it directly:
gem install bitly_exporter
Usage
First, create a user and an exporter:
user = BitlyExporter::User.new('youroauthaccesstoken')
exporter = BitlyExporter::Exporter.new(user)
The export
method triggers the export. There are two ways to consume the results.
Using a block:
exporter.export do |link|
# Create a record, store the link, etc
end
As a traditional method:
results = exporter.export
results.each_with_index do |link, index|
puts "Link Index: #{index}, Link: #{link.link}"
end
export
takes two optional arguments: progress
& max
. Set progress
to true
to see progress while exporting. Setting max
will import (in increments of 100) up to the maximum specified. This is a good way to see a sample response.
Show progress:
results = exporter.export(true)
With max:
exporter.export(false, 200) do |link|
# Create a record, store the link, etc
end
Link Objects
See the API docs for more information. A link object has the following methods:
- link (short_link)
- long_url
- aggregate_link (global_bitly_identifier)
- archived
- title
- private
- client_id
- created_at
- modified_at
- user_ts
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Write Tests
- Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
This code is provided under the MIT license. See LICENSE for more details.