Skip to content

Commit

Permalink
Added Bitly patch.
Browse files Browse the repository at this point in the history
Now using EventMachine::HttpRequest for request.
  • Loading branch information
mccoder committed Apr 23, 2010
1 parent 7470e82 commit 4f24fed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ begin
gemspec.authors = ["Ilya Grigorik"]
gemspec.required_ruby_version = ">= 1.9"
gemspec.add_dependency("eventmachine", ">= 0.12.9")
gemspec.add_dependency("bitly", "= 0.4.0")
gemspec.add_dependency("em-http-request")
gemspec.add_dependency("em-mysqlplus")
gemspec.add_dependency("em-jack")
Expand Down
27 changes: 27 additions & 0 deletions lib/em-synchrony/em-bitly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'bitly'
require 'eventmachine'
require 'fiber'
require 'em-synchrony/em-http'

module Bitly
module Utils
#Be Aware suported only version Bitly-0.4.0.
#In next version (in branch) of Bitly library interface changed.
def get_result(request)
http = EventMachine::HttpRequest.new(request).get(:timeout => 100)

result = if(http.response_header.status == 200)
Crack::JSON.parse(http.response)
else
{'errorMessage' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69, 'statusCode' => 'ERROR'}
end

if 'OK'==result['statusCode']
result['results']
else
raise BitlyError.new(result['errorMessage'],result['errorCode'])
end
end

end
end

0 comments on commit 4f24fed

Please sign in to comment.