mygengo 1.12 → 1.13
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 +7 -6
- data/Rakefile +6 -8
- data/lib/mygengo-ruby/api_handler.rb +24 -18
- data/lib/mygengo.rb +1 -1
- data/licenses/LICENSE.txt +4 -4
- metadata +68 -2
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mygengo (1.13)
|
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
|
+
mygengo!
|
44
|
+
rack-test
|
45
|
+
rake
|
46
|
+
rspec
|
47
|
+
simplecov
|
48
|
+
webmock
|
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
|
1
|
+
[![Build Status](https://secure.travis-ci.org/myGengo/mygengo-ruby.png)](http://travis-ci.org/myGengo/mygengo-ruby)
|
2
|
+
Gengo Ruby Library (for the [Gengo API](http://gengo.com/))
|
2
3
|
========================================================================================================
|
3
4
|
Translating your tools and products helps people all over the world access them; this is, of course, a
|
4
|
-
somewhat tricky problem to solve. **[
|
5
|
+
somewhat tricky problem to solve. **[Gengo](http://gengo.com/)** is a service that offers human-translation
|
5
6
|
(which is often a higher quality than machine translation), and an API to manage sending in work and watching
|
6
7
|
jobs. This is a ruby interface to make using the API simpler (some would say incredibly easy).
|
7
8
|
|
8
9
|
|
9
10
|
Installation & Requirements
|
10
11
|
-------------------------------------------------------------------------------------------------------
|
11
|
-
Installing
|
12
|
+
Installing Gengo is fairly simple:
|
12
13
|
|
13
14
|
gem install mygengo
|
14
15
|
|
@@ -16,14 +17,14 @@ Installing myGengo is fairly simple:
|
|
16
17
|
Tests - Running Them, etc
|
17
18
|
------------------------------------------------------------------------------------------------------
|
18
19
|
myGengo has a full suite of tests, however they're not currently automated. Each script in the _examples_
|
19
|
-
directory tests a different
|
20
|
+
directory tests a different Gengo API endpoint; run against those if you wish to test for now.
|
20
21
|
|
21
22
|
Question, Comments, Complaints, Praise?
|
22
23
|
------------------------------------------------------------------------------------------------------
|
23
24
|
If you have questions or comments and would like to reach us directly, please feel free to do
|
24
25
|
so at the following outlets. We love hearing from developers!
|
25
26
|
|
26
|
-
Email: api [at]
|
27
|
+
Email: api [at] gengo dot com
|
27
28
|
Twitter: **[@mygengo_dev](http://twitter.com/mygengo_dev)**
|
28
29
|
|
29
30
|
If you come across any issues, please file them on the **[Github project issue tracker](https://github.com/myGengo/mygengo-ruby/issues)**. Thanks!
|
@@ -49,4 +50,4 @@ puts mygengo.getAccountBalance()
|
|
49
50
|
|
50
51
|
With that, you can call any number of methods supported by this library. The entire library is rdoc supported,
|
51
52
|
so you can look at more method information there - there's also a full suite of test code/examples, located in the 'examples'
|
52
|
-
directory.
|
53
|
+
directory. Enjoy!
|
data/Rakefile
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
Rake::TestRake.new do |t|
|
7
|
-
t.libs << "test"
|
8
|
-
t.test_files = FileList['test/*test.rb']
|
9
|
-
t.verbose = true
|
5
|
+
RSpec::Core::RakeTask.new do |t|
|
10
6
|
end
|
7
|
+
|
8
|
+
task :default => :spec
|
@@ -18,7 +18,7 @@ module MyGengo
|
|
18
18
|
attr_accessor :debug
|
19
19
|
attr_accessor :client_info
|
20
20
|
|
21
|
-
# Creates a new API handler to shuttle calls/jobs/etc over to the
|
21
|
+
# Creates a new API handler to shuttle calls/jobs/etc over to the Gengo translation API.
|
22
22
|
#
|
23
23
|
# Options:
|
24
24
|
# <tt>opts</tt> - A hash containing the api key, the api secret key, the API version (defaults to 1), whether to use
|
@@ -30,7 +30,7 @@ module MyGengo
|
|
30
30
|
:private_key => '',
|
31
31
|
:api_version => '1.1',
|
32
32
|
:sandbox => false,
|
33
|
-
:user_agent => "
|
33
|
+
:user_agent => "Gengo Ruby Library; Version #{MyGengo::Config::VERSION}; http://gengo.com/;",
|
34
34
|
:debug => false,
|
35
35
|
}.merge(opts)
|
36
36
|
|
@@ -43,7 +43,7 @@ module MyGengo
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# This is... hilariously awkward, but Ruby escapes things very differently from PHP/etc. This causes
|
46
|
-
# issues with de-escaping things on the backend over at
|
46
|
+
# issues with de-escaping things on the backend over at Gengo; in the future this will become obsolete,
|
47
47
|
# but for now we'll just leave this here...
|
48
48
|
def urlencode(string)
|
49
49
|
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
|
@@ -56,7 +56,7 @@ module MyGengo
|
|
56
56
|
OpenSSL::HMAC.hexdigest 'sha1', @opts[:private_key], ts
|
57
57
|
end
|
58
58
|
|
59
|
-
# The "GET" method; handles requesting basic data sets from
|
59
|
+
# The "GET" method; handles requesting basic data sets from Gengo and converting
|
60
60
|
# the response to a Ruby hash/object.
|
61
61
|
#
|
62
62
|
# Options:
|
@@ -67,12 +67,16 @@ module MyGengo
|
|
67
67
|
is_delete = params.delete(:is_delete)
|
68
68
|
is_download_file = params.delete(:is_download)
|
69
69
|
|
70
|
-
# The first part of the object we're going to encode and use in our request to
|
70
|
+
# The first part of the object we're going to encode and use in our request to Gengo. The signing process
|
71
71
|
# is a little annoying at the moment, so bear with us...
|
72
|
-
query = {
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
query = params.reduce({}) {|hash_thus_far, (param_key, param_value)|
|
73
|
+
hash_thus_far.merge(
|
74
|
+
param_key.to_sym => param_value.to_s
|
75
|
+
)
|
76
|
+
}
|
77
|
+
|
78
|
+
query[:api_key] = @opts[:public_key]
|
79
|
+
query[:ts] = Time.now.gmtime.to_i.to_s
|
76
80
|
|
77
81
|
endpoint << "?api_sig=" + signature_of(query[:ts])
|
78
82
|
endpoint << '&' + query.map { |k, v| "#{k}=#{urlencode(v)}" }.join('&')
|
@@ -110,7 +114,7 @@ module MyGengo
|
|
110
114
|
|
111
115
|
end
|
112
116
|
|
113
|
-
# The "POST" method; handles shuttling up encoded job data to
|
117
|
+
# The "POST" method; handles shuttling up encoded job data to Gengo
|
114
118
|
# for translation and such. Somewhat similar to the above methods, but depending on the scenario
|
115
119
|
# can get some strange exceptions, so we're gonna keep them fairly separate for the time being. Consider
|
116
120
|
# for a merger down the road...
|
@@ -179,10 +183,12 @@ module MyGengo
|
|
179
183
|
|
180
184
|
# prepare the file_hash and append file_key to each job payload
|
181
185
|
files_hash = params[:jobs].each_value.reduce({}) do |hash_thus_far, job_values|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
+
if job_values[:file_path].present?
|
187
|
+
job_mime_type = MIME::Types.type_for(job_values[:file_path]).first.content_type
|
188
|
+
file_hash_key = "file_#{hash_thus_far.length.to_s}".to_sym
|
189
|
+
job_values[:file_key] = file_hash_key
|
190
|
+
hash_thus_far[file_hash_key] = UploadIO.new(File.open(job_values[:file_path]), job_mime_type, File.basename(job_values[:file_path]))
|
191
|
+
end
|
186
192
|
hash_thus_far
|
187
193
|
end
|
188
194
|
|
@@ -239,7 +245,7 @@ module MyGengo
|
|
239
245
|
self.get_from_mygengo('account/balance', params)
|
240
246
|
end
|
241
247
|
|
242
|
-
# Posts a translation job over to
|
248
|
+
# Posts a translation job over to Gengo, returns a response indicating whether the submission was
|
243
249
|
# successful or not. Param list is quite expansive here, pay attention...
|
244
250
|
#
|
245
251
|
# Options:
|
@@ -271,13 +277,13 @@ module MyGengo
|
|
271
277
|
#
|
272
278
|
# Options:
|
273
279
|
# <tt>jobs</tt> - An Array of job objects to update (job objects or ids)
|
274
|
-
# <tt>action</tt> - A String describing the update to this job. "approved", "rejected", etc - see
|
280
|
+
# <tt>action</tt> - A String describing the update to this job. "approved", "rejected", etc - see Gengo docs.
|
275
281
|
def updateTranslationJobs(params = {})
|
276
282
|
params[:is_put] = true
|
277
283
|
self.send_to_mygengo('translate/jobs', {:jobs => params[:jobs], :action => params[:action]})
|
278
284
|
end
|
279
285
|
|
280
|
-
# Given an ID, pulls down information concerning that job from
|
286
|
+
# Given an ID, pulls down information concerning that job from Gengo.
|
281
287
|
#
|
282
288
|
# <tt>id</tt> - The ID of a job to check.
|
283
289
|
# <tt>pre_mt</tt> - Optional, get a machine translation if the human translation is not done.
|
@@ -324,7 +330,7 @@ module MyGengo
|
|
324
330
|
end
|
325
331
|
end
|
326
332
|
|
327
|
-
# Post a comment for a translator or
|
333
|
+
# Post a comment for a translator or Gengo on a job.
|
328
334
|
#
|
329
335
|
# Options:
|
330
336
|
# <tt>id</tt> - The ID of the job you're commenting on.
|
data/lib/mygengo.rb
CHANGED
data/licenses/LICENSE.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
All code provided from the http://
|
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
2
|
|
3
3
|
New BSD License
|
4
|
-
Copyright (c) 2009-2011,
|
4
|
+
Copyright (c) 2009-2011, Gengo, Inc.
|
5
5
|
All rights reserved.
|
6
6
|
|
7
7
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
@@ -11,8 +11,8 @@ this list of conditions and the following disclaimer.
|
|
11
11
|
Redistributions in binary form must reproduce the above copyright notice,
|
12
12
|
this list of conditions and the following disclaimer in the documentation
|
13
13
|
and/or other materials provided with the distribution.
|
14
|
-
Neither the name of
|
14
|
+
Neither the name of Gengo, Inc. nor the names of its contributors may
|
15
15
|
be used to endorse or promote products derived from this software
|
16
16
|
without specific prior written permission.
|
17
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.
|
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mygengo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.13'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-08-
|
15
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: json
|
@@ -62,6 +62,70 @@ dependencies:
|
|
62
62
|
- - ! '>='
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rspec
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.7'
|
73
|
+
type: :development
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.7'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rack-test
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: webmock
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
65
129
|
description: Gengo is a service that offers various translation APIs, both machine
|
66
130
|
and high quality human-sourced. The Gengo gem lets you interface with the Gengo
|
67
131
|
REST API (http://gengo.com/services/api/dev-docs/).
|
@@ -74,6 +138,8 @@ files:
|
|
74
138
|
- lib/mygengo-ruby/mygengo_exception.rb
|
75
139
|
- lib/mygengo.rb
|
76
140
|
- licenses/LICENSE.txt
|
141
|
+
- Gemfile
|
142
|
+
- Gemfile.lock
|
77
143
|
- Rakefile
|
78
144
|
- README.md
|
79
145
|
homepage: http://gengo.com/services/api/dev-docs/
|