sinew 2.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f5a493286f0bfdff9cb26bf85e768750edc57f489aec31e049a3c634bdc9074
4
- data.tar.gz: bda8c48fe0a1bccd4caf0c3304c248c218839f0d5547269df977dca56bca43c6
3
+ metadata.gz: fde4bbaa95fce45f3a7ae7aeacab1672615ea1ace852845b0395ce9cce32f861
4
+ data.tar.gz: 5743800570722443f704c5fc7bc421346cc4f2fb116b8fe9f615bf84fb95f826
5
5
  SHA512:
6
- metadata.gz: e9be078939e5e652c1775473322af55065d4ed0a541ba204b84381ba2d44c22b013e19993f500e02f08c9c686c0ee0f0af95cba9f644edd76058d0c1c05180c8
7
- data.tar.gz: 9bd2bde0fa0802a0d3b8467322dae695591a6a8928bf86ac1c7fab11f9754a4b66741e41e2ca029f9f9d1c5307c7e750bd29c64231399866ca4acb4d42087e31
6
+ metadata.gz: 94009061e7f4e36cc23528be3866c6a372df51a83e096144cafbd923259439e6d44a7d656fbdcfe09c2e059b48deb553caca3ec5d332b33845afd1e91550371a
7
+ data.tar.gz: 5a8baf7fbdba371065c796c9fdce4312039558b27b4a16676b3df16d5138916ce84db0677dce6ede1831be8040df9112a0491e421813af5e5fd0b0b747d49239
@@ -6,6 +6,10 @@ module Sinew
6
6
  class Response
7
7
  attr_accessor :request, :uri, :body, :code, :headers
8
8
 
9
+ #
10
+ # factory methods
11
+ #
12
+
9
13
  def self.from_network(request, party_response)
10
14
  Response.new.tap do |response|
11
15
  response.request = request
@@ -34,6 +38,9 @@ module Sinew
34
38
 
35
39
  # overwrite with cached response headers
36
40
  if head
