An open API service indexing awesome lists of open source software.

https://github.com/dewski/cached_bitly

An easy Bitly toolkit with Redis being the caching layer.
https://github.com/dewski/cached_bitly

Last synced: about 1 year ago
JSON representation

An easy Bitly toolkit with Redis being the caching layer.

Awesome Lists containing this project

README

          

CachedBitly [![Build Status](https://secure.travis-ci.org/dewski/cached_bitly.png)](http://travis-ci.org/dewski/cached_bitly)
===========

An easy bit.ly toolkit with Redis as a caching layer.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'cached_bitly'
```

And then execute:

```
$ bundle
```

Or install it yourself as:

```
$ gem install cached_bitly
```

## Usage

To communicate with bit.ly you'll need your login and API key which you can get from the [Advanced tab](https://bitly.com/a/settings/advanced) within your account settings.

If you set the bit.ly environment variables everything will just work:

```
BITLY_LOGIN=dewski
BITLY_API_KEY=Z_bf4b4fg16991dd72d276e7z9d94d1bc00b
```

You may also set the bit.ly client directly with your own configuration:

```ruby
CachedBitly.bitly_client = Bitly.new('username', 'password')
```

There are 2 main methods to interface with bit.ly, the first being a way to retreive already generated URLs:

```ruby
# First lookup will generate the URL from bit.ly
CachedBitly.fetch('https://github.com') # => http://bit.ly/WuNWHc

# Hits redis with no additional HTTP request
CachedBitly.fetch('https://github.com') # => http://bit.ly/WuNWHc
```

If you'd like to just pass in a large block of HTML you can cache multiple links at once:

```ruby
content = "GitHub and @dewski join forces"
CachedBitly.clean(content) # => "GitHub and @dewski join forces"
```

## Configuring CachedBitly

If you don't want to shorten all links within your HTML you can bypass bit.ly by setting your allowed hostnames:

```ruby
CachedBitly.allowed_hostnames = ['github.com']
content = "GitHub and Garrett join forces"
CachedBitly.clean(content) # => "GitHub and @dewski join forces"
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request