opener-chained-daemon 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfaaa3d8dc1f3ad59f09104ba3fd80ed7df960f804187b3e28f1e6cdaeb5e120
4
- data.tar.gz: dba40f046b26bc2ae55053d47441a29677d9c7fa4b681cb656e9cbebde03d5f6
3
+ metadata.gz: 5b39c68214bb77d796b0b7cb609d65a52344b2405e41d528b0c4753251fccc14
4
+ data.tar.gz: 005e47314b0b223b7a875112a824064be74a46de978f5c4d0e54690bb6087b70
5
5
  SHA512:
6
- metadata.gz: b8018365ade5df98bb0e25681c4697cb127461ad8163d37dab403658058fd540b23ba32ebbca346092d6ddb00cbe8eb780f8648af5ccb26cf4e75ced1a22df6e
7
- data.tar.gz: 3c3160113cd7babb0199e8e43b0c9eb5ada4190ea194db3830b2afdf3f17b61931e7705de06dff90135344488c60cef512720f3332e01f1675539e235cb8f7e1
6
+ metadata.gz: d97b590bf53342ec675e5da47b0357a2af5fcd519315eb6ca18edd75f3c480aca0c474397af78fd92d7503672dafe67b98ca94bb6ce74f17fe6cf862841cd4dd
7
+ data.tar.gz: 4cbdf973388f3e72febd98d14f86da25ad05cc312d33c50d72cbd9b10ac6072e929917b1c89de12e28b2e241cbae69ddb74f5ab43b771ba6a8e1fdcf4627b444
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require_relative '../lib/opener/chained_daemon'
5
+
6
+ begin
7
+ require 'awesome_print'
8
+ require 'pry'
9
+ binding.pry
10
+ rescue LoadError
11
+ require 'irb'
12
+ IRB.start
13
+ end
@@ -1,5 +1,6 @@
1
1
  require 'active_support/all'
2
2
  require 'oga'
3
+ require 'hashie'
3
4
  require 'google/cloud/translate'
4
5
 
5
6
  require 'opener/daemons'
@@ -15,3 +16,5 @@ require 'opener/opinion_detector_basic'
15
16
 
16
17
  require_relative 'chained_daemon/chained_daemon'
17
18
  require_relative 'chained_daemon/cli'
19
+ require_relative 'chained_daemon/microsoft_translator'
20
+
@@ -57,6 +57,8 @@ module Opener
57
57
  case translate_service params
58
58
  when :google
59
59
  raw.content = google_translator.translate raw.content, to: :en
60
+ when :microsoft
61
+ raw.content = microsoft_translator.translate raw.content, to: :en
60
62
  else
61
63
  raw.content = google_translator.translate raw.content, to: :en
62
64
  end
@@ -75,6 +77,10 @@ module Opener
75
77
  @google_translator ||= Google::Cloud.new.translate ENV['GOOGLE_TRANSLATE_TOKEN']
76
78
  end
77
79
 
80
+ def microsoft_translator
81
+ @microsoft_translator ||= MicrosoftTranslator.new
82
+ end
83
+
78
84
  private
79
85
 
80
86
  def debug_print queue, input
@@ -0,0 +1,27 @@
1
+ module Opener
2
+ class ChainedDaemon
3
+ class MicrosoftTranslator
4
+
5
+ URL = 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=%{to}'
6
+ TOKEN = ENV['MICROSOFT_TRANSLATE_TOKEN']
7
+
8
+ def initialize
9
+ @http = HTTPClient.new
10
+ end
11
+
12
+ def translate text, to: :en
13
+ url = URL % {to: to}
14
+ resp = @http.post url,
15
+ body: [{Text: text}].to_json,
16
+ header: {'Ocp-Apim-Subscription-Key' => TOKEN, 'Content-Type' => 'application/json'}
17
+
18
+ data = JSON.parse resp.body
19
+ raise data['error']['message'] if data.is_a? Hash and data['error']
20
+
21
+ data = Hashie::Mash.new data[0]
22
+ data&.translations&.first&.text
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class ChainedDaemon
3
3
 
4
- VERSION = '2.0.1'
4
+ VERSION = '2.1.0'
5
5
 
6
6
  end
7
7
  end
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'activesupport'
24
24
  spec.add_dependency 'google-cloud-translate', '~> 1.0'
25
+ spec.add_dependency 'httpclient'
26
+ spec.add_dependency 'hashie'
25
27
 
26
28
  spec.add_dependency 'opener-daemons', '~> 2.7.1'
27
29
  spec.add_dependency 'opener-callback-handler', '~> 1.0'
@@ -37,6 +39,7 @@ Gem::Specification.new do |spec|
37
39
  spec.add_development_dependency 'bundler', '~> 1.3'
38
40
  spec.add_development_dependency 'rake'
39
41
  spec.add_development_dependency 'pry'
42
+ spec.add_development_dependency 'awesome_print'
40
43
  spec.add_development_dependency 'rspec'
41
44
  spec.add_development_dependency 'rack-test'
42
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-chained-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-09 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: httpclient
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: hashie
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  requirement: !ruby/object:Gem::Requirement
43
71
  requirements:
@@ -206,6 +234,20 @@ dependencies:
206
234
  - - ">="
207
235
  - !ruby/object:Gem::Version
208
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ requirement: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ name: awesome_print
244
+ prerelease: false
245
+ type: :development
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
209
251
  - !ruby/object:Gem::Dependency
210
252
  requirement: !ruby/object:Gem::Requirement
211
253
  requirements:
@@ -240,16 +282,19 @@ executables:
240
282
  - chained-daemon
241
283
  - chained-daemon-daemon
242
284
  - chained-daemon-csv
285
+ - console
243
286
  extensions: []
244
287
  extra_rdoc_files: []
245
288
  files:
246
289
  - bin/chained-daemon
247
290
  - bin/chained-daemon-csv
248
291
  - bin/chained-daemon-daemon
292
+ - bin/console
249
293
  - exec/chained-daemon.rb
250
294
  - lib/opener/chained_daemon.rb
251
295
  - lib/opener/chained_daemon/chained_daemon.rb
252
296
  - lib/opener/chained_daemon/cli.rb
297
+ - lib/opener/chained_daemon/microsoft_translator.rb
253
298
  - lib/opener/chained_daemon/version.rb
254
299
  - opener-chained-daemon.gemspec
255
300
  homepage: