forked from igrigorik/em-synchrony
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now using EventMachine::HttpRequest for request.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |