e360-tuiguang 0.1.1 → 0.1.2
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/e360/tuiguang.rb +27 -26
- data/lib/e360/tuiguang/version.rb +1 -1
- 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: 233bb3fe6592d3048f62604b4c5dc8cda3a04d1c
|
4
|
+
data.tar.gz: 7aaa4d32f36677a66f7848ecdae9e6288b7f990c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8853bd0d1b73f4aad029fcdabcb954c314b6e085d7c23f21002807ddc79b3231f921abb4aea5b6ebe19c6e19d432402bc518d679f40a33d8e2e226110be7247b
|
7
|
+
data.tar.gz: 2ae170d8b2e538f5499516fa0c89d6b0765683b56ab6735a6982d0e0b2c6fa08dde9504b05413c1ab4fb4ff01e79207ef65ab594ce0eeb393dfd5a0b7b69338e
|
data/lib/e360/tuiguang.rb
CHANGED
@@ -131,7 +131,7 @@ module E360
|
|
131
131
|
def request(url)
|
132
132
|
url = URI(url)
|
133
133
|
params = URI.decode_www_form(url.query)
|
134
|
-
params.unshift ['_', Time.now.strftime('%
|
134
|
+
params.unshift ['_', Time.now.strftime('%s%L')]
|
135
135
|
if @token && @expire_times
|
136
136
|
params.unshift ['expireTimes', @expire_times]
|
137
137
|
params.unshift ['token', @token]
|
@@ -139,29 +139,33 @@ module E360
|
|
139
139
|
url.query = URI.encode_www_form(params)
|
140
140
|
@req_url = url.to_s
|
141
141
|
puts "Url: #{@req_url}"
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
142
|
+
begin
|
143
|
+
http = Net::HTTP.new(url.host, url.port)
|
144
|
+
request = Net::HTTP::Get.new(url)
|
145
|
+
request["accept"] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
146
|
+
request["accept-encoding"] = 'gzip, deflate, sdch'
|
147
|
+
request["accept-language"] = 'zh-CN,zh;q=0.8'
|
148
|
+
request["cache-control"] = 'no-cache'
|
149
|
+
request["connection"] = 'keep-alive'
|
150
|
+
request["cookie"] = @cookies
|
151
|
+
request["host"] = 'dianjing.e.360.cn'
|
152
|
+
request["pragma"] = 'no-cache'
|
153
|
+
request["referer"] = "http://dianjing.e.360.cn/adrank?_=#{Time.now.strftime('%s%L')}"
|
154
|
+
request["upgrade-insecure-requests"] = '1'
|
155
|
+
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'
|
156
|
+
response = http.request(request)
|
157
|
+
if response.is_a?(Net::HTTPRedirection)
|
158
|
+
p "Redirection: #{response['location']}"
|
159
|
+
if response['location'] == 'http://e.360.cn'
|
160
|
+
raise LoginExpired
|
161
|
+
end
|
162
162
|
end
|
163
|
-
|
164
|
-
|
163
|
+
raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
164
|
+
unless response.is_a?(Net::HTTPSuccess)
|
165
|
+
p 'Sleep 3s'
|
166
|
+
sleep 3
|
167
|
+
end
|
168
|
+
end until response.is_a?(Net::HTTPSuccess)
|
165
169
|
@resp = response.read_body
|
166
170
|
if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
|
167
171
|
@resp = Zlib::GzipReader.new(StringIO.new(@resp)).read
|
@@ -215,9 +219,6 @@ module E360
|
|
215
219
|
class LoginExpired < StandardError;
|
216
220
|
end
|
217
221
|
|
218
|
-
class RedirectHome < StandardError;
|
219
|
-
end
|
220
|
-
|
221
222
|
class TokenExpired < StandardError;
|
222
223
|
end
|
223
224
|
|