gengo 0.0.6 → 0.0.7.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ff0f3938fa56369d49bd3d1b433cf89df456a30
4
- data.tar.gz: 393640dd5d5048c6cb0d6019da56ac8bb5e386c8
3
+ metadata.gz: be085b6228a9ff5fd3fba670320090db211a8507
4
+ data.tar.gz: aa298c83a73ce44d7a51e6090a4f0ceb6c475291
5
5
  SHA512:
6
- metadata.gz: 2afd41658a2d4e95d723c26b1e7e05dc5e5cdbe915640f9d122337556c1384392efaaf0a737ece1fdc79d481cebe9bef969fb9f570174321960e2700adbfeae1
7
- data.tar.gz: 8ca39ce90ba3c64f7127083e98ae3c051e555d62a14fa74d3d42d0d235e0f2f98f5fced6e431c28a6625f4f1cb096bfed2e85ed10e75111e7b597f126abfb004
6
+ metadata.gz: d60284a73d86897c116f3fc4242ef98d8fb5107eab982da7e5cea9f7649087963dc0c7c151b1d8b875dfda02c5e9746dcb7f81bd73f032fc508ab474d4270513
7
+ data.tar.gz: c1a2a082c13c47033295380ee221117548fe40bacbc6b51b904c9fd7e712e82b947ec02894a666d27a52be130d12d5934e52c68fbba0c357c9721dd35a1ed08c
data/Gemfile CHANGED
@@ -2,9 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gengo-ruby.gemspec
4
4
  gemspec
5
-
6
- group :development, :test do
7
- gem 'rake'
8
- gem 'rspec'
9
- gem 'simplecov'
10
- end
@@ -11,7 +11,7 @@ Gem::Specification.new do |gs|
11
11
  "Issam Zeibak",
12
12
  "Alexander Lidé",
13
13
  ]
14
- gs.date = "2015-04-27"
14
+ gs.date = "2015-08-24"
15
15
  gs.summary = "A library for interfacing with the Gengo Translation API."
16
16
  gs.description = "Gengo is a service that offers various translation APIs, both machine and high quality human-sourced. The Gengo gem lets you interface with the Gengo REST API (http://developers.gengo.com/).Note: previous version of this library can be found at https://rubygems.org/gems/mygengo. All further updates will be made here."
17
17
  gs.email = "api@gengo.com"
@@ -25,6 +25,7 @@ Gem::Specification.new do |gs|
25
25
  gs.add_dependency('mime-types')
26
26
  gs.add_development_dependency 'rspec', '~> 2.7'
27
27
  gs.add_development_dependency 'rack-test'
28
+ gs.add_development_dependency 'rake'
28
29
  gs.add_development_dependency 'simplecov'
29
30
  gs.add_development_dependency 'webmock'
30
31
  end
@@ -30,13 +30,13 @@ module Gengo
30
30
  :private_key => '',
31
31
  :api_version => '2',
32
32
  :sandbox => false,
33
- :user_agent => "Gengo Ruby Library; Version #{Gengo::Config::VERSION}; http://gengo.com/;",
33
+ :user_agent => "Gengo Ruby Library; Version #{Gengo::Config::VERSION}; Ruby Version #{RUBY_DESCRIPTION}; http://gengo.com/;",
34
34
  :debug => false,
35
35
  }.merge(opts)
36
36
 
37
37
  # Let's go ahead and separate these out, for clarity...
38
38
  @debug = @opts[:debug]
39
- @api_host = (@opts[:sandbox] == true ? Gengo::Config::SANDBOX_API_HOST : Gengo::Config::API_HOST)
39
+ @api_host = (@opts[:sandbox] ? Gengo::Config::SANDBOX_API_HOST : Gengo::Config::API_HOST)
40
40
 
41
41
  # More of a public "check this" kind of object.
42
42
  @client_info = {"VERSION" => Gengo::Config::VERSION}
