Last active
October 13, 2015 23:08
-
-
Save szabcsee/4270782 to your computer and use it in GitHub Desktop.
GoogleFish Ruby gem usage, how it works with Sinatra
This file contains hidden or 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
get '/translate' do | |
doc = open(params[:url]) { |f| Hpricot (f) } | |
doc.search("//iframe").remove | |
doc.search("//script").remove | |
doc.search("//.headline_meta").remove | |
doc.search("//frameset").remove | |
article = (doc/".post").inner_html | |
google = GoogleFish.new('YOUR-API-KEY') | |
@result = google.translate( params[:language_from], params[:language_to], 'Good night, sleep tight') | |
erb :translated | |
end |
I Have same error!
I tried to run it from irb and got these errors:
GoogleFish::Request::ApiError: GoogleFish::Request::ApiError
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:61:in get' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:34:inperform_translation'
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:19:in request_translation' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:12:intranslate'
from (irb):16
from /Users/szabcsee/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `'
1.9.3-p194 :017 >
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to run it from irb and got these errors:
GoogleFish::Request::ApiError: GoogleFish::Request::ApiError
'from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:61:in
get' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:34:in
perform_translation'from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:19:in
request_translation' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:12:in
translate'from (irb):16
from /Users/szabcsee/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `
1.9.3-p194 :017 >