gengo-motion 1.0
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 +7 -0
- data/README.md +29 -0
- data/lib/gengo-motion.rb +8 -0
- data/lib/project/config.rb +4 -0
- data/lib/project/gengo-motion.rb +19 -0
- data/lib/project/gengo-ruby/api_handler.rb +462 -0
- data/lib/project/gengo-ruby/gengo_exception.rb +13 -0
- data/lib/project/gengo-ruby/http_client.rb +57 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97e5fe28939aed0dbb7d0b3cb249adb016027827
|
4
|
+
data.tar.gz: c4b7c4bd12e984a3e4966602ae1032b4bdbf5e19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40307c1743e0bd86767f8288ab1a1e640c06e90a479b8ede3c356baf49f6459d5c216769578dad6d0cb3192385d336d9b6c8b9d3478f0b1aa2c1565a94611fb0
|
7
|
+
data.tar.gz: a836c80d0cf08f6d986de2bf7f6b938bd1ba90728e19019f83d39b7073178e9dfba9bdf8030830ac798145baa8c0916d87c422ff0f75cc3a9b060276d0f4bb9d
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# gengo-motion
|
2
|
+
|
3
|
+
Gengo API Wrapper for RubyMotion
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'motion-gengo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install motion-gengo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/lib/gengo-motion.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# require 'rubygems'
|
2
|
+
# require 'gengo-ruby/api_handler'
|
3
|
+
# require 'gengo-ruby/gengo_exception'
|
4
|
+
|
5
|
+
# require "motion-cocoapods"
|
6
|
+
# require "bubble-wrap"
|
7
|
+
# require "afmotion"
|
8
|
+
|
9
|
+
module Gengo
|
10
|
+
# Store global config objects here - e.g, urls, etc.
|
11
|
+
module Config
|
12
|
+
# API url endpoints; replace the version at function call time to
|
13
|
+
# allow for function-by-function differences in versioning.
|
14
|
+
API_HOST = 'api.gengo.com'
|
15
|
+
SANDBOX_API_HOST = 'api.sandbox.gengo.com'
|
16
|
+
|
17
|
+
VERSION = '0.0.0'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,462 @@
|
|
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 => '2',
|
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
|
+
string.escape_url
|
49
|
+
end
|
50
|
+
|
51
|
+
# Creates an HMAC::SHA1 signature, signing the timestamp with the private key.
|
52
|
+
def signature_of(ts)
|
53
|
+
# OpenSSL::HMAC.hexdigest 'sha1', @opts[:private_key], ts
|
54
|
+
ts.SHA1HMACWithKey(@opts[:private_key])
|
55
|
+
end
|
56
|
+
|
57
|
+
# The "GET" method; handles requesting basic data sets from Gengo and converting
|
58
|
+
# the response to a Ruby hash/object.
|
59
|
+
#
|
60
|
+
# Options:
|
61
|
+
# <tt>endpoint</tt> - String/URL to request data from.
|
62
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
63
|
+
def get_from_gengo(endpoint, params = {})
|
64
|
+
# Do this small check here...
|
65
|
+
is_delete = params.delete(:is_delete)
|
66
|
+
is_download_file = params.delete(:is_download)
|
67
|
+
|
68
|
+
# The first part of the object we're going to encode and use in our request to Gengo. The signing process
|
69
|
+
# is a little annoying at the moment, so bear with us...
|
70
|
+
query = params.reduce({}) do |hash_thus_far, (param_key, param_value)|
|
71
|
+
hash_thus_far.merge(param_key.to_sym => param_value.to_s)
|
72
|
+
end
|
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
|
+
#========================================
|
81
|
+
|
82
|
+
# uri = "/v#{@opts[:api_version]}/" + endpoint
|
83
|
+
# headers = {
|
84
|
+
# 'Accept' => 'application/json',
|
85
|
+
# 'User-Agent' => @opts[:user_agent]
|
86
|
+
# }
|
87
|
+
|
88
|
+
uri = "http://#{@api_host}/v#{@opts[:api_version]}/#{endpoint}"
|
89
|
+
headers = {
|
90
|
+
'Accept' => 'application/json',
|
91
|
+
'User-Agent' => @opts[:user_agent],
|
92
|
+
"Cache-Control" => "no-cache"
|
93
|
+
}
|
94
|
+
|
95
|
+
# if is_delete
|
96
|
+
# req = Net::HTTP::Delete.new(uri, headers)
|
97
|
+
# else
|
98
|
+
# req = Net::HTTP::Get.new(uri, headers)
|
99
|
+
# end
|
100
|
+
|
101
|
+
# http = Net::HTTP.start(@api_host, 80)
|
102
|
+
|
103
|
+
# if @debug
|
104
|
+
# http.set_debug_output($stdout)
|
105
|
+
# end
|
106
|
+
# http.read_timeout = 5*60
|
107
|
+
# resp = http.request(req)
|
108
|
+
|
109
|
+
# if is_download_file.nil?
|
110
|
+
# json = JSON.parse(resp.body)
|
111
|
+
# if json['opstat'] != 'ok'
|
112
|
+
# raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
113
|
+
# end
|
114
|
+
|
115
|
+
# # Return it if there are no problems, nice...
|
116
|
+
# return json
|
117
|
+
# else
|
118
|
+
# return resp.body
|
119
|
+
# end
|
120
|
+
|
121
|
+
#=======================================
|
122
|
+
|
123
|
+
|
124
|
+
http = Gengo::HTTPClient.new
|
125
|
+
http.headers = headers
|
126
|
+
http.get(uri) do |resp|
|
127
|
+
if is_download_file.nil?
|
128
|
+
json = BW::JSON.parse(resp.content)
|
129
|
+
if json['opstat'] != 'ok'
|
130
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
131
|
+
end
|
132
|
+
|
133
|
+
# Return it if there are no problems, nice...
|
134
|
+
return json
|
135
|
+
else
|
136
|
+
return resp.content
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
#==========================================
|
141
|
+
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
# The "POST" method; handles shuttling up encoded job data to Gengo
|
146
|
+
# for translation and such. Somewhat similar to the above methods, but depending on the scenario
|
147
|
+
# can get some strange exceptions, so we're gonna keep them fairly separate for the time being. Consider
|
148
|
+
# for a merger down the road...
|
149
|
+
#
|
150
|
+
# Options:
|
151
|
+
# <tt>endpoint</tt> - String/URL to post data to.
|
152
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
153
|
+
def send_to_gengo(endpoint, params = {})
|
154
|
+
|
155
|
+
# Check if this is a put
|
156
|
+
is_put = params.delete(:is_put)
|
157
|
+
|
158
|
+
query = {
|
159
|
+
:api_key => @opts[:public_key],
|
160
|
+
:data => params.to_json.gsub('"', '\"'),
|
161
|
+
:ts => Time.now.gmtime.to_i.to_s
|
162
|
+
}
|
163
|
+
|
164
|
+
url = URI.parse("http://#{@api_host}/v#{@opts[:api_version]}/#{endpoint}")
|
165
|
+
http = Net::HTTP.new(url.host, url.port)
|
166
|
+
http.read_timeout = 5*60
|
167
|
+
if is_put
|
168
|
+
request = Net::HTTP::Put.new(url.path)
|
169
|
+
else
|
170
|
+
request = Net::HTTP::Post.new(url.path)
|
171
|
+
end
|
172
|
+
|
173
|
+
request.add_field('Accept', 'application/json')
|
174
|
+
request.add_field('User-Agent', @opts[:user_agent])
|
175
|
+
|
176
|
+
request.content_type = 'application/x-www-form-urlencoded'
|
177
|
+
request.body = {
|
178
|
+
"api_sig" => signature_of(query[:ts]),
|
179
|
+
"api_key" => urlencode(@opts[:public_key]),
|
180
|
+
"data" => urlencode(params.to_json.gsub('\\', '\\\\')),
|
181
|
+
"ts" => query[:ts].to_i.to_s
|
182
|
+
}.map { |k, v| "#{k}=#{v}" }.flatten.join('&')
|
183
|
+
|
184
|
+
if @debug
|
185
|
+
http.set_debug_output($stdout)
|
186
|
+
end
|
187
|
+
|
188
|
+
resp = http.request(request)
|
189
|
+
|
190
|
+
case resp
|
191
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
192
|
+
json = JSON.parse(resp.body)
|
193
|
+
|
194
|
+
if json['opstat'] != 'ok'
|
195
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
196
|
+
end
|
197
|
+
|
198
|
+
# Return it if there are no problems, nice...
|
199
|
+
json
|
200
|
+
else
|
201
|
+
resp.error!
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# The "UPLOAD" method; handles sending a file to the quote method
|
206
|
+
#
|
207
|
+
# Options:
|
208
|
+
# <tt>endpoint</tt> - String/URL to post data to.
|
209
|
+
# <tt>params</tt> - Data necessary for request (keys, etc). Generally taken care of by the requesting instance.
|
210
|
+
def upload_to_gengo(endpoint, params = {})
|
211
|
+
|
212
|
+
# prepare the file_hash and append file_key to each job payload
|
213
|
+
files_hash = params[:jobs].each_value.reduce({}) do |hash_thus_far, job_values|
|
214
|
+
if job_values[:file_path]
|
215
|
+
job_mime_type = MIME::Types.type_for(job_values[:file_path]).first.content_type
|
216
|
+
file_hash_key = "file_#{hash_thus_far.length.to_s}".to_sym
|
217
|
+
job_values[:file_key] = file_hash_key
|
218
|
+
hash_thus_far[file_hash_key] = UploadIO.new(File.open(job_values[:file_path]), job_mime_type, File.basename(job_values[:file_path]))
|
219
|
+
end
|
220
|
+
hash_thus_far
|
221
|
+
end
|
222
|
+
|
223
|
+
url = URI.parse("http://#{@api_host}/v#{@opts[:api_version]}/#{endpoint}")
|
224
|
+
|
225
|
+
http = Net::HTTP.new(url.host, url.port)
|
226
|
+
http.read_timeout = 5*60
|
227
|
+
|
228
|
+
call_timestamp = Time.now.gmtime.to_i.to_s
|
229
|
+
|
230
|
+
the_hash = files_hash.merge({
|
231
|
+
"api_sig" => signature_of(call_timestamp),
|
232
|
+
"api_key" => @opts[:public_key],
|
233
|
+
"data" =>params.to_json.gsub('\\', '\\\\'),
|
234
|
+
"ts" => call_timestamp
|
235
|
+
})
|
236
|
+
|
237
|
+
request = Net::HTTP::Post::Multipart.new(url.path, the_hash, {'Accept' => 'application/json', 'User-Agent' => @opts[:user_agent] })
|
238
|
+
|
239
|
+
if @debug
|
240
|
+
http.set_debug_output($stdout)
|
241
|
+
end
|
242
|
+
|
243
|
+
resp = http.request(request)
|
244
|
+
|
245
|
+
case resp
|
246
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
247
|
+
json = JSON.parse(resp.body)
|
248
|
+
|
249
|
+
if json['opstat'] != 'ok'
|
250
|
+
raise Gengo::Exception.new(json['opstat'], json['err']['code'].to_i, json['err']['msg'])
|
251
|
+
end
|
252
|
+
|
253
|
+
# Return it if there are no problems, nice...
|
254
|
+
json
|
255
|
+
else
|
256
|
+
resp.error!
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns a Ruby-hash of the stats for the current account. No arguments required!
|
261
|
+
#
|
262
|
+
# Options:
|
263
|
+
# <tt>None</tt> - N/A
|
264
|
+
def getAccountStats(params = {})
|
265
|
+
self.get_from_gengo('account/stats', params)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Returns a Ruby-hash of the balance for the authenticated account. No args required!
|
269
|
+
#
|
270
|
+
# Options:
|
271
|
+
# <tt>None</tt> - N/A
|
272
|
+
def getAccountBalance(params = {})
|
273
|
+
self.get_from_gengo('account/balance', params)
|
274
|
+
end
|
275
|
+
|
276
|
+
# Returns an array of preferred translators for the current account by language pair. No args required!
|
277
|
+
#
|
278
|
+
# Options:
|
279
|
+
# <tt>None</tt> - N/A
|
280
|
+
def getAccountPreferredTranslators(params = {})
|
281
|
+
self.get_from_gengo('account/preferred_translators', params)
|
282
|
+
end
|
283
|
+
|
284
|
+
# Much like the above, but takes a hash titled "jobs" that is multiple jobs, each with their own unique key.
|
285
|
+
#
|
286
|
+
# Options:
|
287
|
+
# <tt>jobs</tt> - "Jobs" is a hash containing further hashes; each further hash is a job. This is best seen in the example code.
|
288
|
+
def postTranslationJobs(params = {})
|
289
|
+
self.send_to_gengo('translate/jobs', params)
|
290
|
+
end
|
291
|
+
|
292
|
+
# Updates an already submitted job.
|
293
|
+
#
|
294
|
+
# Options:
|
295
|
+
# <tt>id</tt> - The ID of a job to update.
|
296
|
+
# <tt>action</tt> - A hash describing the update to this job. See the examples for further documentation.
|
297
|
+
def updateTranslationJob(params = {})
|
298
|
+
params[:is_put] = true
|
299
|
+
self.send_to_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
300
|
+
end
|
301
|
+
|
302
|
+
# Updates a group of already submitted jobs.
|
303
|
+
#
|
304
|
+
# Options:
|
305
|
+
# <tt>jobs</tt> - An Array of job objects to update (job objects or ids)
|
306
|
+
# <tt>action</tt> - A String describing the update to this job. "approved", "rejected", etc - see Gengo docs.
|
307
|
+
def updateTranslationJobs(params = {})
|
308
|
+
params[:is_put] = true
|
309
|
+
self.send_to_gengo('translate/jobs', {:jobs => params[:jobs], :action => params[:action]})
|
310
|
+
end
|
311
|
+
|
312
|
+
# Given an ID, pulls down information concerning that job from Gengo.
|
313
|
+
#
|
314
|
+
# <tt>id</tt> - The ID of a job to check.
|
315
|
+
# <tt>pre_mt</tt> - Optional, get a machine translation if the human translation is not done.
|
316
|
+
def getTranslationJob(params = {})
|
317
|
+
self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
318
|
+
end
|
319
|
+
|
320
|
+
# Pulls down a list of recently submitted jobs, allows some filters.
|
321
|
+
#
|
322
|
+
# <tt>status</tt> - Optional. "unpaid", "available", "pending", "reviewable", "approved", "rejected", or "canceled".
|
323
|
+
# <tt>timestamp_after</tt> - Optional. Epoch timestamp from which to filter submitted jobs.
|
324
|
+
# <tt>count</tt> - Optional. Defaults to 10.
|
325
|
+
def getTranslationJobs(params = {})
|
326
|
+
if params[:ids] and params[:ids].kind_of?(Array)
|
327
|
+
params[:ids] = params[:ids].map { |i| i.to_s() }.join(',')
|
328
|
+
self.get_from_gengo('translate/jobs/:ids'.gsub(':ids', params.delete(:ids)))
|
329
|
+
else
|
330
|
+
self.get_from_gengo('translate/jobs', params)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
# Pulls a group of jobs that were previously submitted together.
|
335
|
+
#
|
336
|
+
# <tt>id</tt> - Required, the ID of a job that you want the batch/group of.
|
337
|
+
def getTranslationOrderJobs(params = {})
|
338
|
+
self.get_from_gengo('translate/order/:order_id'.gsub(':order_id', params.delete(:order_id).to_s), params)
|
339
|
+
end
|
340
|
+
|
341
|
+
# Mirrors the bulk Translation call, but just returns an estimated cost.
|
342
|
+
def determineTranslationCost(params = {})
|
343
|
+
is_upload = params.delete(:is_upload)
|
344
|
+
if is_upload
|
345
|
+
self.upload_to_gengo('translate/service/quote/file', params)
|
346
|
+
else
|
347
|
+
self.send_to_gengo('translate/service/quote', params)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# Mirrors the bulk Translation call, but just returns an estimated cost.
|
352
|
+
def getTranslationQuote(params = {})
|
353
|
+
determineTranslationCost(params)
|
354
|
+
end
|
355
|
+
|
356
|
+
# Post a comment for a translator or Gengo on a job.
|
357
|
+
#
|
358
|
+
# Options:
|
359
|
+
# <tt>id</tt> - The ID of the job you're commenting on.
|
360
|
+
# <tt>comment</tt> - The comment to put on the job.
|
361
|
+
def postTranslationJobComment(params = {})
|
362
|
+
self.send_to_gengo('translate/job/:id/comment'.gsub(':id', params.delete(:id).to_s), params)
|
363
|
+
end
|
364
|
+
|
365
|
+
# Get all comments (the history) from a given job.
|
366
|
+
#
|
367
|
+
# Options:
|
368
|
+
# <tt>id</tt> - The ID of the job to get comments for.
|
369
|
+
def getTranslationJobComments(params = {})
|
370
|
+
self.get_from_gengo('translate/job/:id/comments'.gsub(':id', params.delete(:id).to_s), params)
|
371
|
+
end
|
372
|
+
|
373
|
+
# Returns the feedback you've submitted for a given job.
|
374
|
+
#
|
375
|
+
# Options:
|
376
|
+
# <tt>id</tt> - The ID of the translation job you're retrieving comments from.
|
377
|
+
def getTranslationJobFeedback(params = {})
|
378
|
+
self.get_from_gengo('translate/job/:id/feedback'.gsub(':id', params.delete(:id).to_s), params)
|
379
|
+
end
|
380
|
+
|
381
|
+
# Gets a list of the revision resources for a job. Revisions are created each time a translator updates the text.
|
382
|
+
#
|
383
|
+
# Options:
|
384
|
+
# <tt>id</tt> - The ID of the translation job you're getting revisions from.
|
385
|
+
def getTranslationJobRevisions(params = {})
|
386
|
+
self.get_from_gengo('translate/job/:id/revisions'.gsub(':id', params.delete(:id).to_s), params)
|
387
|
+
end
|
388
|
+
|
389
|
+
# Get a specific revision to a job.
|
390
|
+
#
|
391
|
+
# Options:
|
392
|
+
# <tt>id</tt> - The ID of the translation job you're getting revisions from.
|
393
|
+
# <tt>rev_id</tt> - The ID of the revision you're looking up.
|
394
|
+
def getTranslationJobRevision(params = {})
|
395
|
+
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)
|
396
|
+
end
|
397
|
+
|
398
|
+
# Deletes an order, cancelling all available jobs.
|
399
|
+
#
|
400
|
+
# This method is EXPERIMENTAL
|
401
|
+
#
|
402
|
+
# Options:
|
403
|
+
# <tt>id</tt> - The ID of the order you want to delete.
|
404
|
+
def deleteTranslationOrder(params = {})
|
405
|
+
params[:is_delete] = true
|
406
|
+
self.get_from_gengo('translate/order/:id'.gsub(':id', params.delete(:id).to_s), params)
|
407
|
+
end
|
408
|
+
|
409
|
+
# Deletes a job.
|
410
|
+
#
|
411
|
+
# Options:
|
412
|
+
# <tt>id</tt> - The ID of the job you want to delete.
|
413
|
+
def deleteTranslationJob(params = {})
|
414
|
+
params[:is_delete] = true
|
415
|
+
self.get_from_gengo('translate/job/:id'.gsub(':id', params.delete(:id).to_s), params)
|
416
|
+
end
|
417
|
+
|
418
|
+
# Deletes multiple jobs.
|
419
|
+
#
|
420
|
+
# Options:
|
421
|
+
# <tt>ids</tt> - An Array of job IDs you want to delete.
|
422
|
+
def deleteTranslationJobs(params = {})
|
423
|
+
if params[:ids] and params[:ids].kind_of?(Array)
|
424
|
+
params[:job_ids] = params[:ids].map { |i| i.to_s() }.join(',')
|
425
|
+
params.delete(:ids)
|
426
|
+
end
|
427
|
+
|
428
|
+
params[:is_delete] = true
|
429
|
+
self.get_from_gengo('translate/jobs', params)
|
430
|
+
end
|
431
|
+
|
432
|
+
# Gets information about currently supported language pairs.
|
433
|
+
#
|
434
|
+
# Options:
|
435
|
+
# <tt>lc_src</tt> - Optional language code to filter on.
|
436
|
+
def getServiceLanguagePairs(params = {})
|
437
|
+
self.get_from_gengo('translate/service/language_pairs', params)
|
438
|
+
end
|
439
|
+
|
440
|
+
# Pulls down currently supported languages.
|
441
|
+
def getServiceLanguages(params = {})
|
442
|
+
self.get_from_gengo('translate/service/languages', params)
|
443
|
+
end
|
444
|
+
|
445
|
+
# Gets list of glossaries that belongs to the authenticated user
|
446
|
+
def getGlossaryList(params = {})
|
447
|
+
self.get_from_gengo('translate/glossary', params)
|
448
|
+
end
|
449
|
+
|
450
|
+
# Gets one glossary that belongs to the authenticated user
|
451
|
+
def getGlossary(params = {})
|
452
|
+
self.get_from_gengo('translate/glossary/:id'.gsub(':id', params.delete(:id).to_s), params)
|
453
|
+
end
|
454
|
+
|
455
|
+
# Downloads one glossary that belongs to the authenticated user
|
456
|
+
def getGlossaryFile(params = {})
|
457
|
+
params[:is_download] = true
|
458
|
+
self.get_from_gengo('translate/glossary/download/:id'.gsub(':id', params.delete(:id).to_s), params)
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
end
|
@@ -0,0 +1,13 @@
|
|
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
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Gengo
|
2
|
+
class HTTPClient
|
3
|
+
attr_accessor :headers, :cache_policy, :timeout
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@headers = {}
|
7
|
+
@cache_policy = NSURLRequestUseProtocolCachePolicy
|
8
|
+
@timeout = 30.0
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(url, &block)
|
12
|
+
request = NSURLRequest.alloc.initWithURL(url.nsurl, cachePolicy:@cache_policy, timeoutInterval:@timeout)
|
13
|
+
|
14
|
+
if self.headers.size > 0
|
15
|
+
mutableRequest = request.mutableCopy
|
16
|
+
self.headers.each { |k, v| mutableRequest.addValue(v, forHTTPHeaderField:k) }
|
17
|
+
request = mutableRequest.copy
|
18
|
+
end
|
19
|
+
|
20
|
+
error = Pointer.new(:object)
|
21
|
+
response = Pointer.new(:object)
|
22
|
+
body = NSURLConnection.sendSynchronousRequest(request, returningResponse:response, error:error)
|
23
|
+
|
24
|
+
res = Response.new
|
25
|
+
res.error = error[0] ? error[0] : nil
|
26
|
+
res.status_code = response[0] ? response[0].statusCode : nil
|
27
|
+
res.body = body
|
28
|
+
|
29
|
+
block.call(res)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Response
|
33
|
+
attr_accessor :status_code, :body, :error
|
34
|
+
|
35
|
+
def ok?
|
36
|
+
if error.present?
|
37
|
+
false
|
38
|
+
else
|
39
|
+
self.status_code.to_s =~ /2\d\d/ ? true : false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def message
|
44
|
+
if error.present?
|
45
|
+
error.localizedDescription
|
46
|
+
else
|
47
|
+
self.status_code.nil? ? nil : NSHTTPURLResponse.localizedStringForStatusCode(status_code)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def content
|
52
|
+
return nil if not body
|
53
|
+
body.to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gengo-motion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toshiaki Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: afmotion
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bubble-wrap
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: motion-cocoapods
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cocoapods
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sugarcube
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Gengo API wrapper for RubyMotion
|
98
|
+
email:
|
99
|
+
- toshiaki.takahashi@gengo.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- lib/gengo-motion.rb
|
106
|
+
- lib/project/config.rb
|
107
|
+
- lib/project/gengo-motion.rb
|
108
|
+
- lib/project/gengo-ruby/api_handler.rb
|
109
|
+
- lib/project/gengo-ruby/gengo_exception.rb
|
110
|
+
- lib/project/gengo-ruby/http_client.rb
|
111
|
+
homepage: http://gengo.com/developers/
|
112
|
+
licenses:
|
113
|
+
- New BSD License
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.1.10
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: ''
|
135
|
+
test_files: []
|