pincers 0.7.6 → 0.7.7

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: 13800946bd226e0d1901e8f2ca9602d3093263b7
4
- data.tar.gz: 15bb77962be50cfde06c890a8eb788443d12c4e2
3
+ metadata.gz: 6da332a1a2cd06206a29878abce0860c7dd9714a
4
+ data.tar.gz: 77a17252be6f58e1e76adcd04158c2ce94c3cbd3
5
5
  SHA512:
6
- metadata.gz: 03255eba9a8a32ac3a3c509fd5be6cae8e0bd0e3e34b09478bde052d48077e04d057aec40a733ae1d35a6e3fcd5d438480f3cad1baefae40278c94fdf6ac49e8
7
- data.tar.gz: 72996ed5cd0fba1cb6f7174864bdc8a29e0c31593b8830ea4446ce34748dee0c8e3dc7dbed0d0723cfb39c914ed258734fe0c6a9f2cb310c2e13d0d26270651a
6
+ metadata.gz: e34c26b569947c44307c280864268f6e7cbe855f35c9c265b188ef585a87d96e98b82973fc05230b679fbdbfb93c7a7bb9a95e688b55f7df4dd889ae0d5a34ec
7
+ data.tar.gz: 01c3d5999f23c5351a14aaeab86a516d11006f8f93ec963af24d6a5c39e655d9ea422c9808a949d10ab5a27acee83842feb0cd3e8dede0aff6e8c2aadbd7d7ca
@@ -33,12 +33,18 @@ module Pincers::Chenso
33
33
  end
34
34
 
35
35
  def execute(_client)
36
- _client.send(@method, @uri) do |request|
37
- request.headers.merge DEFAULT_HEADERS
38
- request.set_form_data(@data, @encoding) unless @data.nil?
36
+ response = begin
37
+ _client.send(@method, @uri) do |request|
38
+ request.headers.merge DEFAULT_HEADERS
39
+ request.set_form_data(@data, @encoding) unless @data.nil?
40
+ end
41
+
42
+ _client
43
+ rescue Pincers::Http::RequestError => exc
44
+ exc
39
45
  end
40
46
 
41
- BrowsingState.new _client.uri, ::Nokogiri::HTML(_client.content)
47
+ BrowsingState.new response.uri, ::Nokogiri::HTML(response.content)
42
48
  end
43
49
  end
44
50
  end
@@ -4,7 +4,6 @@ require 'net/http'
4
4
  require 'pincers/http/utils'
5
5
  require 'pincers/http/session'
6
6
  require 'pincers/http/request'
7
- require 'pincers/http/response_document'
8
7
  require 'pincers/http/errors'
9
8
 
10
9
  module Pincers::Http
@@ -127,7 +126,7 @@ module Pincers::Http
127
126
 
128
127
  def perform_in_session(_request)
129
128
  begin
130
- new_document = ResponseDocument.new @session.perform _request
129
+ new_document = @session.perform _request
131
130
  rescue
132
131
  @document = nil unless frozen
133
132
  raise
@@ -2,7 +2,7 @@ module Pincers::Http
2
2
  class RequestError < StandardError
3
3
  extend Forwardable
4
4
 
5
- def_delegators :@response, :code, :body
5
+ def_delegators :@response, :code, :uri, :content
6
6
 
7
7
  attr_reader :response
8
8
 
@@ -1,16 +1,19 @@
1
- require 'pincers/http/base_document'
2
-
3
1
  module Pincers::Http
4
- class ResponseDocument < BaseDocument
2
+ class Response
5
3
 
6
- attr_reader :response
4
+ attr_reader :uri, :response
7
5
 
8
- def initialize(_response)
6
+ def initialize(_uri, _response)
9
7
  @response = _response
8
+ @uri = _uri
9
+ end
10
+
11
+ def code
12
+ @response.code
10
13
  end
11
14
 
12
- def uri
13
- @response.uri
15
+ def message
16
+ @response.message
14
17
  end
15
18
 
16
19
  def content_type
@@ -1,5 +1,6 @@
1
1
  require 'pincers/http/errors'
2
2
  require 'pincers/http/cookie_jar'
3
+ require 'pincers/http/response'
3
4
 
4
5
  module Pincers::Http
5
6
  class Session
@@ -66,15 +67,14 @@ module Pincers::Http
66
67
  update_cookies(uri, http_response)
67
68
 
68
69
  case http_response
69
- when Net::HTTPSuccess then
70
- http_response.uri = uri # uri is not always set by net/http
71
- http_response
72
- when Net::HTTPRedirection then
70
+ when Net::HTTPSuccess
71
+ Response.new(uri, http_response)
72
+ when Net::HTTPRedirection
73
73
  location = Utils.parse_uri(http_response['location'])
74
74
  location = URI.join(uri, location) if location.relative?
75
75
  perform_recursive(_request, _limit - 1, location)
76
76
  else
77
- handle_error_response http_response
77
+ handle_error_response Response.new(uri, http_response)
78
78
  end
79
79
  end
80
80
 
@@ -1,3 +1,3 @@
1
1
  module Pincers
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pincers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -252,13 +252,12 @@ files:
252
252
  - lib/pincers/extension/labs.rb
253
253
  - lib/pincers/extension/queries.rb
254
254
  - lib/pincers/factory.rb
255
- - lib/pincers/http/base_document.rb
256
255
  - lib/pincers/http/client.rb
257
256
  - lib/pincers/http/cookie.rb
258
257
  - lib/pincers/http/cookie_jar.rb
259
258
  - lib/pincers/http/errors.rb
260
259
  - lib/pincers/http/request.rb
261
- - lib/pincers/http/response_document.rb
260
+ - lib/pincers/http/response.rb
262
261
  - lib/pincers/http/session.rb
263
262
  - lib/pincers/http/utils.rb
264
263
  - lib/pincers/nokogiri/backend.rb
@@ -1,20 +0,0 @@
1
- module Pincers::Http
2
- class BaseDocument
3
-
4
- def uri
5
- raise NotImplementedError
6
- end
7
-
8
- def content_type
9
- raise NotImplementedError
10
- end
11
-
12
- def content
13
- raise NotImplementedError
14
- end
15
-
16
- def save(_path)
17
- File.write _path, content
18
- end
19
- end
20
- end