Skip to content

Commit

Permalink
covering all api methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oleriesenberg committed Jul 8, 2009
1 parent d5547ad commit a335682
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
8 changes: 6 additions & 2 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
== 0.1.0 2009-07-07

* Covering all api methods


== 0.0.1 2009-07-05

* 1 major enhancement:
* Initial release
* Initial release
2 changes: 1 addition & 1 deletion lib/bitly-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
require 'bitly-api/bitly-api'

module BitlyApi
VERSION = '0.0.1'
VERSION = '0.1.0'
end
27 changes: 23 additions & 4 deletions lib/bitly-api/bitly-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,35 @@ def shorten(long_url)
http_response = open(build_url("shorten", "longUrl=#{long_url}")).read
data = JSON.parse(http_response)
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
results = data["results"][long_url]
results
data["results"][long_url]
end

def expand(short_url)
http_response = open(build_url("expand", "shortUrl=#{short_url}")).read
data = JSON.parse(http_response)
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
results = data["results"][short_url]
results
data["results"][short_url]
end

def info(short_url)
http_response = open(build_url("info", "shortUrl=#{short_url}")).read
data = JSON.parse(http_response)
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
data["results"][short_url.split(/\//)[-1]]
end

def stats(short_url)
http_response = open(build_url("stats", "shortUrl=#{short_url}")).read
data = JSON.parse(http_response)
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
data["results"]
end

def errors
http_response = open("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}").read
data = JSON.parse(http_response)
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
data["results"]
end

private
Expand Down

0 comments on commit a335682

Please sign in to comment.