41
+ if head !~ /^{/
42
+ return from_legacy_head(response, head)
43
+ end
37
44
  head = JSON.parse(head, symbolize_names: true)
38
45
  response.uri = URI.parse(head[:uri])
39
46
  response.code = head[:code]
@@ -52,6 +59,26 @@ module Sinew
52
59
  end
53
60
  end
54
61
 
62
+ def self.from_legacy_head(response, head)
63
+ response.tap do |response|
64
+ case head
65
+ when /\ACURLER_ERROR/
66
+ # error
67
+ response.code = 999
68
+ when /\AHTTP/
69
+ # redirect
70
+ location = head.scan(/Location: ([^\r\n]+)/).flatten.last
71
+ response.uri += location
72
+ else
73
+ $stderr.puts "unknown cached /head for #{response.uri}"
74
+ end
75
+ end
76
+ end
77
+
78
+ #
79
+ # accessors
80
+ #
81
+
55
82
  def error?
56
83
  code >= 400
57
84
  end
@@ -1,4 +1,4 @@
1
1
  module Sinew
2
2
  # Gem version
3
- VERSION = '2.0.0'.freeze
3
+ VERSION = '2.0.1'.freeze
4
4
  end
@@ -0,0 +1,51 @@
1
+ HTTP/1.1 302 FOUND
2
+ Connection: keep-alive
3
+ Server: gunicorn/19.7.1
4
+ Date: Wed, 02 May 2018 20:55:20 GMT
5
+ Content-Type: text/html; charset=utf-8
6
+ Content-Length: 247
7
+ Location: /relative-redirect/2
8
+ Access-Control-Allow-Origin: *
9
+ Access-Control-Allow-Credentials: true
10
+ X-Powered-By: Flask
11
+ X-Processed-Time: 0
12
+ Via: 1.1 vegur
13
+
14
+ HTTP/1.1 302 FOUND
15
+ Connection: keep-alive
16
+ Server: gunicorn/19.7.1
17
+ Date: Wed, 02 May 2018 20:55:20 GMT
18
+ Content-Type: text/html; charset=utf-8
19
+ Content-Length: 0
20
+ Location: /relative-redirect/1
21
+ Access-Control-Allow-Origin: *
22
+ Access-Control-Allow-Credentials: true
23
+ X-Powered-By: Flask
24
+ X-Processed-Time: 0
25
+ Via: 1.1 vegur
26
+
27
+ HTTP/1.1 302 FOUND
28
+ Connection: keep-alive
29
+ Server: gunicorn/19.7.1
30
+ Date: Wed, 02 May 2018 20:55:20 GMT
31
+ Content-Type: text/html; charset=utf-8
32
+ Content-Length: 0
33
+ Location: /get
34
+ Access-Control-Allow-Origin: *
35
+ Access-Control-Allow-Credentials: true
36
+ X-Powered-By: Flask
37
+ X-Processed-Time: 0
38
+ Via: 1.1 vegur
39
+
40
+ HTTP/1.1 200 OK
41
+ Connection: keep-alive
42
+ Server: gunicorn/19.7.1
43
+ Date: Wed, 02 May 2018 20:55:20 GMT
44
+ Content-Type: application/json
45
+ Access-Control-Allow-Origin: *
46
+ Access-Control-Allow-Credentials: true
47
+ X-Powered-By: Flask
48
+ X-Processed-Time: 0
49
+ Content-Length: 220
50
+ Via: 1.1 vegur
51
+
@@ -0,0 +1 @@
1
+ CURLER_ERROR curl error (22)
@@ -0,0 +1,11 @@
1
+ {
2
+ "args": {},
3
+ "headers": {
4
+ "Accept": "*/*",
5
+ "Connection": "close",
6
+ "Host": "eu.httpbin.org",
7
+ "User-Agent": "sinew/1.0.4"
8
+ },
9
+ "origin": "104.36.46.249",
10
+ "url": "http://eu.httpbin.org/get"
11
+ }
@@ -0,0 +1,2 @@
1
+ get 'http://eu.httpbin.org/status/500'
2
+ get 'http://eu.httpbin.org/redirect/3'
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ class TestLegacy < MiniTest::Test
4
+ def setup
5
+ super
6
+
7
+ # These are legacy cache files, pulled from an older version of sinew. We
8
+ # use them to test our legacy head parsing.
9
+ src = 'legacy/eu.httpbin.org'
10
+ dst = "#{TMP}/eu.httpbin.org"
11
+ FileUtils.cp_r(File.expand_path(src, __dir__), dst)
12
+ end
13
+
14
+ def test_legacy
15
+ sinew.dsl.get('http://eu.httpbin.org/status/500')
16
+ assert_equal "\n", sinew.dsl.raw
17
+
18
+ sinew.dsl.get('http://eu.httpbin.org/redirect/3')
19
+ assert_equal 'http://eu.httpbin.org/get', sinew.dsl.url
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinew
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Doppelt
@@ -181,9 +181,15 @@ files:
181
181
  - lib/sinew/version.rb
182
182
  - sample.sinew
183
183
  - sinew.gemspec
184
+ - test/legacy/eu.httpbin.org/head/redirect,3
185
+ - test/legacy/eu.httpbin.org/head/status,500
186
+ - test/legacy/eu.httpbin.org/redirect,3
187
+ - test/legacy/eu.httpbin.org/status,500
188
+ - test/legacy/legacy.sinew
184
189
  - test/test.html
185
190
  - test/test_cache.rb
186
191
  - test/test_helper.rb
192
+ - test/test_legacy.rb
187
193
  - test/test_main.rb
188
194
  - test/test_nokogiri_ext.rb
189
195
  - test/test_output.rb
@@ -214,9 +220,15 @@ signing_key:
214
220
  specification_version: 4
215
221
  summary: Sinew - structured web crawling using recipes.
216
222
  test_files:
223
+ - test/legacy/eu.httpbin.org/head/redirect,3
224
+ - test/legacy/eu.httpbin.org/head/status,500
225
+ - test/legacy/eu.httpbin.org/redirect,3
226
+ - test/legacy/eu.httpbin.org/status,500
227
+ - test/legacy/legacy.sinew
217
228
  - test/test.html
218
229
  - test/test_cache.rb
219
230
  - test/test_helper.rb
231
+ - test/test_legacy.rb
220
232
  - test/test_main.rb
221
233
  - test/test_nokogiri_ext.rb
222
234
  - test/test_output.rb