Last active
January 26, 2017 22:30
-
-
Save Arcolye/0e3ba1b98cfd03de9016e84dceb6fe8d to your computer and use it in GitHub Desktop.
GoToStudy - Gengo Translation API wrapper
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
# 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