translationApiClient 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ require 'httpadapter/adapters/typhoeus'
2
+ require 'rack/request'
3
+ require 'rack/multipart'
4
+
5
+ module TranslationApiClient
6
+ module Swagger
7
+ class Response
8
+ require 'json'
9
+
10
+
11
+ attr_accessor :raw
12
+
13
+ def initialize(raw)
14
+ self.raw = raw
15
+
16
+ case self.code
17
+ when 500..510 then raise(ServerError, self.error_message)
18
+ when 299..426 then raise(ClientError, self.error_message)
19
+ end
20
+ end
21
+
22
+ def code
23
+ raw.code
24
+ end
25
+
26
+ # Account for error messages that take different forms...
27
+ def error_message
28
+ body['message']
29
+ rescue
30
+ body
31
+ end
32
+
33
+ # If body is JSON, parse it
34
+ # Otherwise return raw string
35
+ def body
36
+ if headers["Content-Type"] && (headers["Content-Type"].include? "multipart/")
37
+ adapter = HTTPAdapter::TyphoeusAdapter.new
38
+
39
+ result = adapter.adapt_response(raw)
40
+ req = Rack::Request.new(result)
41
+ parts = req.env[2][0].force_encoding("UTF-8").split("--"+headers["Content-Type"][27...67])
42
+ parts.delete_if {|x| !x.include? "part-name: "}
43
+ parts.map! { |value|
44
+ arr = value.split(' ')
45
+ arr[0] = ''
46
+ arr[1] = '"'+arr[1]+'":'
47
+ if arr[2][0] != '{'
48
+ for i in 2..arr.length-1
49
+ arr[i] = arr[i].gsub('"', '\"')
50
+ end
51
+ arr[2] = '{ "ouput":"'+arr[2]
52
+ end
53
+ if arr[-1][-1] != '}'
54
+ arr[-1] = arr[-1]+'"}'
55
+ end
56
+ arr[-1] = arr[-1]+','
57
+ arr = arr.join(" ")
58
+ value = arr
59
+ }
60
+ parts = parts.join(" ").sub! /\,$/, ''
61
+
62
+ parts = "{"+parts+'}'
63
+ #JSON.parse(parts)
64
+ #JSON.parse req.env[2].gsub('=>', ':')
65
+ puts parts#JSON.parse(parts)
66
+ # Rack::Multipart.parse_multipart(req.env)
67
+ result
68
+
69
+ else
70
+ begin
71
+ JSON.parse(raw.body, :symbolize_names => true)
72
+ rescue
73
+ raw.body
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ # `headers_hash` is a Typhoeus-specific extension of Hash,
80
+ # so simplify it back into a regular old Hash.
81
+ def headers
82
+ h = {}
83
+ raw.headers_hash.each {|k,v| h[k] = v }
84
+ h
85
+ end
86
+
87
+ # Extract the response format from the header hash
88
+ # e.g. {'Content-Type' => 'application/json'}
89
+ def format
90
+ headers['Content-Type'].split("/").last.downcase
91
+ end
92
+
93
+ def json?
94
+ format == 'json'
95
+ end
96
+
97
+ def xml?
98
+ format == 'xml'
99
+ end
100
+
101
+ def pretty_body
102
+ return unless body.present?
103
+ case format
104
+ when 'json' then JSON.pretty_generate(body).gsub(/\n/, '<br/>')
105
+ end
106
+ end
107
+
108
+ def pretty_headers
109
+ JSON.pretty_generate(headers).gsub(/\n/, '<br/>')
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ module TranslationApiClient
2
+ module Swagger
3
+ VERSION = "1.0.2"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ The new environmental review ordered by the State Department likely would push off any decision until 2013, after next year's elections, though officials denied that politics was involved in the decision.
2
+ It could have been ten times its size, could have been the Microsoft of the 90s...
3
+ "That's one of the key things the new President should attend to."
4
+ "They have a natural hedge," he said.
5
+ One of the men wore a yellow t-shirt with black jeans, with no shoes, and near him there was one man with white under vest.
6
+ I think all of us feel a bit disconnected from the word grunge.
7
+ Toyota or Sony, for example, blamed the yen for their weak results between July and September.
8
+ IBM's company motto is to change everything, except for its values.
9
+ The men, ranging in age from 15 to 25, had sprayed a railway carriage at Hohenschönhausener-Grenzgraben.
10
+ Two days after the suspension of Syria from membership of the Arab League, the European Union has reinforced its sanctions against Damascus, whilst Syria's neighbours Turkey and Jordan, came out in favour of president Assad's departure.
11
+ Later, the family sent a note asking for an apology from LaBelle but got no response.
12
+ This means that it is nothing special anymore, but it cannot be considered a negative.
13
+ In August, the local United Nations headquarters will be its first international target.
14
+ In the scene, Peters, a well known Canadian comedian of Indian origin who recently appeared as a presenter on the tour of "My Violent Torpedo of Truth" by Charlie Sheen appears as Joseph.
15
+ The nuclear industry will draw lessons from this accident, as it has from its two predecessors.
16
+ He encouraged the Blues from the age of 7 years and the victorious campaigns of 1998 and 2000.
17
+ In the same way as a surgeon would find it difficult to work in a country with a shortage of anaesthetists, the complementarities existing between locals and immigrants bring it about that the arrival of immigrants has a positive effect on the pay of locals.
18
+ A good idea, provided that it will, prove realistic this time.
19
+ "We have Schengen area, and we already have an institute of reinforced cooperation."
20
+ The boy was not accompanied by adults.
21
+ Tales of cheating on school and college tests are rife.
22
+ M. Monti undertook that once in office he would work hard to ensure that Italy would once again become a protagonist in Europe.
23
+ If you boss your partner around several times a day, he may find it very annoying.
24
+ However, she does not want to wait any longer, and set clear rules for her future life.
25
+ Pelta Promised New FAČR Regulations That Would Avoid Election Mate
26
+ They also realize that the anger that returning troops faced in the latter years of the Vietnam War was far worse.
27
+ The ex President Alberto Fujimori was hospitalized Tuesday in a public hospital in order to be evaluated for the loss of muscle strength that occurs in the legs, informed his family doctor.
28
+ For detailed information please visit festival web pages at: www.festaacademica.cz
29
+ Being cigar-shaped, it is introduced inside the 1-metre wide pipeline, and it is pushed along by the gas.
30
+ Jon Huntsman, Obama's former ambassador to China and the only candidate with a vision of a sophisticated foreign policy, has failed to suppress an attitude which flatters the emotions.
31
+ Both teams found it difficult to join in the combination; the game remained around the mid-field line most of the time.
32
+ Thank you for staying with us through all these years.
33
+ At one point, a piece of plywood came flying from the crowd.
@@ -0,0 +1,66 @@
1
+ require 'rspec'
2
+ require 'httpadapter'
3
+
4
+ require_relative '../lib/translationApiClient'
5
+
6
+ describe "TranslationApiClient" do
7
+ before :all do
8
+ TranslationApiClient::Swagger.configure do |configuration|
9
+ configuration.host = "https://api-platform.systran.net"
10
+ if File.exists?("./apiKey.txt")
11
+ key = File.read("./apiKey.txt", :encoding => 'UTF-8')
12
+ if key.length > 0
13
+ configuration.key = key
14
+ else
15
+ raise "The apiKey.txt file is empty"
16
+ end
17
+ else
18
+ raise "The apiKey.txt file doesn't exist"
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ describe "Configuration" do
25
+ it "assures the user has a correct client configuration" do
26
+ expect(TranslationApiClient::Swagger.configuration.key.length).to be_between(10, 100)
27
+ end
28
+ end
29
+ describe "TranslationApi" do
30
+ it "Lists language pairs in which translation is supported." do
31
+ result = TranslationApiClient::TranslationApi.translation_supported_languages_get
32
+ expect(result.language_pairs).not_to be_empty
33
+ end
34
+ it "Lists profiles available for translation." do
35
+ result = TranslationApiClient::TranslationApi.translation_profile_get
36
+ expect(result.profiles).not_to be_empty
37
+ end
38
+ it "Translates text from source language to target language" do
39
+ result = TranslationApiClient::TranslationApi.translation_translate_get("The quick brown fox jumps over the lazy dog", "fr")
40
+ expect(result.outputs).not_to be_empty
41
+ end
42
+ it "Translates text from source language to target language with annotations and source" do
43
+ result = TranslationApiClient::TranslationApi.translation_translate_get("The quick brown fox jumps over the lazy dog", "fr", {:with_source => true, :with_annotations => true})
44
+ expect(result.outputs).not_to be_empty
45
+ end
46
+ it "Synchronously translates a file from source language to target language" do
47
+ result = TranslationApiClient::TranslationApi.translation_translate_file_get(File.open("./spec/sample.txt","r"), "fr", {:with_source => true, :with_annotations => true})
48
+ expect(result).not_to be_empty
49
+ end
50
+ it "Asynchronously translates a file from source language to target language" do
51
+ result = TranslationApiClient::TranslationApi.translation_translate_file_get(File.open("./spec/sample.txt","r"), "fr", {:async => true})
52
+ expect(result.requestId).to be_truthy
53
+ end
54
+ it "Gets the status of an asynchronous translation request" do
55
+ request = TranslationApiClient::TranslationApi.translation_translate_file_get(File.open("./spec/sample.txt","r"), "fr", {:async => true})
56
+ result = TranslationApiClient::TranslationApi.translation_translate_status_get(request.requestId)
57
+ expect(result).to be_truthy
58
+ end
59
+ it "Cancels an asynchronous translation request" do
60
+ request = TranslationApiClient::TranslationApi.translation_translate_file_get(File.open("./spec/sample.txt","r"), "fr", {:async => true})
61
+ result = TranslationApiClient::TranslationApi.translation_translate_cancel_get(request.requestId)
62
+ expect(result).to be_truthy
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "TranslationApi_client/swagger/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "translationApiClient"
7
+ s.version = '1.0.3'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Systran"]
10
+ s.email = "support-professional@systransoft.com"
11
+ s.homepage = "http://www.systransoft.com/"
12
+ s.summary = %q{A ruby wrapper for the Systran Translation platform APIs}
13
+ s.description = %q{This gem maps to the translation swagger API}
14
+ s.license = "Apache-2.0"
15
+
16
+ s.add_runtime_dependency 'typhoeus', '~> 0.2', '>= 0.2.1'
17
+ s.add_runtime_dependency 'addressable', '~> 2.2', '>= 2.2.4'
18
+ s.add_runtime_dependency 'json', '~> 1.4', '>= 1.4.6'
19
+ s.add_runtime_dependency 'httpadapter', '~> 1.0.1'
20
+
21
+
22
+ s.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
23
+ s.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.3'
24
+ s.add_development_dependency 'webmock', '~> 1.6', '>= 1.6.2'
25
+ s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
26
+ s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
27
+ s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
28
+ s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.10'
29
+
30
+
31
+ s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }
32
+ s.test_files = `find spec/*`.split("\n")
33
+ s.executables = []
34
+ s.require_paths = ["lib"]
35
+ end
metadata ADDED
@@ -0,0 +1,284 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translationApiClient
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Systran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: addressable
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.2.4
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.2.4
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.4'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.4.6
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.4'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.4.6
73
+ - !ruby/object:Gem::Dependency
74
+ name: httpadapter
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 1.0.1
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 1.0.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: rspec
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '3.2'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.2.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.2'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 3.2.0
107
+ - !ruby/object:Gem::Dependency
108
+ name: vcr
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '2.9'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.9.3
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.9'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.9.3
127
+ - !ruby/object:Gem::Dependency
128
+ name: webmock
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '1.6'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 1.6.2
137
+ type: :development
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '1.6'
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 1.6.2
147
+ - !ruby/object:Gem::Dependency
148
+ name: autotest
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '4.4'
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 4.4.6
157
+ type: :development
158
+ prerelease: false
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: '4.4'
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 4.4.6
167
+ - !ruby/object:Gem::Dependency
168
+ name: autotest-rails-pure
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '4.1'
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: 4.1.2
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - "~>"
182
+ - !ruby/object:Gem::Version
183
+ version: '4.1'
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: 4.1.2
187
+ - !ruby/object:Gem::Dependency
188
+ name: autotest-growl
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '0.2'
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 0.2.16
197
+ type: :development
198
+ prerelease: false
199
+ version_requirements: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - "~>"
202
+ - !ruby/object:Gem::Version
203
+ version: '0.2'
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: 0.2.16
207
+ - !ruby/object:Gem::Dependency
208
+ name: autotest-fsevent
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '0.2'
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 0.2.10
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - "~>"
222
+ - !ruby/object:Gem::Version
223
+ version: '0.2'
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 0.2.10
227
+ description: This gem maps to the translation swagger API
228
+ email: support-professional@systransoft.com
229
+ executables: []
230
+ extensions: []
231
+ extra_rdoc_files: []
232
+ files:
233
+ - Gemfile
234
+ - LICENCE.txt
235
+ - README.md
236
+ - apiKey.txt
237
+ - lib/translationApiClient.rb
238
+ - lib/translationApi_client/api/translation_api.rb
239
+ - lib/translationApi_client/models/base_object.rb
240
+ - lib/translationApi_client/models/language_pair.rb
241
+ - lib/translationApi_client/models/profile.rb
242
+ - lib/translationApi_client/models/profile_id.rb
243
+ - lib/translationApi_client/models/profiles_response.rb
244
+ - lib/translationApi_client/models/supported_language_response.rb
245
+ - lib/translationApi_client/models/translation_cancel.rb
246
+ - lib/translationApi_client/models/translation_output.rb
247
+ - lib/translationApi_client/models/translation_response.rb
248
+ - lib/translationApi_client/models/translation_status.rb
249
+ - lib/translationApi_client/monkey.rb
250
+ - lib/translationApi_client/swagger.rb
251
+ - lib/translationApi_client/swagger/configuration.rb
252
+ - lib/translationApi_client/swagger/request.rb
253
+ - lib/translationApi_client/swagger/response.rb
254
+ - lib/translationApi_client/swagger/version.rb
255
+ - spec/sample.txt
256
+ - spec/translationApiClient_spec.rb
257
+ - translationApiClient.gemspec
258
+ homepage: http://www.systransoft.com/
259
+ licenses:
260
+ - Apache-2.0
261
+ metadata: {}
262
+ post_install_message:
263
+ rdoc_options: []
264
+ require_paths:
265
+ - lib
266
+ required_ruby_version: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
271
+ required_rubygems_version: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - ">="
274
+ - !ruby/object:Gem::Version
275
+ version: '0'
276
+ requirements: []
277
+ rubyforge_project:
278
+ rubygems_version: 2.6.8
279
+ signing_key:
280
+ specification_version: 4
281
+ summary: A ruby wrapper for the Systran Translation platform APIs
282
+ test_files:
283
+ - spec/sample.txt
284
+ - spec/translationApiClient_spec.rb