e360-tuiguang 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e004b90b8db1ae65a12702390a39b9b41e47394
4
- data.tar.gz: c4ecb872ca79ec7cf054e50e29a162a60be57224
3
+ metadata.gz: 233bb3fe6592d3048f62604b4c5dc8cda3a04d1c
4
+ data.tar.gz: 7aaa4d32f36677a66f7848ecdae9e6288b7f990c
5
5
  SHA512:
6
- metadata.gz: e53f80049296a91782fdca59f7ee994a7a9c1202d2d684fcbf1bf0d2db4008d18239f3e853960e90f2c59622b7cb490c87f5ec8c2ef7ecf936ffe0ea15345be7
7
- data.tar.gz: f8856fd0c4e955fd8c841f0c59a6a6674d17c48b051f924a8e55f91255a6e7d999bfd1d2b1145edbab1e83c94b1869b00a4d8f18b5ba1a441583fa4db5e12803
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('%N%L')]
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
- http = Net::HTTP.new(url.host, url.port)
143
- request = Net::HTTP::Get.new(url)
144
- request["accept"] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
145
- request["accept-encoding"] = 'gzip, deflate, sdch'
146
- request["accept-language"] = 'zh-CN,zh;q=0.8'
147
- request["cache-control"] = 'no-cache'
148
- request["connection"] = 'keep-alive'
149
- request["cookie"] = @cookies
150
- request["host"] = 'dianjing.e.360.cn'
151
- request["pragma"] = 'no-cache'
152
- request["referer"] = "http://dianjing.e.360.cn/adrank?_=#{Time.now.strftime('%N%L')}"
153
- request["upgrade-insecure-requests"] = '1'
154
- 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'
155
- response = http.request(request)
156
- puts "Redirection: #{response['location']}" if response.is_a?(Net::HTTPRedirection)
157
- if response.is_a?(Net::HTTPRedirection)
158
- if response['location'] == 'http://e.360.cn'
159
- raise LoginExpired
160
- elsif response['location'].include?('http://e.360.cn/home')
161
- raise RedirectHome
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
- end
164
- raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
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
 
@@ -1,5 +1,5 @@
1
1
  module E360
2
2
  module Tuiguang
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e360-tuiguang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Jie