Skip to content

Instantly share code, notes, and snippets.

@Arcolye
Last active January 26, 2017 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arcolye/0e3ba1b98cfd03de9016e84dceb6fe8d to your computer and use it in GitHub Desktop.
Save Arcolye/0e3ba1b98cfd03de9016e84dceb6fe8d to your computer and use it in GitHub Desktop.
GoToStudy - Gengo Translation API wrapper
# Gengo provides an API to their human translation service
# https://gengo.com/developers/
class GengoTranslation
require 'gengo'
attr_accessor :gengo
def initialize(sandbox: false)
sandbox = true unless Rails.env.production?
@gengo = Gengo::API.new({
public_key: sandbox ? ENV['GENGO_PUBLIC_KEY_SANDBOX'] : ENV['GENGO_PUBLIC_KEY'],
private_key: sandbox ? ENV['GENGO_PRIVATE_KEY_SANDBOX'] : ENV['GENGO_PRIVATE_KEY'],
sandbox: sandbox,
api_version: '2'
})
end
def self.callback_hostname
if Rails.env.development?
"132fb088.ngrok.com"
elsif Rails.env.production?
"www.gotostudy.com"
end
end
def our_account_balance
bal = @gengo.getAccountBalance()['response']
"#{bal['credits']} #{bal['currency']}"
end
def get_ongoing_translations
@gengo.getTranslationJobs
end
def request_translations(jobs_hash)
@gengo.postTranslationJobs({jobs: jobs_hash})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment