bing_translator 4.3.0 → 4.4.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 +31 -31
- 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: 6d6189472e447e49343dfb34c3d4f336fc0c5ee0
|
4
|
+
data.tar.gz: 1d9274f8190ae7d44f6ee70c28217cee0aa59a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edc29f613d4f8137eeefbda7a1089b0f5bfdf2c0bc1de11ad247eb70235ab1f913748c29e7e6a4ad5ab3be054cff355f52218708f024a0c4d1f9ece009f1a30f
|
7
|
+
data.tar.gz: ef1f85b0dc3b065c89c96f43a91636a8b0ecfdfd44059c15fdae986e76bc97a14b02e290b1bad7ba612605f028d896d1a1db4e82d45af74d83e8c748a32cad85
|
data/lib/bing_translator.rb
CHANGED
@@ -102,6 +102,37 @@ class BingTranslator
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
# Get a new access token and set it internally as @access_token
|
106
|
+
#
|
107
|
+
# Microsoft changed up how you get access to the Translate API.
|
108
|
+
# This gets a new token if it's required. We call this internally
|
109
|
+
# before any request we make to the Translate API.
|
110
|
+
#
|
111
|
+
# @return {hash}
|
112
|
+
# Returns existing @access_token if we don't need a new token yet,
|
113
|
+
# or returns the one just obtained.
|
114
|
+
def get_access_token
|
115
|
+
return @access_token if @access_token and
|
116
|
+
Time.now < @access_token['expires_at']
|
117
|
+
|
118
|
+
params = {
|
119
|
+
'client_id' => CGI.escape(@client_id),
|
120
|
+
'client_secret' => CGI.escape(@client_secret),
|
121
|
+
'scope' => CGI.escape('http://api.microsofttranslator.com'),
|
122
|
+
'grant_type' => 'client_credentials'
|
123
|
+
}
|
124
|
+
|
125
|
+
http = Net::HTTP.new(@access_token_uri.host, @access_token_uri.port)
|
126
|
+
http.use_ssl = true
|
127
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @skip_ssl_verify
|
128
|
+
|
129
|
+
response = http.post(@access_token_uri.path, prepare_param_string(params))
|
130
|
+
@access_token = JSON.parse(response.body)
|
131
|
+
raise AuthenticationException, @access_token['error'] if @access_token["error"]
|
132
|
+
@access_token['expires_at'] = Time.now + @access_token['expires_in'].to_i
|
133
|
+
@access_token
|
134
|
+
end
|
135
|
+
|
105
136
|
private
|
106
137
|
def datasets
|
107
138
|
raise AuthenticationException, "Must provide account key" if @account_key.nil?
|
@@ -150,35 +181,4 @@ private
|
|
150
181
|
headers: {'Authorization' => "Bearer #{get_access_token['access_token']}"},
|
151
182
|
)
|
152
183
|
end
|
153
|
-
|
154
|
-
# Private: Get a new access token
|
155
|
-
#
|
156
|
-
# Microsoft changed up how you get access to the Translate API.
|
157
|
-
# This gets a new token if it's required. We call this internally
|
158
|
-
# before any request we make to the Translate API.
|
159
|
-
#
|
160
|
-
# Returns nothing if we don't need a new token yet, or
|
161
|
-
# a Hash of information relating to the token if we obtained a new one.
|
162
|
-
# Also sets @access_token internally.
|
163
|
-
def get_access_token
|
164
|
-
return @access_token if @access_token and
|
165
|
-
Time.now < @access_token['expires_at']
|
166
|
-
|
167
|
-
params = {
|
168
|
-
'client_id' => CGI.escape(@client_id),
|
169
|
-
'client_secret' => CGI.escape(@client_secret),
|
170
|
-
'scope' => CGI.escape('http://api.microsofttranslator.com'),
|
171
|
-
'grant_type' => 'client_credentials'
|
172
|
-
}
|
173
|
-
|
174
|
-
http = Net::HTTP.new(@access_token_uri.host, @access_token_uri.port)
|
175
|
-
http.use_ssl = true
|
176
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @skip_ssl_verify
|
177
|
-
|
178
|
-
response = http.post(@access_token_uri.path, prepare_param_string(params))
|
179
|
-
@access_token = JSON.parse(response.body)
|
180
|
-
raise AuthenticationException, @access_token['error'] if @access_token["error"]
|
181
|
-
@access_token['expires_at'] = Time.now + @access_token['expires_in'].to_i
|
182
|
-
@access_token
|
183
|
-
end
|
184
184
|
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.4.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-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|