bing_translator 4.4.1 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bing_translator.rb +35 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5688ce36fd3a8290503bb1d54497866e593f62c3
4
- data.tar.gz: 6b1e4aaf3115bfedd6ec05895ec557a0af60f7f8
3
+ metadata.gz: 6aa2feb9308fe7f78b458c0d01040ec3ec5fc994
4
+ data.tar.gz: a8167bc17eb99fc49e5250c7679801eca9fa8e4d
5
5
  SHA512:
6
- metadata.gz: e417692423142d7e97eecd0a7b8b48bc02606135fe09c8b5ee2e14daf19b8ca07b897a75404ba75657dc7ecf1807f83bb1e107b12760c12e8589365be1150de9
7
- data.tar.gz: 23e842d544a2e18f42f5d9e1f6f18c3a016f2b6a8cdcda111d1bc4101e39a3fde6c3cc9daa6a4411caff1390c9dee0cc35a319a0c5111c7db75725419c0fefa6
6
+ metadata.gz: 4f28167678917a0e032342fbb1ecac5de2b76ecb11ee8c60bcd644254342252c039b8cbf14ff7309321c8d0bb36169479caa764da5091fc93cee0590539f46d7
7
+ data.tar.gz: aeb5fd8baa22fe0756d5cfe0592b416601dad8d1b91f34f7417043c72bffd706c8c500ffdb08769d99e22e5088c75bdc7e5ec20399b8564b4763d23011dd920b
@@ -42,7 +42,22 @@ class BingTranslator
42
42
  'contentType' => params[:content_type] || 'text/plain'
43
43
  }
44
44
 
45
- result(:translate, params).body[:translate_response][:translate_result]
45
+ result(:translate, params)
46
+ end
47
+
48
+ def translate_array(texts, params = {})
49
+ raise "Must provide :to." if params[:to].nil?
50
+
51
+ # Important notice: param order makes sense in SOAP. Do not reorder or delete!
52
+ params = {
53
+ 'texts' => { 'arr:string' => texts },
54
+ 'from' => params[:from].to_s,
55
+ 'to' => params[:to].to_s,
56
+ 'category' => 'general',
57
+ 'contentType' => params[:content_type] || 'text/plain'
58
+ }
59
+
60
+ array_wrap(result(:translate_array, params)[:translate_array_response]).map{|r| r[:translated_text]}
46
61
  end
47
62
 
48
63
  def detect(text)
@@ -51,7 +66,7 @@ class BingTranslator
51
66
  'language' => '',
52
67
  }
53
68
 
54
- result(:detect, params).body[:detect_response][:detect_result].to_sym
69
+ result(:detect, params).to_sym
55
70
  end
56
71
 
57
72
  # format: 'audio/wav' [default] or 'audio/mp3'
@@ -67,7 +82,7 @@ class BingTranslator
67
82
  'options' => params[:options] || 'MinSize',
68
83
  }
69
84
 
70
- uri = URI.parse(result(:speak, params).body[:speak_response][:speak_result])
85
+ uri = URI.parse(result(:speak, params))
71
86
 
72
87
  http = Net::HTTP.new(uri.host, uri.port)
73
88
  if uri.scheme == "https"
@@ -85,7 +100,7 @@ class BingTranslator
85
100
  end
86
101
 
87
102
  def supported_language_codes
88
- result(:get_languages_for_translate).body[:get_languages_for_translate_response][:get_languages_for_translate_result][:string]
103
+ result(:get_languages_for_translate)[:string]
89
104
  end
90
105
 
91
106
  def language_names(codes, locale = 'en')
@@ -93,7 +108,7 @@ class BingTranslator
93
108
  attributes 'xmlns:a' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
94
109
  end
95
110
 
96
- response.body[:get_language_names_response][:get_language_names_result][:string]
111
+ response[:string]
97
112
  end
98
113
 
99
114
  def balance
@@ -156,7 +171,7 @@ private
156
171
  # Specify SOAP namespace in tag names (see https://github.com/savonrb/savon/issues/340 )
157
172
  params = Hash[params.map{|k,v| ["v2:#{k}", v]}]
158
173
  begin
159
- soap_client.call(action, message: params, &block)
174
+ soap_client.call(action, message: params, &block).body[:"#{action}_response"][:"#{action}_result"]
160
175
  rescue AuthenticationException
161
176
  raise
162
177
  rescue StandardError => e
@@ -178,7 +193,21 @@ private
178
193
  wsdl: WSDL_URI,
179
194
  namespace: NAMESPACE_URI,
180
195
  namespace_identifier: :v2,
196
+ namespaces: {
197
+ 'xmlns:arr' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
198
+ },
181
199
  headers: {'Authorization' => "Bearer #{get_access_token['access_token']}"},
182
200
  )
183
201
  end
202
+
203
+ # Private: Array#wrap based on ActiveSupport extension
204
+ def array_wrap(object)
205
+ if object.nil?
206
+ []
207
+ elsif object.respond_to?(:to_ary)
208
+ object.to_ary || [object]
209
+ else
210
+ [object]
211
+ end
212
+ end
184
213
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricky Elrod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-19 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri