gengo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +33 -20
- data/gengo-ruby.gemspec +2 -1
- data/lib/gengo-ruby/api_handler.rb +36 -6
- data/lib/gengo-ruby/version.rb +1 -1
- metadata +17 -5
- data/test.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa10fb803c44eb7336b4bd11e36a5b745a28a77
|
4
|
+
data.tar.gz: 7d012f183a69e22553b08a60f640cb4029c14e95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61dfd9cbf2661e47012dfde5912fae162c9043489ffee899229588df305b58c1b882541e45bff1002f79a9f1de2347c2634e0b4d6e337754b0d73f4bf626c2b7
|
7
|
+
data.tar.gz: 0899fef6a4929acc7a897d1f42b27288229f36d8ce559081a916be22657cebd8768bda0de186a6b08d1d245cca4d407bb65fcb445100e22a2c32fdd0cf32a77e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gengo (0.
|
4
|
+
gengo (0.2.0)
|
5
5
|
json
|
6
6
|
mime-types
|
7
7
|
multipart-post
|
@@ -9,43 +9,56 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
addressable (2.
|
13
|
-
crack (0.4.
|
12
|
+
addressable (2.4.0)
|
13
|
+
crack (0.4.3)
|
14
14
|
safe_yaml (~> 1.0.0)
|
15
|
-
diff-lcs (1.
|
15
|
+
diff-lcs (1.3)
|
16
16
|
docile (1.1.5)
|
17
|
-
|
18
|
-
|
17
|
+
hashdiff (0.3.0)
|
18
|
+
json (2.0.2)
|
19
|
+
mime-types (3.1)
|
20
|
+
mime-types-data (~> 3.2015)
|
21
|
+
mime-types-data (3.2016.0521)
|
19
22
|
multipart-post (2.0.0)
|
20
|
-
rack (1.6.
|
23
|
+
rack (1.6.4)
|
21
24
|
rack-test (0.6.3)
|
22
25
|
rack (>= 1.0)
|
23
|
-
rake (
|
24
|
-
rspec (
|
25
|
-
rspec-core (~>
|
26
|
-
rspec-expectations (~>
|
27
|
-
rspec-mocks (~>
|
28
|
-
rspec-core (
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
rake (11.3.0)
|
27
|
+
rspec (3.5.0)
|
28
|
+
rspec-core (~> 3.5.0)
|
29
|
+
rspec-expectations (~> 3.5.0)
|
30
|
+
rspec-mocks (~> 3.5.0)
|
31
|
+
rspec-core (3.5.4)
|
32
|
+
rspec-support (~> 3.5.0)
|
33
|
+
rspec-expectations (3.5.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.5.0)
|
36
|
+
rspec-mocks (3.5.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.5.0)
|
39
|
+
rspec-support (3.5.0)
|
32
40
|
safe_yaml (1.0.4)
|
33
|
-
simplecov (0.
|
41
|
+
simplecov (0.12.0)
|
34
42
|
docile (~> 1.1.0)
|
35
|
-
json (
|
43
|
+
json (>= 1.8, < 3)
|
36
44
|
simplecov-html (~> 0.10.0)
|
37
45
|
simplecov-html (0.10.0)
|
38
|
-
webmock (1.
|
46
|
+
webmock (2.1.0)
|
39
47
|
addressable (>= 2.3.6)
|
40
48
|
crack (>= 0.3.2)
|
49
|
+
hashdiff
|
41
50
|
|
42
51
|
PLATFORMS
|
43
52
|
ruby
|
44
53
|
|
45
54
|
DEPENDENCIES
|
46
55
|
gengo!
|
56
|
+
rack (~> 1.6)
|
47
57
|
rack-test
|
48
58
|
rake
|
49
|
-
rspec (~>
|
59
|
+
rspec (~> 3.5)
|
50
60
|
simplecov
|
51
61
|
webmock
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
1.13.7
|
data/gengo-ruby.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |gs|
|
|
23
23
|
gs.add_dependency('json')
|
24
24
|
gs.add_dependency('multipart-post')
|
25
25
|
gs.add_dependency('mime-types')
|
26
|
-
gs.add_development_dependency 'rspec', '~>
|
26
|
+
gs.add_development_dependency 'rspec', '~> 3.5'
|
27
|
+
gs.add_development_dependency 'rack', '~> 1.6'
|
27
28
|
gs.add_development_dependency 'rack-test'
|
28
29
|
gs.add_development_dependency 'rake'
|
29
30
|
gs.add_development_dependency 'simplecov'
|
@@ -28,6 +28,7 @@ module Gengo
|
|
28
28
|
@opts = {
|
29
29
|
:public_key => '',
|
30
30
|
:private_key => '',
|
31
|
+
:access_token => '',
|
31
32
|
:api_version => '2',
|
32
33
|
:sandbox => false,
|
33
34
|
:user_agent => "Gengo Ruby Library; Version #{Gengo::Config::VERSION}; Ruby Version #{RUBY_DESCRIPTION}; http://gengo.com/;",
|
@@ -52,6 +53,14 @@ module Gengo
|
|
52
53
|
OpenSSL::HMAC.hexdigest 'sha1', @opts[:private_key], ts
|
53
54
|
end
|
54
55
|
|
56
|
+
def auth_by_access_token?
|
57
|
+
@opts[:access_token] != ''
|
58
|
+
end
|
59
|
+
|
60
|
+
def access_token_bearer
|
61
|
+
"Bearer #{@opts[:access_token]}"
|
62
|
+
end
|
63
|
+
|
55
64
|
# The "GET" method; handles requesting basic data sets from Gengo and converting
|
56
65
|
# the response to a Ruby hash/object.
|
57
66
|
#
|
@@ -72,15 +81,20 @@ module Gengo
|
|
72
81
|
query[:api_key] = @opts[:public_key]
|
73
82
|
query[:ts] = Time.now.gmtime.to_i.to_s
|
74
83
|
|
75
|
-
endpoint << "?api_sig=" + signature_of(query[:ts])
|
76
|
-
endpoint << '&' + query.map { |k, v| "#{k}=#{urlencode(v)}" }.join('&')
|
77
|
-
|
78
|
-
uri = "/v#{@opts[:api_version]}/" + endpoint
|
79
84
|
headers = {
|
80
85
|
'Accept' => 'application/json',
|
81
86
|
'User-Agent' => @opts[:user_agent]
|
82
87
|
}
|
83
88
|
|
89
|
+
if auth_by_access_token?
|
90
|
+
headers.merge!('Authorization' => access_token_bearer)
|
91
|
+
end
|
92
|
+
|
93
|
+
endpoint << "?api_sig=" + signature_of(query[:ts])
|
94
|
+
endpoint << '&' + query.map { |k, v| "#{k}=#{urlencode(v)}" }.join('&')
|
95
|
+
|
96
|
+
uri = "/v#{@opts[:api_version]}/" + endpoint
|
97
|
+
|
84
98
|
if is_delete
|
85
99
|
req = Net::HTTP::Delete.new(uri, headers)
|
86
100
|
else
|
@@ -144,6 +158,10 @@ module Gengo
|
|
144
158
|
request.add_field('Accept', 'application/json')
|
145
159
|
request.add_field('User-Agent', @opts[:user_agent])
|
146
160
|
|
161
|
+
if auth_by_access_token?
|
162
|
+
request.add_field('Authorization', access_token_bearer)
|
163
|
+
end
|
164
|
+
|
147
165
|
request.content_type = 'application/x-www-form-urlencoded'
|
148
166
|
request.body = {
|
149
167
|
"api_sig" => signature_of(query[:ts]),
|
@@ -204,7 +222,12 @@ module Gengo
|
|
204
222
|
"ts" => call_timestamp
|
205
223
|
})
|
206
224
|
|
207
|
-
|
225
|
+
headers = {'Accept' => 'application/json', 'User-Agent' => @opts[:user_agent] }
|
226
|
+
if auth_by_access_token?
|
227
|
+
headers.merge!('Authorization' => access_token_bearer)
|
228
|
+
end
|
229
|
+
|
230
|
+
request = Net::HTTP::Post::Multipart.new(url.path, the_hash, headers)
|
208
231
|
|
209
232
|
if @debug
|
210
233
|
http.set_debug_output($stdout)
|
@@ -227,6 +250,14 @@ module Gengo
|
|
227
250
|
end
|
228
251
|
end
|
229
252
|
|
253
|
+
# Returns a Ruby-hash of the current account. No arguments required!
|
254
|
+
#
|
255
|
+
# Options:
|
256
|
+
# <tt>None</tt> - N/A
|
257
|
+
def getAccountMe(params = {})
|
258
|
+
self.get_from_gengo('account/me', params)
|
259
|
+
end
|
260
|
+
|
230
261
|
# Returns a Ruby-hash of the stats for the current account. No arguments required!
|
231
262
|
#
|
232
263
|
# Options:
|
@@ -283,7 +314,6 @@ module Gengo
|
|
283
314
|
# Given an ID, pulls down information concerning that job from Gengo.
|
284
315
|
#
|
285
316
|
# <tt>id</tt> - The ID of a job to check.
|
286
|
-
# <tt>pre_mt</tt> - Optional, get a machine translation if the human translation is not done.
|
287
317
|
def getTranslationJob(params = {})
|
288
318
|
id = params.delete(:id).to_s
|
289
319
|
self.get_from_gengo("translate/job/#{id}", params)
|
data/lib/gengo-ruby/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Romaine
|
@@ -61,14 +61,28 @@ dependencies:
|
|
61
61
|
requirements:
|
62
62
|
- - "~>"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '3.5'
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - "~>"
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
71
|
+
version: '3.5'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: rack
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.6'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.6'
|
72
86
|
- !ruby/object:Gem::Dependency
|
73
87
|
name: rack-test
|
74
88
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,7 +159,6 @@ files:
|
|
145
159
|
- lib/gengo-ruby/version.rb
|
146
160
|
- lib/gengo.rb
|
147
161
|
- licenses/LICENSE.txt
|
148
|
-
- test.rb
|
149
162
|
homepage: http://developers.gengo.com
|
150
163
|
licenses:
|
151
164
|
- New BSD
|
@@ -171,4 +184,3 @@ signing_key:
|
|
171
184
|
specification_version: 4
|
172
185
|
summary: A library for interfacing with the Gengo Translation API.
|
173
186
|
test_files: []
|
174
|
-
has_rdoc: true
|
data/test.rb
DELETED
@@ -1,11 +0,0 @@
|
|
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()
|