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.
- Host: GitHub
- URL: https://github.com/dewski/cached_bitly
- Owner: dewski
- License: mit
- Created: 2012-11-20T19:47:44.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-06-06T18:31:21.000Z (almost 13 years ago)
- Last Synced: 2024-04-26T19:21:59.736Z (almost 2 years ago)
- Language: Ruby
- Homepage:
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
CachedBitly [](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