-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring of the google api call into ApiCall module
- Loading branch information
Elise Huard
committed
Jan 23, 2009
1 parent
1feb4f5
commit 0d238cf
Showing
6 changed files
with
34 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
:minor: 0 | ||
:patch: 2 | ||
:patch: 3 | ||
:major: 0 |
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,22 @@ | ||
module GoogleTranslate | ||
module ApiCall | ||
def google_api_call(text,params,klas) | ||
raise NoGivenString if text.nil? | ||
|
||
request = URL_STRING + params + CGI.escape(text) | ||
response = '' | ||
open(request) { |f| | ||
response = f.read | ||
} | ||
raise GoogleUnavailable if response.nil? || response == "" | ||
|
||
parsed_response = klas.new(response) | ||
raise GoogleException, parsed_response.details if parsed_response.status != 200 # success | ||
|
||
parsed_response # return response class | ||
|
||
rescue OpenURI::HTTPError | ||
raise GoogleUnavailable | ||
end | ||
end | ||
end |
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
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