bing_translator 3.4.0 → 4.0.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 +5 -5
- 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: 215d7a5fcf887591e5b6d7e8133cc995ae0e656c
|
4
|
+
data.tar.gz: 1f02356a8a7c04cba1ec36184c2481b8d3199904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c31d2e26d1c7a606c37f9cda72ddd220ae25598311b6d28fc3d87b3fd0fab81c35480c2427ef3101215beebc33ed335482f6102b26a129fea4f109fb16cc678d
|
7
|
+
data.tar.gz: ae3854820d91eee8a22ba7bf3ef9cbf5d571f3d7602e9d9839b869a4d5836dd280e1bd6d0dd57b814c5649b9f82c0048ce294284679dbefc53ba5e1a22e56a81
|
data/lib/bing_translator.rb
CHANGED
@@ -10,9 +10,6 @@ require 'net/https'
|
|
10
10
|
require 'nokogiri'
|
11
11
|
require 'json'
|
12
12
|
|
13
|
-
class BingTranslatorException < Exception; end
|
14
|
-
class BingTranslatorAuthenticationException < Exception; end
|
15
|
-
|
16
13
|
class BingTranslator
|
17
14
|
TRANSLATE_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Translate'
|
18
15
|
DETECT_URI = 'http://api.microsofttranslator.com/V2/Http.svc/Detect'
|
@@ -20,6 +17,9 @@ class BingTranslator
|
|
20
17
|
ACCESS_TOKEN_URI = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13'
|
21
18
|
SPEAK_URI = 'http://api.microsofttranslator.com/v2/Http.svc/Speak'
|
22
19
|
|
20
|
+
class Exception < StandardError; end
|
21
|
+
class AuthenticationException < StandardError; end
|
22
|
+
|
23
23
|
def initialize(client_id, client_secret, skip_ssl_verify = false)
|
24
24
|
@client_id = client_id
|
25
25
|
@client_secret = client_secret
|
@@ -105,7 +105,7 @@ private
|
|
105
105
|
results
|
106
106
|
else
|
107
107
|
html = Nokogiri::HTML(results.body)
|
108
|
-
raise
|
108
|
+
raise Exception, html.xpath("//text()").remove.map(&:to_s).join(' ')
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
@@ -135,7 +135,7 @@ private
|
|
135
135
|
|
136
136
|
response = http.post(@access_token_uri.path, prepare_param_string(params))
|
137
137
|
@access_token = JSON.parse(response.body)
|
138
|
-
raise
|
138
|
+
raise AuthenticationException, @access_token['error'] if @access_token["error"]
|
139
139
|
@access_token['expires_at'] = Time.now + @access_token['expires_in'].to_i
|
140
140
|
@access_token
|
141
141
|
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
|
+
version: 4.0.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: 2013-07-
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|