I'm planning on using Bit.ly Pro and the Bit.ly API to make my own short urls in a Rails 3 project.
I've got a User and a Note model. And a url structure like this: '/username/1-note-title'.
Now I would like to give each note a short url. But I don't know from where I should do the API call. Right now I got this code in the Note controller but I don't know if that's the right place or how to get the url of the specific note...
url = ???
parsed_json = JSON('http://api.bit.ly/v3/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&longUrl=' + url + '&format=json')
@short_url = parsed_json["data"]["url"]
The JSON object structure just for reference:
{
"status_code": 200,
"data": {
"url": "http://bit.ly/cmeH01",
"hash": "cmeH01",
"global_hash": "1YKMfY",
"long_url": "http://betaworks.com/",
"new_hash": 0
},
"status_txt": "OK"
}
Help wanted, thanks in advance!