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.
- checksums.yaml +4 -4
- data/lib/bing_translator.rb +35 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa2feb9308fe7f78b458c0d01040ec3ec5fc994
|
4
|
+
data.tar.gz: a8167bc17eb99fc49e5250c7679801eca9fa8e4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f28167678917a0e032342fbb1ecac5de2b76ecb11ee8c60bcd644254342252c039b8cbf14ff7309321c8d0bb36169479caa764da5091fc93cee0590539f46d7
|
7
|
+
data.tar.gz: aeb5fd8baa22fe0756d5cfe0592b416601dad8d1b91f34f7417043c72bffd706c8c500ffdb08769d99e22e5088c75bdc7e5ec20399b8564b4763d23011dd920b
|
data/lib/bing_translator.rb
CHANGED
@@ -42,7 +42,22 @@ class BingTranslator
|
|
42
42
|
'contentType' => params[:content_type] || 'text/plain'
|
43
43
|
}
|
44
44
|
|
45
|
-
result(:translate, params)
|
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).
|
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)
|
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)
|
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
|
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
|
+
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:
|
11
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|