aitch 0.1.2 → 0.1.3
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/README.md +19 -2
- data/aitch.gemspec +2 -0
- data/lib/aitch.rb +1 -0
- data/lib/aitch/configuration.rb +4 -0
- data/lib/aitch/html_parser.rb +7 -0
- data/lib/aitch/response.rb +2 -0
- data/lib/aitch/version.rb +1 -1
- data/spec/aitch/html_parser_spec.rb +11 -0
- data/spec/aitch/response_spec.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784b17de50a0aa8ff0b9232c153aa67a30f0c713
|
4
|
+
data.tar.gz: 96c2f060bb52b68d26a6040f19315ef7578a8a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e264c4a316fb85601f6cf112ee1aab7d8f17140ed019d1096bf0045f1b3d7052b66a282f5365f9e9b474bfd928a23b1ca99c35e13faa5ea1478282fe7a071b3
|
7
|
+
data.tar.gz: 0b70c3a814cb20dab65aaa4293506f596441618d95b4dc3c76a3e2d9a28a6f5f825bac8829191dc60bbb4316d7ce86851747249c7cb25519cf1b9b7ab2df4e0a
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ A simple HTTP client.
|
|
10
10
|
Features:
|
11
11
|
|
12
12
|
* Supports Gzip|Deflate response
|
13
|
-
* Automatically parses JSON and XML responses
|
13
|
+
* Automatically parses JSON, HTML and XML responses
|
14
14
|
* Automatically follows redirect
|
15
15
|
|
16
16
|
## Installation
|
@@ -60,6 +60,9 @@ Aitch.configure do |config|
|
|
60
60
|
|
61
61
|
# Set the XML parser.
|
62
62
|
config.xml_parser = Aitch::XMLParser
|
63
|
+
|
64
|
+
# Set the HTML parser.
|
65
|
+
config.html_parser = Aitch::HTMLParser
|
63
66
|
end
|
64
67
|
```
|
65
68
|
|
@@ -94,7 +97,21 @@ response.redirect? # status 3xx
|
|
94
97
|
response.error? # status 4xx or 5xx
|
95
98
|
response.error # response error
|
96
99
|
response.body # returned body
|
97
|
-
response.data # JSON or XML payload
|
100
|
+
response.data # HTML, JSON or XML payload
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Parsing XML and HTML with Nokogiri
|
104
|
+
|
105
|
+
If your response is a XML or a HTML content type, we'll automatically convert the response into a Nokogiri object.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
response = Aitch.get("http://simplesideias.com.br")
|
109
|
+
|
110
|
+
response.data.class
|
111
|
+
#=> Nokogiri::HTML::Document
|
112
|
+
|
113
|
+
response.data.css("h1").size
|
114
|
+
#=> 69
|
98
115
|
```
|
99
116
|
|
100
117
|
### Following redirects
|
data/aitch.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
spec.add_development_dependency "rspec"
|
data/lib/aitch.rb
CHANGED
data/lib/aitch/configuration.rb
CHANGED
@@ -27,6 +27,9 @@ module Aitch
|
|
27
27
|
# Set the XML parser.
|
28
28
|
attr_accessor :xml_parser
|
29
29
|
|
30
|
+
# Set the HTML parser.
|
31
|
+
attr_accessor :html_parser
|
32
|
+
|
30
33
|
def initialize
|
31
34
|
@timeout = 10
|
32
35
|
@redirect_limit = 5
|
@@ -35,6 +38,7 @@ module Aitch
|
|
35
38
|
@default_headers = {}
|
36
39
|
@json_parser = JSON
|
37
40
|
@xml_parser = XMLParser
|
41
|
+
@html_parser = HTMLParser
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/aitch/response.rb
CHANGED
data/lib/aitch/version.rb
CHANGED
data/spec/aitch/response_spec.rb
CHANGED
@@ -158,7 +158,7 @@ describe Aitch::Response do
|
|
158
158
|
FakeWeb.register_uri(:get, "http://example.org/", body: "Hello", content_type: "text/html")
|
159
159
|
response = Aitch.get("http://example.org/")
|
160
160
|
|
161
|
-
expect(response.data).to
|
161
|
+
expect(response.data).to be_a(Nokogiri::HTML::Document)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +141,7 @@ files:
|
|
127
141
|
- lib/aitch.rb
|
128
142
|
- lib/aitch/configuration.rb
|
129
143
|
- lib/aitch/errors.rb
|
144
|
+
- lib/aitch/html_parser.rb
|
130
145
|
- lib/aitch/namespace.rb
|
131
146
|
- lib/aitch/redirect.rb
|
132
147
|
- lib/aitch/request.rb
|
@@ -139,6 +154,7 @@ files:
|
|
139
154
|
- lib/aitch/xml_parser.rb
|
140
155
|
- spec/aitch/aitch_spec.rb
|
141
156
|
- spec/aitch/configuration_spec.rb
|
157
|
+
- spec/aitch/html_parser_spec.rb
|
142
158
|
- spec/aitch/namespace_spec.rb
|
143
159
|
- spec/aitch/request_spec.rb
|
144
160
|
- spec/aitch/response_spec.rb
|
@@ -173,6 +189,7 @@ summary: A simple HTTP client
|
|
173
189
|
test_files:
|
174
190
|
- spec/aitch/aitch_spec.rb
|
175
191
|
- spec/aitch/configuration_spec.rb
|
192
|
+
- spec/aitch/html_parser_spec.rb
|
176
193
|
- spec/aitch/namespace_spec.rb
|
177
194
|
- spec/aitch/request_spec.rb
|
178
195
|
- spec/aitch/response_spec.rb
|