@@ -94,18 +94,23 @@ module Gengo
94
94
  http.read_timeout = 5*60
95
95
  resp = http.request(req)
96
96
 
97
- if is_download_file.nil?
97
+ return resp.body if is_download_file
98
+
99
+ begin
98
100
  json = JSON.parse(resp.body)
99
- if json['opstat'] != 'ok'
100
- raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
101
- end
101
+ rescue => e
102
+ # TODO(yugui) Log the original error
103
+ raise Gengo::Exception.new('error', resp.code.to_i, resp.body) unless resp.kind_of?(Net::HTTPSuccess)
102
104
 
103
- # Return it if there are no problems, nice...
104
- return json
105
- else
106
- return resp.body
105
+ # It should be very unlikely, but resp.body can be invalid as a JSON in theory even though the status is successful.
106
+ # In this case, raise an exception to report that unexpected status.
107
+ raise Gengo::Exception.new('error', 500, 'unexpected format of server response. Report it to Gengo if this exception repeatedly happens')
107
108
  end
108
109
 
110
+ raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg']) unless json['opstat'] == 'ok'
111
+
112
+ # Return it if there are no problems, nice...
113
+ return json
109
114
  end
110
115
 
111
116
  # The "POST" method; handles shuttling up encoded job data to Gengo
@@ -152,19 +157,18 @@ module Gengo
152
157
  end
153
158
 
154
159
  resp = http.request(request)
155
-
156
- case resp
157
- when Net::HTTPSuccess, Net::HTTPRedirection
158
- json = JSON.parse(resp.body)
159
-
160
- if json['opstat'] != 'ok'
161
- raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
162
- end
163
-
164
- # Return it if there are no problems, nice...
165
- json
166
- else
167
- resp.error!
160
+ resp.error! unless resp.kind_of?(Net::HTTPSuccess)
161
+
162
+ json = JSON.parse(resp.body)
163
+ return json if json['opstat'] == 'ok'
164
+
165
+ case
166
+ when json['err']['code']
167
+ raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
168
+ when json['err'].respond_to?(:each)
169
+ # Ad-hock care of bulk operations. To be done in a higher-layer in future. [#93504182]
170
+ err = json['err'].map {|key, value| value.respond_to?(:first) ? value.first : value }
171
+ raise Gengo::Exception.new(json['opstat'], err.first['code'], err.map{|e| e['msg']}.join(';'))
168
172
  end
169
173
  end
170
174
 
@@ -262,17 +266,18 @@ module Gengo
262
266
  # <tt>action</tt> - A hash describing the update to this job. See the examples for further documentation.
263
267
  def updateTranslationJob(params = {})
264
268
  params[:is_put] = true
265
- self.send_to_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
269
+ id = params.delete(:id).to_s
270
+ self.send_to_gengo("translate/job/#{id}", params)
266
271
  end
267
272
 
268
273
  # Updates a group of already submitted jobs.
269
274
  #
270
275
  # Options:
271
- # <tt>jobs</tt> - An Array of job objects to update (job objects or ids)
276
+ # <tt>job_ids</tt> - An Array of job objects to update (job objects or ids)
272
277
  # <tt>action</tt> - A String describing the update to this job. "approved", "rejected", etc - see Gengo docs.
273
278
  def updateTranslationJobs(params = {})
274
279
  params[:is_put] = true
275
- self.send_to_gengo('translate/jobs', {:jobs => params[:jobs], :action => params[:action]})
280
+ self.send_to_gengo('translate/jobs', params)
276
281
  end
277
282
 
278
283
  # Given an ID, pulls down information concerning that job from Gengo.
@@ -280,35 +285,75 @@ module Gengo
280
285
  # <tt>id</tt> - The ID of a job to check.
281
286
  # <tt>pre_mt</tt> - Optional, get a machine translation if the human translation is not done.
282
287
  def getTranslationJob(params = {})
283
- self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
288
+ id = params.delete(:id).to_s
289
+ self.get_from_gengo("translate/job/#{id}", params)
284
290
  end
