gengo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +48 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/lib/gengo-ruby/api_handler.rb +433 -0
- data/lib/gengo-ruby/gengo_exception.rb +15 -0
- data/lib/gengo.rb +15 -0
- data/licenses/LICENSE.txt +18 -0
- metadata +169 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gengo (0.0.0)
|
5
|
+
json
|
6
|
+
mime-types
|
7
|
+
multipart-post
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.3.2)
|
13
|
+
crack (0.3.1)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
json (1.7.5)
|
16
|
+
mime-types (1.19)
|
17
|
+
multi_json (1.3.6)
|
18
|
+
multipart-post (1.1.5)
|
19
|
+
rack (1.4.1)
|
20
|
+
rack-test (0.6.1)
|
21
|
+
rack (>= 1.0)
|
22
|
+
rake (0.9.2.2)
|
23
|
+
rspec (2.11.0)
|
24
|
+
rspec-core (~> 2.11.0)
|
25
|
+
rspec-expectations (~> 2.11.0)
|
26
|
+
rspec-mocks (~> 2.11.0)
|
27
|
+
rspec-core (2.11.1)
|
28
|
+
rspec-expectations (2.11.2)
|
29
|
+
diff-lcs (~> 1.1.3)
|
30
|
+
rspec-mocks (2.11.2)
|
31
|
+
simplecov (0.6.4)
|
32
|
+
multi_json (~> 1.0)
|
33
|
+
simplecov-html (~> 0.5.3)
|
34
|
+
simplecov-html (0.5.3)
|
35
|
+
webmock (1.8.9)
|
36
|
+
addressable (>= 2.2.7)
|
37
|
+
crack (>= 0.1.7)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
gengo!
|
44
|
+
rack-test
|
45
|
+
rake
|
46
|
+
rspec
|
47
|
+
simplecov
|
48
|
+
webmock
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/gengo/gengo-ruby.png)](http://travis-ci.org/gengo/gengo-ruby)
|
2
|
+
Gengo Ruby Library (for the [Gengo API](http://gengo.com/api/))
|
3
|
+
========================================================================================================
|
4
|
+
Translating your tools and products helps people all over the world access them; this is, of course, a
|
5
|
+
somewhat tricky problem to solve. **[Gengo](http://gengo.com/)** is a service that offers human-translation
|
6
|
+
(which is often a higher quality than machine translation), and an API to manage sending in work and watching
|
7
|
+
jobs. This is a ruby interface to make using the API simpler (some would say incredibly easy).
|
8
|
+
|
9
|
+
|
10
|
+
Installation & Requirements
|
11
|
+
-------------------------------------------------------------------------------------------------------
|
12
|
+
Installing Gengo is fairly simple:
|
13
|
+
|
14
|
+
gem install gengo
|
15
|
+
|
16
|
+
|
17
|
+
Tests - Running Them, etc
|
18
|
+
------------------------------------------------------------------------------------------------------
|
19
|
+
Gengo has a full suite of tests, however they're not currently automated. Each script in the _examples_
|
20
|
+
directory tests a different Gengo API endpoint; run against those if you wish to test for now.
|
21
|
+
|
22
|
+
Question, Comments, Complaints, Praise?
|
23
|
+
------------------------------------------------------------------------------------------------------
|
24
|
+
If you have questions or comments and would like to reach us directly, please feel free to do
|
25
|
+
so at the following outlets. We love hearing from developers!
|
26
|
+
|
27
|
+
Email: api [at] gengo dot com
|
28
|
+
Twitter: **[@gengo_dev](http://twitter.com/gengo_dev)**
|
29
|
+
|
30
|
+
If you come across any issues, please file them on the **[Github project issue tracker](https://github.com/gengo/gengo-ruby/issues)**. Thanks!
|
31
|
+
|
32
|
+
|
33
|
+
Documentation
|
34
|
+
------------------------------------------------------------------------------------------------------
|
35
|
+
The usage of the API is very simple - the most important part is getting authenticated. To do this is just
|
36
|
+
a few lines of code:
|
37
|
+
|
38
|
+
``` ruby
|
39
|
+
require 'gengo'
|
40
|
+
|
41
|
+
gengo = Gengo::API.new({
|
42
|
+
:public_key => 'your_public_key',
|
43
|
+
:private_key => 'your_private_key',
|
44
|
+
:sandbox => true, # Or false, depending on your work
|
45
|
+
})
|
46
|
+
|
47
|
+
# Get some information
|
48
|
+
puts gengo.getAccountBalance()
|
49
|
+
```
|
50
|
+
|
51
|
+
With that, you can call any number of methods supported by this library. The entire library is rdoc supported,
|
52
|
+
so you can look at more method information there - there's also a full suite of test code/examples, located in the 'examples'
|
53
|
+
directory. Enjoy!
|
data/Rakefile
ADDED
@@ -0,0 +1,433 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'cgi'
|
7
|
+
require 'json'
|
8
|
+
require 'openssl'
|
9
|
+
require 'time'
|
10
|
+
require 'net/http/post/multipart'
|
11
|
+
require 'mime/types'
|
12
|
+
|
13
|
+
module Gengo
|
14
|
+
|
15
|
+
# The only real class that ever needs to be instantiated.
|
16
|
+
class API
|
17
|
+
attr_accessor :api_host
|
18
|
+
attr_accessor :debug
|
19
|
+
attr_accessor :client_info
|
20
|
+
|
21
|
+
# Creates a new API handler to shuttle calls/jobs/etc over to the Gengo translation API.
|
22
|
+
#
|
23
|
+
# Options:
|
24
|
+
# <tt>opts</tt> - A hash containing the api key, the api secret key, the API version (defaults to 1), whether to use
|
25
|
+
# the sandbox API, and an optional custom user agent to send.
|
26
|
+
def initialize(opts)
|
27
|
+
# Consider this an example of the object you need to pass.
|
28
|
+
@opts = {
|
29
|
+
:public_key => '',
|
30
|
+
:private_key => '',
|
31
|
+
:api_version => '1.1',
|
32
|
+
:sandbox => false,
|
33
|
+
:user_agent => "Gengo Ruby Library; Version #{Gengo::Config::VERSION}; http://gengo.com/;",
|
34
|
+
:debug => false,
|
35
|
+
}.merge(opts)
|
36
|
+
|
37
|
+
# Let's go ahead and separate these out, for clarity...
|
38
|
+
@debug = @opts[:debug]
|
39
|
+
@api_host = (@opts[:sandbox] == true ? Gengo::Config::SANDBOX_API_HOST : Gengo::Config::API_HOST)
|
40
|
+
|
41
|
+
# More of a public "check this" kind of object.
|
42
|
+
@client_info = {"VERSION" => Gengo::Config::VERSION}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Use CGI escape to escape a string
|
46
|
+
def urlencode(string)
|
47
|
+
CGI::escape(string)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Creates an HMAC::SHA1 signature, signing the timestamp with the private key.
|
51
|
+
def signature_of(ts)
|
52
|
+
OpenSSL::HMAC.hexdigest 'sha1', @opts[:private_key], ts
|
53
|
+
end
|
54
|
+
|
55
|
+
# The "GET" method; handles requesting basic data sets from Gengo and converting
|
56
|
+
# the response to a Ruby hash/object.
|
57
|
+
#
|
58
|
+
# Options:
|
59
|
+
# <tt>endpoint</tt> - String/URL to request data from.
|
60
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
61
|
+
def get_from_gengo(endpoint, params = {})
|
62
|
+
# Do this small check here...
|
63
|
+
is_delete = params.delete(:is_delete)
|
64
|
+
is_download_file = params.delete(:is_download)
|
65
|
+
|
66
|
+
# The first part of the object we're going to encode and use in our request to Gengo. The signing process
|
67
|
+
# is a little annoying at the moment, so bear with us...
|
68
|
+
query = params.reduce({}) {|hash_thus_far, (param_key, param_value)|
|
69
|
+
hash_thus_far.merge(
|
70
|
+
param_key.to_sym => param_value.to_s
|
71
|
+
)
|
72
|
+
}
|
73
|
+
|
74
|
+
query[:api_key] = @opts[:public_key]
|
75
|
+
query[:ts] = Time.now.gmtime.to_i.to_s
|
76
|
+
|
77
|
+
endpoint << "?api_sig=" + signature_of(query[:ts])
|
78
|
+
endpoint << '&' + query.map { |k, v| "#{k}=#{urlencode(v)}" }.join('&')
|
79
|
+
|
80
|
+
uri = "/v#{@opts[:api_version]}/" + endpoint
|
81
|
+
headers = {
|
82
|
+
'Accept' => 'application/json',
|
83
|
+
'User-Agent' => @opts[:user_agent]
|
84
|
+
}
|
85
|
+
|
86
|
+
if is_delete
|
87
|
+
req = Net::HTTP::Delete.new(uri, headers)
|
88
|
+
else
|
89
|
+
req = Net::HTTP::Get.new(uri, headers)
|
90
|
+
end
|
91
|
+
|
92
|
+
http = Net::HTTP.start(@api_host, 80)
|
93
|
+
if @debug
|
94
|
+
http.set_debug_output($stdout)
|
95
|
+
end
|
96
|
+
http.read_timeout = 5*60
|
97
|
+
resp = http.request(req)
|
98
|
+
|
99
|
+
if is_download_file.nil?
|
100
|
+
json = JSON.parse(resp.body)
|
101
|
+
if json['opstat'] != 'ok'
|
102
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return it if there are no problems, nice...
|
106
|
+
return json
|
107
|
+
else
|
108
|
+
return resp.body
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# The "POST" method; handles shuttling up encoded job data to Gengo
|
114
|
+
# for translation and such. Somewhat similar to the above methods, but depending on the scenario
|
115
|
+
# can get some strange exceptions, so we're gonna keep them fairly separate for the time being. Consider
|
116
|
+
# for a merger down the road...
|
117
|
+
#
|
118
|
+
# Options:
|
119
|
+
# <tt>endpoint</tt> - String/URL to post data to.
|
120
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
121
|
+
def send_to_gengo(endpoint, params = {})
|
122
|
+
|
123
|
+
# Check if this is a put
|
124
|
+
is_put = params.delete(:is_put)
|
125
|
+
|
126
|
+
query = {
|
127
|
+
:api_key => @opts[:public_key],
|
128
|
+
:data => params.to_json.gsub('"', '\"'),
|
129
|
+
:ts => Time.now.gmtime.to_i.to_s
|
130
|
+
}
|
131
|
+
|
132
|
+
url = URI.parse("http://#{@api_host}/v#{@opts[:api_version]}/#{endpoint}")
|
133
|
+
http = Net::HTTP.new(url.host, url.port)
|
134
|
+
http.read_timeout = 5*60
|
135
|
+
if is_put
|
136
|
+
request = Net::HTTP::Put.new(url.path)
|
137
|
+
else
|
138
|
+
request = Net::HTTP::Post.new(url.path)
|
139
|
+
end
|
140
|
+
|
141
|
+
request.add_field('Accept', 'application/json')
|
142
|
+
request.add_field('User-Agent', @opts[:user_agent])
|
143
|
+
|
144
|
+
request.content_type = 'application/x-www-form-urlencoded'
|
145
|
+
request.body = {
|
146
|
+
"api_sig" => signature_of(query[:ts]),
|
147
|
+
"api_key" => urlencode(@opts[:public_key]),
|
148
|
+
"data" => urlencode(params.to_json.gsub('\\', '\\\\')),
|
149
|
+
"ts" => query[:ts].to_i.to_s
|
150
|
+
}.map { |k, v| "#{k}=#{v}" }.flatten.join('&')
|
151
|
+
|
152
|
+
if @debug
|
153
|
+
http.set_debug_output($stdout)
|
154
|
+
end
|
155
|
+
|
156
|
+
resp = http.request(request)
|
157
|
+
|
158
|
+
case resp
|
159
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
160
|
+
json = JSON.parse(resp.body)
|
161
|
+
|
162
|
+
if json['opstat'] != 'ok'
|
163
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
164
|
+
end
|
165
|
+
|
166
|
+
# Return it if there are no problems, nice...
|
167
|
+
json
|
168
|
+
else
|
169
|
+
resp.error!
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# The "UPLOAD" method; handles sending a file to the quote method
|
174
|
+
#
|
175
|
+
# Options:
|
176
|
+
# <tt>endpoint</tt> - String/URL to post data to.
|
177
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
178
|
+
def upload_to_gengo(endpoint, params = {})
|
179
|
+
|
180
|
+
# prepare the file_hash and append file_key to each job payload
|
181
|
+
files_hash = params[:jobs].each_value.reduce({}) do |hash_thus_far, job_values|
|
182
|
+
if job_values[:file_path]
|
183
|
+
job_mime_type = MIME::Types.type_for(job_values[:file_path]).first.content_type
|
184
|
+
file_hash_key = "file_#{hash_thus_far.length.to_s}".to_sym
|
185
|
+
job_values[:file_key] = file_hash_key
|
186
|
+
hash_thus_far[file_hash_key] = UploadIO.new(File.open(job_values[:file_path]), job_mime_type, File.basename(job_values[:file_path]))
|
187
|
+
end
|
188
|
+
hash_thus_far
|
189
|
+
end
|
190
|
+
|
191
|
+
url = URI.parse("http://#{@api_host}/v#{@opts[:api_version]}/#{endpoint}")
|
192
|
+
|
193
|
+
http = Net::HTTP.new(url.host, url.port)
|
194
|
+
http.read_timeout = 5*60
|
195
|
+
|
196
|
+
call_timestamp = Time.now.gmtime.to_i.to_s
|
197
|
+
|
198
|
+
the_hash = files_hash.merge({
|
199
|
+
"api_sig" => signature_of(call_timestamp),
|
200
|
+
"api_key" => @opts[:public_key],
|
201
|
+
"data" =>params.to_json.gsub('\\', '\\\\'),
|
202
|
+
"ts" => call_timestamp
|
203
|
+
})
|
204
|
+
|
205
|
+
request = Net::HTTP::Post::Multipart.new(url.path, the_hash, {'Accept' => 'application/json', 'User-Agent' => @opts[:user_agent] })
|
206
|
+
|
207
|
+
if @debug
|
208
|
+
http.set_debug_output($stdout)
|
209
|
+
end
|
210
|
+
|
211
|
+
resp = http.request(request)
|
212
|
+
|
213
|
+
case resp
|
214
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
215
|
+
json = JSON.parse(resp.body)
|
216
|
+
|
217
|
+
if json['opstat'] != 'ok'
|
218
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
219
|
+
end
|
220
|
+
|
221
|
+
# Return it if there are no problems, nice...
|
222
|
+
json
|
223
|
+
else
|
224
|
+
resp.error!
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# Returns a Ruby-hash of the stats for the current account. No arguments required!
|
229
|
+
#
|
230
|
+
# Options:
|
231
|
+
# <tt>None</tt> - N/A
|
232
|
+
def getAccountStats(params = {})
|
233
|
+
self.get_from_gengo('account/stats', params)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Returns a Ruby-hash of the balance for the authenticated account. No args required!
|
237
|
+
#
|
238
|
+
# Options:
|
239
|
+
# <tt>None</tt> - N/A
|
240
|
+
def getAccountBalance(params = {})
|
241
|
+
self.get_from_gengo('account/balance', params)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Posts a translation job over to Gengo, returns a response indicating whether the submission was
|
245
|
+
# successful or not. Param list is quite expansive here, pay attention...
|
246
|
+
#
|
247
|
+
# Options:
|
248
|
+
# <tt>job</tt> - A job is a hash of data describing what you want translated. See the examples included for
|
249
|
+
# more information on what this should be. (type/slug/body_src/lc_src/lc_tgt/tier/auto_approve/comment/callback_url/custom_data)
|
250
|
+
def postTranslationJob(params = {})
|
251
|
+
self.send_to_gengo('translate/job', params)
|
252
|
+
end
|
253
|
+
|
254
|
+
# Much like the above, but takes a hash titled "jobs" that is multiple jobs, each with their own unique key.
|
255
|
+
#
|
256
|
+
# Options:
|
257
|
+
# <tt>jobs</tt> - "Jobs" is a hash containing further hashes; each further hash is a job. This is best seen in the example code.
|
258
|
+
def postTranslationJobs(params = {})
|
259
|
+
self.send_to_gengo('translate/jobs', params)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Updates an already submitted job.
|
263
|
+
#
|
264
|
+
# Options:
|
265
|
+
# <tt>id</tt> - The ID of a job to update.
|
266
|
+
# <tt>action</tt> - A hash describing the update to this job. See the examples for further documentation.
|
267
|
+
def updateTranslationJob(params = {})
|
268
|
+
params[:is_put] = true
|
269
|
+
self.send_to_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Updates a group of already submitted jobs.
|
273
|
+
#
|
274
|
+
# Options:
|
275
|
+
# <tt>jobs</tt> - An Array of job objects to update (job objects or ids)
|
276
|
+
# <tt>action</tt> - A String describing the update to this job. "approved", "rejected", etc - see Gengo docs.
|
277
|
+
def updateTranslationJobs(params = {})
|
278
|
+
params[:is_put] = true
|
279
|
+
self.send_to_gengo('translate/jobs', {:jobs => params[:jobs], :action => params[:action]})
|
280
|
+
end
|
281
|
+
|
282
|
+
# Given an ID, pulls down information concerning that job from Gengo.
|
283
|
+
#
|
284
|
+
# <tt>id</tt> - The ID of a job to check.
|
285
|
+
# <tt>pre_mt</tt> - Optional, get a machine translation if the human translation is not done.
|
286
|
+
def getTranslationJob(params = {})
|
287
|
+
self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
288
|
+
end
|
289
|
+
|
290
|
+
# Pulls down a list of recently submitted jobs, allows some filters.
|
291
|
+
#
|
292
|
+
# <tt>status</tt> - Optional. "unpaid", "available", "pending", "reviewable", "approved", "rejected", or "canceled".
|
293
|
+
# <tt>timestamp_after</tt> - Optional. Epoch timestamp from which to filter submitted jobs.
|
294
|
+
# <tt>count</tt> - Optional. Defaults to 10.
|
295
|
+
def getTranslationJobs(params = {})
|
296
|
+
if params[:ids] and params[:ids].kind_of?(Array)
|
297
|
+
params[:ids] = params[:ids].map { |i| i.to_s() }.join(',')
|
298
|
+
self.get_from_gengo('translate/jobs/:ids'.gsub(':ids', params.delete(:ids)))
|
299
|
+
else
|
300
|
+
self.get_from_gengo('translate/jobs', params)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
# Pulls a group of jobs that were previously submitted together.
|
305
|
+
#
|
306
|
+
# <tt>id</tt> - Required, the ID of a job that you want the batch/group of.
|
307
|
+
def getTranslationJobBatch(params = {})
|
308
|
+
self.get_from_gengo('translate/jobs/group/:group_id'.gsub(':group_id', params.delete(:group_id).to_s), params)
|
309
|
+
end
|
310
|
+
|
311
|
+
# Pulls a group of jobs that were previously submitted together.
|
312
|
+
#
|
313
|
+
# <tt>id</tt> - Required, the ID of a job that you want the batch/group of.
|
314
|
+
def getTranslationOrderJobs(params = {})
|
315
|
+
self.get_from_gengo('translate/order/:order_id'.gsub(':order_id', params.delete(:order_id).to_s), params)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Mirrors the bulk Translation call, but just returns an estimated cost.
|
319
|
+
def determineTranslationCost(params = {})
|
320
|
+
is_upload = params.delete(:is_upload)
|
321
|
+
|
322
|
+
if is_upload
|
323
|
+
self.upload_to_gengo('translate/service/quote/file', params)
|
324
|
+
else
|
325
|
+
self.send_to_gengo('translate/service/quote', params)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
# Post a comment for a translator or Gengo on a job.
|
330
|
+
#
|
331
|
+
# Options:
|
332
|
+
# <tt>id</tt> - The ID of the job you're commenting on.
|
333
|
+
# <tt>comment</tt> - The comment to put on the job.
|
334
|
+
def postTranslationJobComment(params = {})
|
335
|
+
self.send_to_gengo('translate/job/:id/comment'.gsub(':id', params.delete(:id).to_s), params)
|
336
|
+
end
|
337
|
+
|
338
|
+
# Get all comments (the history) from a given job.
|
339
|
+
#
|
340
|
+
# Options:
|
341
|
+
# <tt>id</tt> - The ID of the job to get comments for.
|
342
|
+
def getTranslationJobComments(params = {})
|
343
|
+
self.get_from_gengo('translate/job/:id/comments'.gsub(':id', params.delete(:id).to_s), params)
|
344
|
+
end
|
345
|
+
|
346
|
+
# Returns the feedback you've submitted for a given job.
|
347
|
+
#
|
348
|
+
# Options:
|
349
|
+
# <tt>id</tt> - The ID of the translation job you're retrieving comments from.
|
350
|
+
def getTranslationJobFeedback(params = {})
|
351
|
+
self.get_from_gengo('translate/job/:id/feedback'.gsub(':id', params.delete(:id).to_s), params)
|
352
|
+
end
|
353
|
+
|
354
|
+
# Gets a list of the revision resources for a job. Revisions are created each time a translator updates the text.
|
355
|
+
#
|
356
|
+
# Options:
|
357
|
+
# <tt>id</tt> - The ID of the translation job you're getting revisions from.
|
358
|
+
def getTranslationJobRevisions(params = {})
|
359
|
+
self.get_from_gengo('translate/job/:id/revisions'.gsub(':id', params.delete(:id).to_s), params)
|
360
|
+
end
|
361
|
+
|
362
|
+
# Get a specific revision to a job.
|
363
|
+
#
|
364
|
+
# Options:
|
365
|
+
# <tt>id</tt> - The ID of the translation job you're getting revisions from.
|
366
|
+
# <tt>rev_id</tt> - The ID of the revision you're looking up.
|
367
|
+
def getTranslationJobRevision(params = {})
|
368
|
+
self.get_from_gengo('translate/job/:id/revisions/:revision_id'.gsub(':id', params.delete(:id).to_s).gsub(':revision_id', params.delete(:rev_id).to_s), params)
|
369
|
+
end
|
370
|
+
|
371
|
+
# Returns a preview image for a job.
|
372
|
+
#
|
373
|
+
# Options:
|
374
|
+
# <tt>id</tt> - The ID of the job you want a preview image of.
|
375
|
+
def getTranslationJobPreviewImage(params = {})
|
376
|
+
params[:is_download] = true
|
377
|
+
self.get_from_gengo('translate/job/:id/preview'.gsub(':id', params.delete(:id).to_s), params)
|
378
|
+
end
|
379
|
+
|
380
|
+
# Deletes a job.
|
381
|
+
#
|
382
|
+
# Options:
|
383
|
+
# <tt>id</tt> - The ID of the job you want to delete.
|
384
|
+
def deleteTranslationJob(params = {})
|
385
|
+
params[:is_delete] = true
|
386
|
+
self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
387
|
+
end
|
388
|
+
|
389
|
+
# Deletes multiple jobs.
|
390
|
+
#
|
391
|
+
# Options:
|
392
|
+
# <tt>ids</tt> - An Array of job IDs you want to delete.
|
393
|
+
def deleteTranslationJobs(params = {})
|
394
|
+
if params[:ids] and params[:ids].kind_of?(Array)
|
395
|
+
params[:job_ids] = params[:ids].map { |i| i.to_s() }.join(',')
|
396
|
+
params.delete(:ids)
|
397
|
+
end
|
398
|
+
|
399
|
+
params[:is_delete] = true
|
400
|
+
self.get_from_gengo('translate/jobs', params)
|
401
|
+
end
|
402
|
+
|
403
|
+
# Gets information about currently supported language pairs.
|
404
|
+
#
|
405
|
+
# Options:
|
406
|
+
# <tt>lc_src</tt> - Optional language code to filter on.
|
407
|
+
def getServiceLanguagePairs(params = {})
|
408
|
+
self.get_from_gengo('translate/service/language_pairs', params)
|
409
|
+
end
|
410
|
+
|
411
|
+
# Pulls down currently supported languages.
|
412
|
+
def getServiceLanguages(params = {})
|
413
|
+
self.get_from_gengo('translate/service/languages', params)
|
414
|
+
end
|
415
|
+
|
416
|
+
# Gets list of glossaries that belongs to the authenticated user
|
417
|
+
def getGlossaryList(params = {})
|
418
|
+
self.get_from_gengo('translate/glossary', params)
|
419
|
+
end
|
420
|
+
|
421
|
+
# Gets one glossary that belongs to the authenticated user
|
422
|
+
def getGlossary(params = {})
|
423
|
+
self.get_from_gengo('translate/glossary/:id'.gsub(':id', params.delete(:id).to_s), params)
|
424
|
+
end
|
425
|
+
|
426
|
+
# Downloads one glossary that belongs to the authenticated user
|
427
|
+
def getGlossaryFile(params = {})
|
428
|
+
params[:is_download] = true
|
429
|
+
self.get_from_gengo('translate/glossary/download/:id'.gsub(':id', params.delete(:id).to_s), params)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Gengo
|
2
|
+
# Base Exception class and such.
|
3
|
+
class Gengo::Exception < ::StandardError
|
4
|
+
attr_accessor :opstat, :code, :msg
|
5
|
+
|
6
|
+
# Pretty self explanatory stuff here...
|
7
|
+
def initialize(opstat, code, msg)
|
8
|
+
@opstat = opstat
|
9
|
+
@code = code
|
10
|
+
@msg = msg
|
11
|
+
|
12
|
+
puts msg
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/gengo.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'gengo-ruby/api_handler'
|
3
|
+
require 'gengo-ruby/gengo_exception'
|
4
|
+
|
5
|
+
module Gengo
|
6
|
+
# Store global config objects here - e.g, urls, etc.
|
7
|
+
module Config
|
8
|
+
# API url endpoints; replace the version at function call time to
|
9
|
+
# allow for function-by-function differences in versioning.
|
10
|
+
API_HOST = 'api.gengo.com'
|
11
|
+
SANDBOX_API_HOST = 'api.sandbox.gengo.com'
|
12
|
+
|
13
|
+
VERSION = '0.0.0'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
All code provided from the http://gengo.com site, such as API example code and libraries, is provided under the New BSD license unless otherwise noted. Details are below.
|
2
|
+
|
3
|
+
New BSD License
|
4
|
+
Copyright (c) 2009-2011, Gengo, Inc.
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
Neither the name of Gengo, Inc. nor the names of its contributors may
|
15
|
+
be used to endorse or promote products derived from this software
|
16
|
+
without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gengo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Romaine
|
9
|
+
- Shawn Smith
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: multipart-post
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mime-types
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.7'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.7'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rack-test
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: simplecov
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: ! 'Gengo is a service that offers various translation APIs, both machine
|
128
|
+
and high quality human-sourced. The Gengo gem lets you interface with the Gengo
|
129
|
+
REST API (http://gengo.com/services/api/dev-docs/).Note: previous version of this
|
130
|
+
library can be found at https://rubygems.org/gems/mygengo. All further updates will
|
131
|
+
be made here.'
|
132
|
+
email: api@gengo.com
|
133
|
+
executables: []
|
134
|
+
extensions: []
|
135
|
+
extra_rdoc_files: []
|
136
|
+
files:
|
137
|
+
- lib/gengo-ruby/api_handler.rb
|
138
|
+
- lib/gengo-ruby/gengo_exception.rb
|
139
|
+
- lib/gengo.rb
|
140
|
+
- licenses/LICENSE.txt
|
141
|
+
- Gemfile
|
142
|
+
- Gemfile.lock
|
143
|
+
- Rakefile
|
144
|
+
- README.md
|
145
|
+
homepage: http://developers.gengo.com
|
146
|
+
licenses: []
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.24
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: A library for interfacing with the Gengo Translation API.
|
169
|
+
test_files: []
|