aranha-parsers 0.8.2 → 0.9.0

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
  SHA256:
3
- metadata.gz: 3194999e6b819ece84259568475c4ead11054197362aa394585f47a1b2d0da21
4
- data.tar.gz: 1876ca753de554dd4d3256a1ab8b3ae6d13489a58e31fa353217120cb1dc20e0
3
+ metadata.gz: cb3631929ccd8b029ab5b097554f96f5eb0cc27dcf8767d3a8a97f050ee60b80
4
+ data.tar.gz: f30f306452ac72997887550051954d290f7e6c321b694236fd9f49bc6fff5d4a
5
5
  SHA512:
6
- metadata.gz: f841901367a6ded73b4cfb85f298e8544581d6b89789e2bab1792a24a0abed38cb88019afb11ae17618ebc1c3fb2808221b975f8ab28d8569ce73e5817c89e05
7
- data.tar.gz: 923f5e862c53671300233eb894d26d34efac54022ee5644775c73f0d15447b2be777ed0b5b02123af6e00b04333524072226bbf10e66debd111beae8a4583a00
6
+ metadata.gz: 35ebd10ceebadd29ade03ef0c5a75ed024e8d4377b19295861d8ef4c4e3bb4e091df5ff9f74398f523c98e0e3ee65eac1352bedc39eae033000cdc8561c5b749
7
+ data.tar.gz: 68a7664bef2ffd163cf110f14779feb92305b90cfb6b23e8d254c4cf2ca6871233d64032704790dd30397383cc67fd5a5b5dc9e67a1d866f1365524707b5ebb5
@@ -11,7 +11,9 @@ module Aranha
11
11
  class << self
12
12
  def from_content(content)
13
13
  ::EacRubyUtils::Fs::Temp.on_file do |path|
14
- path.write(content)
14
+ ::File.open(path.to_s, 'w:UTF-8') do |f|
15
+ f.write content.force_encoding('UTF-8')
16
+ end
15
17
  r = new(path.to_path)
16
18
  r.content
17
19
  r
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/base'
4
+ require 'json'
5
+
6
+ module Aranha
7
+ module Parsers
8
+ module Json
9
+ class Base < ::Aranha::Parsers::Base
10
+ def data
11
+ default_data
12
+ end
13
+
14
+ def default_data
15
+ ::JSON.parse(content)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Json
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -6,8 +6,8 @@ module Aranha
6
6
  module Parsers
7
7
  module Rspec
8
8
  module Setup
9
- def self.perform(_setup_obj)
10
- require 'aranha/parsers/rspec/source_target_fixtures_example'
9
+ def self.extended(_setup_obj)
10
+ require 'aranha/parsers/rspec/shared_examples/source_target_fixtures'
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Parsers
5
+ class SourceAddress
6
+ class FetchContentError < ::RuntimeError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'addressable'
4
4
  require 'curb'
5
+ require 'aranha/parsers/source_address/fetch_content_error'
5
6
 
6
7
  module Aranha
7
8
  module Parsers
@@ -31,18 +32,36 @@ module Aranha
31
32
  source
32
33
  end
33
34
 
35
+ def final_url
36
+ content unless @final_url
37
+ @final_url
38
+ end
39
+
34
40
  def content
35
41
  c = ::Curl::Easy.new(url)
36
42
  c.follow_location = true
37
- raise "Curl perform failed (URL: #{url})" unless c.perform
43
+ curl_perform(c)
38
44
  return c.body_str if c.status.to_i == 200
39
45
 
40
- raise "Get #{url} returned #{c.status.to_i}"
46
+ raise ::Aranha::Parsers::SourceAddress::FetchContentError,
47
+ "Get #{url} returned #{c.status.to_i}"
41
48
  end
42
49
 
43
50
  def serialize
44
51
  url
45
52
  end
53
+
54
+ private
55
+
56
+ def curl_perform(curl)
57
+ unless curl.perform
58
+ raise(::Aranha::Parsers::SourceAddress::FetchContentError,
59
+ "Curl perform failed (URL: #{url})")
60
+ end
61
+ @final_url = curl.url
62
+ rescue Curl::Err::CurlError => e
63
+ raise ::Aranha::Parsers::SourceAddress::FetchContentError, "CURL error: #{e.class.name}"
64
+ end
46
65
  end
47
66
  end
48
67
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aranha
4
4
  module Parsers
5
- VERSION = '0.8.2'
5
+ VERSION = '0.9.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aranha-parsers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-14 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.73'
61
+ version: '0.74'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.73'
68
+ version: '0.74'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httpclient
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,26 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: 2.8.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: nokogiri
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.12'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.12.4
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.12'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.12.4
89
109
  - !ruby/object:Gem::Dependency
90
110
  name: ofx-parser
91
111
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +129,7 @@ dependencies:
109
129
  version: '0.3'
110
130
  - - ">="
111
131
  - !ruby/object:Gem::Version
112
- version: 0.3.2
132
+ version: 0.3.3
113
133
  type: :development
114
134
  prerelease: false
115
135
  version_requirements: !ruby/object:Gem::Requirement
@@ -119,7 +139,7 @@ dependencies:
119
139
  version: '0.3'
120
140
  - - ">="
121
141
  - !ruby/object:Gem::Version
122
- version: 0.3.2
142
+ version: 0.3.3
123
143
  description:
124
144
  email:
125
145
  executables: []
@@ -137,12 +157,15 @@ files:
137
157
  - lib/aranha/parsers/html/node/base.rb
138
158
  - lib/aranha/parsers/html/node/default.rb
139
159
  - lib/aranha/parsers/invalid_state_exception.rb
160
+ - lib/aranha/parsers/json.rb
161
+ - lib/aranha/parsers/json/base.rb
140
162
  - lib/aranha/parsers/patches.rb
141
163
  - lib/aranha/parsers/patches/ofx_parser.rb
142
164
  - lib/aranha/parsers/rspec.rb
143
165
  - lib/aranha/parsers/rspec/setup.rb
144
- - lib/aranha/parsers/rspec/source_target_fixtures_example.rb
166
+ - lib/aranha/parsers/rspec/shared_examples/source_target_fixtures.rb
145
167
  - lib/aranha/parsers/source_address.rb
168
+ - lib/aranha/parsers/source_address/fetch_content_error.rb
146
169
  - lib/aranha/parsers/source_address/file.rb
147
170
  - lib/aranha/parsers/source_address/hash_http_get.rb
148
171
  - lib/aranha/parsers/source_address/hash_http_post.rb