285
291
 
286
- # Pulls down a list of recently submitted jobs, allows some filters.
292
+ # Fetches a list of recent jobs you made.
293
+ #
294
+ # @deprecated Use {#jobs} or {#query_jobs} instead.
287
295
  #
288
- # <tt>status</tt> - Optional. "unpaid", "available", "pending", "reviewable", "approved", "rejected", or "canceled".
289
- # <tt>timestamp_after</tt> - Optional. Epoch timestamp from which to filter submitted jobs.
290
- # <tt>count</tt> - Optional. Defaults to 10.
296
+ # == Keyword Parameters
297
+ # <tt>ids</tt>::
298
+ # Optional. An array of job IDs to be fetched.
299
+ # Other parameters are ignored if you specify this parameter.
300
+ # <tt>status</tt>::
301
+ # Optional. "unpaid", "available", "pending", "reviewable", "approved", "rejected", or "canceled".
302
+ # <tt>timestamp_after</tt>::
303
+ # Optional. Epoch timestamp from which to filter submitted jobs.
304
+ # <tt>count</tt>::
305
+ # Optional. Defaults to 10.
291
306
  def getTranslationJobs(params = {})
292
- if params[:ids] and params[:ids].kind_of?(Array)
293
- params[:ids] = params[:ids].map { |i| i.to_s() }.join(',')
294
- self.get_from_gengo('translate/jobs/:ids'.gsub(':ids', params.delete(:ids)))
307
+ if params[:ids].respond_to?(:each)
308
+ jobs(params.delete(:ids))
295
309
  else
296
- self.get_from_gengo('translate/jobs', params)
310
+ query_jobs(params)
297
311
  end
298
312
  end
299
313
 
300
- # Pulls a group of jobs that were previously submitted together.
314
+ # Fetchs a set of recent jobs whose IDs are the given ones.
315
+ # @param ids [[Integer|String]] An array of job IDs to be fetched
316
+ def jobs(ids)
317
+ get_from_gengo('translate/jobs/%s' % ids.join(','))
318
+ end
319
+
320
+ # Fetchs a set of recent jobs you made.
321
+ # You can apply filters with the following keyword parameters.
322
+ #
323
+ # == Keyword Parameters
324
+ # <tt>status</tt>::
325
+ # Optional. Fetches only jobs in this status.
326
+ # Must be "unpaid", "available", "pending", "reviewable", "approved", "rejected", or "canceled".
327
+ # <tt>timestamp_after</tt>::
328
+ # Optional. Epoch timestamp from which to filter submitted jobs.
329
+ # <tt>count</tt>::
330
+ # Optional. The maximum number of jobs to be returned. Defaults to 10.
331
+ def query_jobs(params = {})
332
+ get_from_gengo('translate/jobs', params)
333
+ end
334
+
335
+ # Fetches a set of jobs in the order you made.
336
+ #
337
+ # @deprecated Use {#jobs_in_order} instead.
301
338
  #
302
- # <tt>id</tt> - Required, the ID of a job that you want the batch/group of.
339
+ # == Required keyword parameters
340
+ # <tt>order_id</tt> - Required, the ID of a job that you want the batch/group of.
303
341
  def getTranslationOrderJobs(params = {})
304
- self.get_from_gengo('translate/order/:order_id'.gsub(':order_id', params.delete(:order_id).to_s), params)
342
+ order_id = params[:order_id]
343
+ raise ArgumentError, 'order_id is a required parameter' unless order_id
344
+ jobs_in_order(order_id)
345
+ end
346
+
347
+ # Fetches a set of jobs in the order you made.
348
+ def jobs_in_order(id)
349
+ self.get_from_gengo("translate/order/#{id}")
305
350
  end
306
351
 
307
352
  # Mirrors the bulk Translation call, but just returns an estimated cost.
308
353
  def determineTranslationCost(params = {})
309
354
  is_upload = params.delete(:is_upload)
310
355
  if is_upload
311
- self.upload_to_gengo('translate/service/quote/file', params)
356
+ self.upload_to_gengo('translate/service/quote', params)
312
357
  else
313
358
  self.send_to_gengo('translate/service/quote', params)
314
359
  end
@@ -325,7 +370,8 @@ module Gengo
325
370
  # <tt>id</tt> - The ID of the job you're commenting on.
326
371
  # <tt>comment</tt> - The comment to put on the job.
327
372
  def postTranslationJobComment(params = {})
328
- self.send_to_gengo('translate/job/:id/comment'.gsub(':id', params.delete(:id).to_s), params)
373
+ id = params.delete(:id).to_s
374
+ self.send_to_gengo("translate/job/#{id}/comment", params)
329
375
  end
330
376
 
331
377
  # Get all comments (the history) from a given job.
@@ -333,7 +379,8 @@ module Gengo
333
379
  # Options:
334
380
  # <tt>id</tt> - The ID of the job to get comments for.
335
381
  def getTranslationJobComments(params = {})
336
- self.get_from_gengo('translate/job/:id/comments'.gsub(':id', params.delete(:id).to_s), params)
382
+ id = params.delete(:id).to_s
383
+ self.get_from_gengo("translate/job/#{id}/comments", params)
337
384
  end
338
385
 
339
386
  # Returns the feedback you've submitted for a given job.
@@ -341,7 +388,8 @@ module Gengo
341
388
  # Options:
342
389
  # <tt>id</tt> - The ID of the translation job you're retrieving comments from.
343
390
  def getTranslationJobFeedback(params = {})
344
- self.get_from_gengo('translate/job/:id/feedback'.gsub(':id', params.delete(:id).to_s), params)
391
+ id = params.delete(:id).to_s
392
+ self.get_from_gengo("translate/job/#{id}/feedback", params)
345
393
  end
346
394
 
347
395
  # Gets a list of the revision resources for a job. Revisions are created each time a translator updates the text.
@@ -349,7 +397,8 @@ module Gengo
349
397
  # Options:
350
398
  # <tt>id</tt> - The ID of the translation job you're getting revisions from.
351
399
  def getTranslationJobRevisions(params = {})
352
- self.get_from_gengo('translate/job/:id/revisions'.gsub(':id', params.delete(:id).to_s), params)
400
+ id = params.delete(:id).to_s
401
+ self.get_from_gengo("translate/job/#{id}/revisions", params)
353
402
  end
354
403
 
355
404
  # Get a specific revision to a job.
@@ -358,7 +407,9 @@ module Gengo
358
407
  # <tt>id</tt> - The ID of the translation job you're getting revisions from.
359
408
  # <tt>rev_id</tt> - The ID of the revision you're looking up.
360
409
  def getTranslationJobRevision(params = {})
361
- self.get_from_gengo('translate/job/:id/revision/:revision_id'.gsub(':id', params.delete(:id).to_s).gsub(':revision_id', params.delete(:rev_id).to_s), params)
410
+ id = params.delete(:id).to_s
411
+ revision_id = params.delete(:rev_id).to_s
412
+ self.get_from_gengo("translate/job/#{id}/revision/#{revision_id}", params)
362
413
  end
363
414
 
364
415
  # Deletes an order, cancelling all available jobs.
@@ -369,7 +420,26 @@ module Gengo
369
420
  # <tt>id</tt> - The ID of the order you want to delete.
370
421
  def deleteTranslationOrder(params = {})
371
422
  params[:is_delete] = true
