sogou-tuiguang 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sogou/tuiguang/version.rb +1 -1
- data/lib/sogou/tuiguang.rb +16 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3e7bbc46dc89507aa68d1c65c514a4e2b99dd31
|
4
|
+
data.tar.gz: 651b01ba0a229682211047045ccfd6ebbaed28fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccd0d3be9743a8e86c9ce8c7807025343804ddbd084c16b76d4fba66dad9b5fd539a0ae0f5ef48f7cafbed15d6f32f837146401b93e0695c698ece4212161e15
|
7
|
+
data.tar.gz: 1866ecb1b56b0cc08f7accbe8b34757261442dd6228c33da9ec0054088eddade72c9a2e84623d89c0ec230b2dd42478b0e5d5297d4524957eecc89b2a6835190
|
data/lib/sogou/tuiguang.rb
CHANGED
@@ -121,14 +121,20 @@ module Sogou
|
|
121
121
|
request["referer"] = 'http://xuri.p4p.sogou.com/cpcadindex/init.action'
|
122
122
|
request["upgrade-insecure-requests"] = '1'
|
123
123
|
request["user-agent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
|
124
|
+
retry_times = 0
|
124
125
|
begin
|
125
126
|
response = http.request(request)
|
126
127
|
if response.is_a?(Net::HTTPRedirection)
|
127
128
|
puts "Redirection: #{response['location']}"
|
128
129
|
raise LoginExpired if response['location'].include? 'https://auth.p4p.sogou.com'
|
129
130
|
end
|
130
|
-
|
131
|
-
|
131
|
+
unless response.is_a?(Net::HTTPSuccess)
|
132
|
+
retry_times += 1
|
133
|
+
p 'Sleep 3s'
|
134
|
+
sleep 3
|
135
|
+
end
|
136
|
+
end if !response.is_a?(Net::HTTPSuccess) && retry_times < 10
|
137
|
+
raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
132
138
|
res = response.read_body
|
133
139
|
if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
|
134
140
|
res = Zlib::GzipReader.new(StringIO.new(res)).read
|
@@ -167,12 +173,18 @@ module Sogou
|
|
167
173
|
request["referer"] = 'http://xuri.p4p.sogou.com/cpcadindex/init.action'
|
168
174
|
request["sogou-request-type"] = 'XMLHTTPRequest'
|
169
175
|
request["user-agent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
|
176
|
+
retry_times = 0
|
170
177
|
begin
|
171
178
|
response = http.request(request)
|
172
179
|
raise LoginExpired if response.is_a?(Net::HTTPUnauthorized)
|
173
180
|
puts "Redirection: #{response['location']}" if response.is_a?(Net::HTTPRedirection)
|
174
|
-
|
175
|
-
|
181
|
+
unless response.is_a?(Net::HTTPSuccess)
|
182
|
+
retry_times += 1
|
183
|
+
p 'Sleep 3s'
|
184
|
+
sleep 3
|
185
|
+
end
|
186
|
+
end if !response.is_a?(Net::HTTPSuccess) && retry_times < 10
|
187
|
+
raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
176
188
|
@res = response.read_body
|
177
189
|
if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
|
178
190
|
@res = Zlib::GzipReader.new(StringIO.new(@res)).read
|