372
- self.get_from_gengo('translate/order/:id'.gsub(':id', params.delete(:id).to_s), params)
423
+ id = params.delete(:id).to_s
424
+ self.get_from_gengo("translate/order/#{id}", params)
425
+ end
426
+
427
+ # Get all comments (the history) from a given order.
428
+ #
429
+ # Requirements:
430
+ # <tt>order_id</tt> - The ID of the order to get comments for.
431
+ def get_translation_order_comments(order_id)
432
+ get_from_gengo("translate/order/#{order_id}/comments")
433
+ end
434
+
435
+ # Post a comment for a translator or Gengo on an order.
436
+ #
437
+ # Options:
438
+ # <tt>id</tt> - The ID of the order you're commenting on.
439
+ # <tt>comment</tt> - The comment to put on the order.
440
+ def post_translation_order_comment(params = {})
441
+ id = params.delete(:id).to_s
442
+ send_to_gengo("translate/order/#{id}/comment", params)
373
443
  end
374
444
 
375
445
  # Deletes a job.
@@ -378,7 +448,8 @@ module Gengo
378
448
  # <tt>id</tt> - The ID of the job you want to delete.
379
449
  def deleteTranslationJob(params = {})
380
450
  params[:is_delete] = true
381
- self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
451
+ id = params.delete(:id).to_s
452
+ self.get_from_gengo("translate/job/#{id}", params)
382
453
  end
383
454
 
384
455
  # Deletes multiple jobs.
@@ -415,13 +486,15 @@ module Gengo
415
486
 
416
487
  # Gets one glossary that belongs to the authenticated user
417
488
  def getGlossary(params = {})
418
- self.get_from_gengo('translate/glossary/:id'.gsub(':id', params.delete(:id).to_s), params)
489
+ id = params.delete(:id).to_s
490
+ self.get_from_gengo("translate/glossary/#{id}", params)
419
491
  end
420
492
 
421
493
  # Downloads one glossary that belongs to the authenticated user
422
494
  def getGlossaryFile(params = {})
423
495
  params[:is_download] = true
424
- self.get_from_gengo('translate/glossary/download/:id'.gsub(':id', params.delete(:id).to_s), params)
496
+ id = params.delete(:id).to_s
497
+ self.get_from_gengo("translate/glossary/download/#{id}", params)
425
498
  end
426
499
  end
427
500
 
@@ -8,6 +8,11 @@ module Gengo
8
8
  @opstat = opstat
9
9
  @code = code
10
10
  @msg = msg
11
+ super(msg)
12
+ end
13
+
14
+ def inspect
15
+ "Gengo::Exception(opstat=%s, code=%d, msg=%s)" % [opstat, code, msg]
11
16
  end
12
17
  end
13
18
  end
@@ -1,5 +1,5 @@
1
1
  module Gengo
2
2
  module Config
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7.rc1'
4
4
  end
5
5
  end
data/test.rb ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: UTF-8
2
+ require 'gengo'
3
+
4
+ gengo = Gengo::API.new({
5
+ :public_key => 'cee8d849f2354e0a9ff62f19868194c1',
6
+ :private_key => 'd0895146e2d9459b908b2c31bab36f52',
7
+ :sandbox => false,
8
+ })
9
+
10
+ # Return the number of credits left on your account.
11
+ puts gengo.getAccountBalance()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gengo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Romaine
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-04-27 00:00:00.000000000 Z
14
+ date: 2015-08-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -83,6 +83,20 @@ dependencies:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: rake
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
86
100
  - !ruby/object:Gem::Dependency
87
101
  name: simplecov
88
102
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +145,7 @@ files:
131
145
  - lib/gengo-ruby/version.rb
132
146
  - lib/gengo.rb
133
147
  - licenses/LICENSE.txt
148
+ - test.rb
134
149
  homepage: http://developers.gengo.com
135
150
  licenses:
136
151
  - New BSD
@@ -146,9 +161,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
161
  version: '0'
147
162
  required_rubygems_version: !ruby/object:Gem::Requirement
148
163
  requirements:
149
- - - ">="
164
+ - - ">"
150
165
  - !ruby/object:Gem::Version
151
- version: '0'
166
+ version: 1.3.1
152
167
  requirements: []
153
168
  rubyforge_project:
154
169
  rubygems_version: 2.4.5