aitch 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/Gemfile.lock +71 -0
- data/README.md +50 -16
- data/aitch.gemspec +1 -1
- data/lib/aitch.rb +1 -0
- data/lib/aitch/configuration.rb +6 -0
- data/lib/aitch/dsl.rb +26 -0
- data/lib/aitch/namespace.rb +25 -14
- data/lib/aitch/redirect.rb +4 -4
- data/lib/aitch/request.rb +6 -7
- data/lib/aitch/response.rb +14 -5
- data/lib/aitch/utils.rb +6 -0
- data/lib/aitch/version.rb +1 -1
- data/spec/aitch/aitch_spec.rb +4 -3
- data/spec/aitch/dsl_spec.rb +47 -0
- data/spec/aitch/request_spec.rb +25 -4
- data/spec/aitch/response_spec.rb +6 -6
- data/spec/aitch/utils_spec.rb +6 -0
- metadata +31 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38aa9fc2ad29df790bc7fd40ce355bf708daf1d6
|
4
|
+
data.tar.gz: f175d33a07de066ba73d913462adbc5fd5e9cd7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 924cd3596df55c55b2be570715eaf1770874f45524557ef6a3a4f037c21ab07e0e8fe97a42445c15719074c8308caee0b1f24f9e8c810db9c7a37c02df97d927
|
7
|
+
data.tar.gz: 0f08930e4e9e0fe574020b8ef7bb4456caeb4fced990efebd65d5f22eda7980beaf7dee225c6afdebebc9ed524e0d902f1786959c29deec9ca3893a08dde163c
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aitch (0.2.0)
|
5
|
+
activesupport
|
6
|
+
nokogiri (>= 1.6.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.0.0)
|
12
|
+
i18n (~> 0.6, >= 0.6.4)
|
13
|
+
minitest (~> 4.2)
|
14
|
+
multi_json (~> 1.3)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 0.3.37)
|
17
|
+
atomic (1.1.10)
|
18
|
+
awesome_print (1.1.0)
|
19
|
+
coderay (1.0.9)
|
20
|
+
diff-lcs (1.2.4)
|
21
|
+
fakeweb (1.3.0)
|
22
|
+
i18n (0.6.4)
|
23
|
+
method_source (0.8.2)
|
24
|
+
mini_portile (0.5.1)
|
25
|
+
minitest (4.7.5)
|
26
|
+
multi_json (1.7.7)
|
27
|
+
nokogiri (1.6.0)
|
28
|
+
mini_portile (~> 0.5.0)
|
29
|
+
notifier (0.4.1)
|
30
|
+
pry (0.9.12.2)
|
31
|
+
coderay (~> 1.0.5)
|
32
|
+
method_source (~> 0.8)
|
33
|
+
slop (~> 3.4)
|
34
|
+
pry-meta (0.0.5)
|
35
|
+
awesome_print
|
36
|
+
pry
|
37
|
+
pry-nav
|
38
|
+
pry-remote
|
39
|
+
pry-nav (0.2.3)
|
40
|
+
pry (~> 0.9.10)
|
41
|
+
pry-remote (0.1.7)
|
42
|
+
pry (~> 0.9)
|
43
|
+
slop (~> 3.0)
|
44
|
+
rake (10.1.0)
|
45
|
+
rspec (2.14.1)
|
46
|
+
rspec-core (~> 2.14.0)
|
47
|
+
rspec-expectations (~> 2.14.0)
|
48
|
+
rspec-mocks (~> 2.14.0)
|
49
|
+
rspec-core (2.14.4)
|
50
|
+
rspec-expectations (2.14.0)
|
51
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
52
|
+
rspec-mocks (2.14.1)
|
53
|
+
slop (3.4.6)
|
54
|
+
test_notifier (1.0.1)
|
55
|
+
notifier
|
56
|
+
thread_safe (0.1.2)
|
57
|
+
atomic
|
58
|
+
tzinfo (0.3.37)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
aitch!
|
65
|
+
bundler
|
66
|
+
fakeweb
|
67
|
+
nokogiri
|
68
|
+
pry-meta
|
69
|
+
rake
|
70
|
+
rspec
|
71
|
+
test_notifier
|
data/README.md
CHANGED
@@ -71,14 +71,25 @@ end
|
|
71
71
|
Performing requests:
|
72
72
|
|
73
73
|
```ruby
|
74
|
-
response = Aitch.get("http://example.org", params, headers)
|
75
|
-
Aitch.post("http://example.org", params, headers)
|
76
|
-
Aitch.put("http://example.org", params, headers)
|
77
|
-
Aitch.patch("http://example.org", params, headers)
|
78
|
-
Aitch.delete("http://example.org", params, headers)
|
79
|
-
Aitch.options("http://example.org", params, headers)
|
80
|
-
Aitch.trace("http://example.org", params, headers)
|
81
|
-
Aitch.head("http://example.org", params, headers)
|
74
|
+
response = Aitch.get("http://example.org", params, headers, options)
|
75
|
+
Aitch.post("http://example.org", params, headers, options)
|
76
|
+
Aitch.put("http://example.org", params, headers, options)
|
77
|
+
Aitch.patch("http://example.org", params, headers, options)
|
78
|
+
Aitch.delete("http://example.org", params, headers, options)
|
79
|
+
Aitch.options("http://example.org", params, headers, options)
|
80
|
+
Aitch.trace("http://example.org", params, headers, options)
|
81
|
+
Aitch.head("http://example.org", params, headers, options)
|
82
|
+
```
|
83
|
+
|
84
|
+
You can also use a DSL.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
response = Aitch.get do
|
88
|
+
url "http://simplesideias.com.br"
|
89
|
+
headers Authorization: "Token token=abc"
|
90
|
+
options follow_redirect: false
|
91
|
+
params a: 1, b: 2
|
92
|
+
end
|
82
93
|
```
|
83
94
|
|
84
95
|
### Response
|
@@ -98,20 +109,38 @@ response.error? # status 4xx or 5xx
|
|
98
109
|
response.error # response error
|
99
110
|
response.body # returned body
|
100
111
|
response.data # HTML, JSON or XML payload
|
112
|
+
response.xml # An alias to the Aitch::Response#data method
|
113
|
+
response.html # An alias to the Aitch::Response#data method
|
114
|
+
response.json # An alias to the Aitch::Response#data method
|
101
115
|
```
|
102
116
|
|
103
|
-
#### Parsing XML and HTML with Nokogiri
|
117
|
+
#### Parsing JSON, XML and HTML with Nokogiri
|
104
118
|
|
105
|
-
If your response is a XML or a HTML content type, we'll automatically convert the response into
|
119
|
+
If your response is a JSON, XML or a HTML content type, we'll automatically convert the response into the appropriate object.
|
106
120
|
|
107
121
|
```ruby
|
108
122
|
response = Aitch.get("http://simplesideias.com.br")
|
109
123
|
|
110
|
-
response.
|
124
|
+
response.html.class
|
111
125
|
#=> Nokogiri::HTML::Document
|
112
126
|
|
113
|
-
response.
|
127
|
+
response.html.css("h1").size
|
114
128
|
#=> 69
|
129
|
+
|
130
|
+
response = Aitch.get("http://simplesideias.com.br/feed")
|
131
|
+
|
132
|
+
response.xml.class
|
133
|
+
#=> Nokogiri::XML::Document
|
134
|
+
|
135
|
+
response.xml.css("item").size
|
136
|
+
#=> 10
|
137
|
+
|
138
|
+
response = Aitch.get("https://api.github.com/users/fnando")
|
139
|
+
response.json.class
|
140
|
+
#=> Hash
|
141
|
+
|
142
|
+
response.json["login"]
|
143
|
+
#=> fnando
|
115
144
|
```
|
116
145
|
|
117
146
|
### Following redirects
|
@@ -131,21 +160,26 @@ The request:
|
|
131
160
|
Aitch.get("http://example.org")
|
132
161
|
```
|
133
162
|
|
134
|
-
If the redirect limit is exceeded, then the `Aitch::TooManyRedirectsError` exception
|
135
|
-
is raised.
|
163
|
+
If the redirect limit is exceeded, then the `Aitch::TooManyRedirectsError` exception is raised.
|
136
164
|
|
137
165
|
### Basic auth
|
138
166
|
|
139
167
|
Setting basic auth credentials:
|
140
168
|
|
141
169
|
```ruby
|
142
|
-
Aitch.get
|
170
|
+
response = Aitch.get do
|
171
|
+
url "http://restrict.example.org/"
|
172
|
+
options: user: "john", password: "test"
|
173
|
+
end
|
143
174
|
```
|
144
175
|
|
145
176
|
### Setting custom headers
|
146
177
|
|
147
178
|
```ruby
|
148
|
-
Aitch.get
|
179
|
+
Aitch.get do
|
180
|
+
url "http://example.org"
|
181
|
+
headers "User-Agent" => "MyBot/1.0.0"
|
182
|
+
end
|
149
183
|
```
|
150
184
|
|
151
185
|
The header value can be a callable object.
|
data/aitch.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
27
|
spec.add_development_dependency "pry-meta"
|
28
28
|
spec.add_development_dependency "test_notifier"
|
29
29
|
spec.add_development_dependency "fakeweb"
|
data/lib/aitch.rb
CHANGED
data/lib/aitch/configuration.rb
CHANGED
data/lib/aitch/dsl.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Aitch
|
2
|
+
class DSL
|
3
|
+
%w[url options headers data].each do |name|
|
4
|
+
class_eval <<-RUBY
|
5
|
+
attr_writer :#{name}
|
6
|
+
|
7
|
+
def #{name}(*args)
|
8
|
+
@#{name} = args.first if args.any?
|
9
|
+
@#{name}
|
10
|
+
end
|
11
|
+
RUBY
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :params, :data
|
15
|
+
alias_method :body, :data
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{
|
19
|
+
url: url,
|
20
|
+
options: options || {},
|
21
|
+
headers: headers || {},
|
22
|
+
data: data
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/aitch/namespace.rb
CHANGED
@@ -9,19 +9,30 @@ module Aitch
|
|
9
9
|
end
|
10
10
|
alias_method :configuration, :config
|
11
11
|
|
12
|
-
def execute(request_method, url, data = {}, headers = {}, options = {})
|
13
|
-
|
14
|
-
|
12
|
+
def execute(request_method = nil, url = nil, data = {}, headers = {}, options = {}, &block)
|
13
|
+
if block_given?
|
14
|
+
dsl = DSL.new
|
15
|
+
dsl.instance_eval(&block)
|
16
|
+
args = dsl.to_h
|
17
|
+
else
|
18
|
+
args = {
|
19
|
+
url: url,
|
20
|
+
data: data,
|
21
|
+
headers: headers,
|
22
|
+
options: options
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
args.merge!(
|
15
27
|
request_method: request_method,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}).perform
|
28
|
+
options: config.to_h.merge(Utils.symbolize_keys(args[:options]))
|
29
|
+
)
|
30
|
+
|
31
|
+
Request.new(args).perform
|
21
32
|
end
|
22
33
|
|
23
|
-
def execute!(*args)
|
24
|
-
response = execute(*args)
|
34
|
+
def execute!(*args, &block)
|
35
|
+
response = execute(*args, &block)
|
25
36
|
raise response.error if response.error?
|
26
37
|
response
|
27
38
|
end
|
@@ -36,12 +47,12 @@ module Aitch
|
|
36
47
|
trace
|
37
48
|
head
|
38
49
|
].each do |method_name|
|
39
|
-
define_method(method_name) do |url, data = {}, headers = {}, options = {}|
|
40
|
-
execute(method_name, url, data, headers, options)
|
50
|
+
define_method(method_name) do |url = nil, data = {}, headers = {}, options = {}, &block|
|
51
|
+
execute(method_name, url, data, headers, options, &block)
|
41
52
|
end
|
42
53
|
|
43
|
-
define_method("#{method_name}!") do |url, data = {}, headers = {}, options = {}|
|
44
|
-
execute!(method_name, url, data, headers, options)
|
54
|
+
define_method("#{method_name}!") do |url = nil, data = {}, headers = {}, options = {}, &block|
|
55
|
+
execute!(method_name, url, data, headers, options, &block)
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
data/lib/aitch/redirect.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Aitch
|
2
2
|
class Redirect
|
3
|
-
def initialize(
|
3
|
+
def initialize(options)
|
4
4
|
@tries = 1
|
5
|
-
@
|
6
|
-
@max_tries = @
|
5
|
+
@options = options
|
6
|
+
@max_tries = @options[:redirect_limit]
|
7
7
|
end
|
8
8
|
|
9
9
|
def followed!
|
@@ -15,7 +15,7 @@ module Aitch
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def enabled?
|
18
|
-
@
|
18
|
+
@options[:follow_redirect]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/aitch/request.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Aitch
|
2
2
|
class Request
|
3
|
-
attr_accessor :config
|
4
3
|
attr_accessor :request_method
|
5
4
|
attr_accessor :url
|
6
5
|
attr_accessor :data
|
@@ -17,8 +16,8 @@ module Aitch
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def perform
|
20
|
-
response = Response.new(
|
21
|
-
redirect = Redirect.new(
|
19
|
+
response = Response.new(options, client.request(request))
|
20
|
+
redirect = Redirect.new(options)
|
22
21
|
|
23
22
|
while redirect.follow?(response)
|
24
23
|
redirect.followed!
|
@@ -73,7 +72,7 @@ module Aitch
|
|
73
72
|
end
|
74
73
|
|
75
74
|
def set_headers(request)
|
76
|
-
all_headers =
|
75
|
+
all_headers = options.fetch(:default_headers, {}).merge(headers)
|
77
76
|
|
78
77
|
all_headers.each do |name, value|
|
79
78
|
value = value.respond_to?(:call) ? value.call : value
|
@@ -91,16 +90,16 @@ module Aitch
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def set_timeout(client)
|
94
|
-
client.read_timeout =
|
93
|
+
client.read_timeout = options[:timeout]
|
95
94
|
end
|
96
95
|
|
97
96
|
def set_logger(client)
|
98
|
-
logger =
|
97
|
+
logger = options[:logger]
|
99
98
|
client.set_debug_output(logger) if logger
|
100
99
|
end
|
101
100
|
|
102
101
|
def set_user_agent(request)
|
103
|
-
request["User-Agent"] =
|
102
|
+
request["User-Agent"] = options[:user_agent]
|
104
103
|
end
|
105
104
|
|
106
105
|
def set_gzip(request)
|
data/lib/aitch/response.rb
CHANGED
@@ -4,8 +4,8 @@ module Aitch
|
|
4
4
|
|
5
5
|
def_delegators :@http_response, :content_type
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(options, http_response)
|
8
|
+
@options = options
|
9
9
|
@http_response = http_response
|
10
10
|
end
|
11
11
|
|
@@ -55,15 +55,18 @@ module Aitch
|
|
55
55
|
|
56
56
|
def data
|
57
57
|
if json?
|
58
|
-
@
|
58
|
+
@options[:json_parser].load(body)
|
59
59
|
elsif xml?
|
60
|
-
@
|
60
|
+
@options[:xml_parser].load(body)
|
61
61
|
elsif html?
|
62
|
-
@
|
62
|
+
@options[:html_parser].load(body)
|
63
63
|
else
|
64
64
|
body
|
65
65
|
end
|
66
66
|
end
|
67
|
+
alias_method :xml, :data
|
68
|
+
alias_method :html, :data
|
69
|
+
alias_method :json, :data
|
67
70
|
|
68
71
|
def headers
|
69
72
|
@headers ||= {}.tap do |headers|
|
@@ -81,5 +84,11 @@ module Aitch
|
|
81
84
|
def respond_to_missing?(name, include_private = false)
|
82
85
|
headers.key?(name.to_s)
|
83
86
|
end
|
87
|
+
|
88
|
+
def inspect
|
89
|
+
"#<#{self.class} #{code} #{@http_response.msg} (#{content_type})>"
|
90
|
+
end
|
91
|
+
|
92
|
+
alias_method :to_s, :inspect
|
84
93
|
end
|
85
94
|
end
|
data/lib/aitch/utils.rb
CHANGED
data/lib/aitch/version.rb
CHANGED
data/spec/aitch/aitch_spec.rb
CHANGED
@@ -28,13 +28,14 @@ describe Aitch do
|
|
28
28
|
let(:request) { double.as_null_object }
|
29
29
|
|
30
30
|
it "delegates to Request" do
|
31
|
+
options = {}
|
32
|
+
|
31
33
|
expected = {
|
32
|
-
config: Aitch.config,
|
33
34
|
request_method: "get",
|
34
35
|
url: "URL",
|
35
36
|
data: "DATA",
|
36
37
|
headers: "HEADERS",
|
37
|
-
options:
|
38
|
+
options: options.merge(Aitch.config.to_h)
|
38
39
|
}
|
39
40
|
|
40
41
|
Aitch::Request
|
@@ -42,7 +43,7 @@ describe Aitch do
|
|
42
43
|
.with(expected)
|
43
44
|
.and_return(request)
|
44
45
|
|
45
|
-
Aitch.get("URL", "DATA", "HEADERS",
|
46
|
+
Aitch.get("URL", "DATA", "HEADERS", options)
|
46
47
|
end
|
47
48
|
|
48
49
|
it "performs request" do
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Aitch::DSL do
|
4
|
+
subject(:dsl) { Aitch::DSL.new }
|
5
|
+
|
6
|
+
it "sets url" do
|
7
|
+
dsl.url "URL"
|
8
|
+
expect(dsl.url).to eql("URL")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "sets options" do
|
12
|
+
dsl.options "OPTIONS"
|
13
|
+
expect(dsl.options).to eql("OPTIONS")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets headers" do
|
17
|
+
dsl.headers "HEADERS"
|
18
|
+
expect(dsl.headers).to eql("HEADERS")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets data" do
|
22
|
+
dsl.data "DATA"
|
23
|
+
expect(dsl.data).to eql("DATA")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets data through params" do
|
27
|
+
dsl.params "PARAMS"
|
28
|
+
expect(dsl.data).to eql("PARAMS")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets data through body" do
|
32
|
+
dsl.body "BODY"
|
33
|
+
expect(dsl.data).to eql("BODY")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns hash" do
|
37
|
+
dsl.options "OPTIONS"
|
38
|
+
dsl.headers "HEADERS"
|
39
|
+
dsl.url "URL"
|
40
|
+
dsl.data "DATA"
|
41
|
+
|
42
|
+
expect(dsl.to_h).to include(data: "DATA")
|
43
|
+
expect(dsl.to_h).to include(headers: "HEADERS")
|
44
|
+
expect(dsl.to_h).to include(url: "URL")
|
45
|
+
expect(dsl.to_h).to include(options: "OPTIONS")
|
46
|
+
end
|
47
|
+
end
|
data/spec/aitch/request_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Aitch::Request do
|
|
5
5
|
Aitch::Request.new({
|
6
6
|
request_method: "get",
|
7
7
|
url: "http://example.org",
|
8
|
-
|
8
|
+
options: {}
|
9
9
|
}.merge(options))
|
10
10
|
end
|
11
11
|
|
@@ -36,7 +36,7 @@ describe Aitch::Request do
|
|
36
36
|
it "sets user agent" do
|
37
37
|
requester = build_request
|
38
38
|
request = requester.request
|
39
|
-
expect(request["User-Agent"]).to eql(requester.
|
39
|
+
expect(request["User-Agent"]).to eql(requester.options[:user_agent])
|
40
40
|
end
|
41
41
|
|
42
42
|
it "requests gzip encoding" do
|
@@ -81,7 +81,7 @@ describe Aitch::Request do
|
|
81
81
|
|
82
82
|
it "sets default headers" do
|
83
83
|
requester = build_request
|
84
|
-
requester.
|
84
|
+
requester.options[:default_headers] = {"HEADER" => "VALUE"}
|
85
85
|
request = requester.request
|
86
86
|
|
87
87
|
expect(request["HEADER"]).to eql("VALUE")
|
@@ -118,7 +118,7 @@ describe Aitch::Request do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it "sets timeout" do
|
121
|
-
request.
|
121
|
+
request.options[:timeout] = 20
|
122
122
|
expect(client.read_timeout).to eql(20)
|
123
123
|
end
|
124
124
|
end
|
@@ -183,4 +183,25 @@ describe Aitch::Request do
|
|
183
183
|
expect(FakeWeb.last_request.path).to eql("/?a=1&b=2")
|
184
184
|
end
|
185
185
|
end
|
186
|
+
|
187
|
+
describe "using the DSL" do
|
188
|
+
it "performs request" do
|
189
|
+
FakeWeb.register_uri(:post, %r[.+], body: "")
|
190
|
+
|
191
|
+
response = Aitch.post do
|
192
|
+
url "http://example.org/some/path"
|
193
|
+
params a: 1, b: 2
|
194
|
+
headers Rendering: "0.1"
|
195
|
+
options user: "user", password: "pass"
|
196
|
+
end
|
197
|
+
|
198
|
+
expect(FakeWeb.last_request.path).to eql("/some/path")
|
199
|
+
expect(FakeWeb.last_request.method).to eql("POST")
|
200
|
+
expect(FakeWeb.last_request.body).to eql("a=1&b=2")
|
201
|
+
expect(FakeWeb.last_request["Rendering"]).to eql("0.1")
|
202
|
+
|
203
|
+
auth = Base64.encode64("user:pass").chomp
|
204
|
+
expect(FakeWeb.last_request["Authorization"]).to eql("Basic #{auth}")
|
205
|
+
end
|
206
|
+
end
|
186
207
|
end
|
data/spec/aitch/response_spec.rb
CHANGED
@@ -138,11 +138,11 @@ describe Aitch::Response do
|
|
138
138
|
expect(response).to be_json
|
139
139
|
end
|
140
140
|
|
141
|
-
it "returns
|
141
|
+
it "returns json" do
|
142
142
|
FakeWeb.register_uri(:get, "http://example.org/", body: "[1,2,3]", content_type: "application/json")
|
143
143
|
response = Aitch.get("http://example.org/")
|
144
144
|
|
145
|
-
expect(response.
|
145
|
+
expect(response.json).to eql([1,2,3])
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -154,11 +154,11 @@ describe Aitch::Response do
|
|
154
154
|
expect(response).to be_html
|
155
155
|
end
|
156
156
|
|
157
|
-
it "returns
|
157
|
+
it "returns html" 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.
|
161
|
+
expect(response.html).to be_a(Nokogiri::HTML::Document)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -170,11 +170,11 @@ describe Aitch::Response do
|
|
170
170
|
expect(response).to be_xml
|
171
171
|
end
|
172
172
|
|
173
|
-
it "returns
|
173
|
+
it "returns xml" do
|
174
174
|
FakeWeb.register_uri(:get, "http://example.org/", body: "<foo/>", content_type: "application/xml")
|
175
175
|
response = Aitch.get("http://example.org/")
|
176
176
|
|
177
|
-
expect(response.
|
177
|
+
expect(response.xml).to be_a(Nokogiri::XML::Document)
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
data/spec/aitch/utils_spec.rb
CHANGED
@@ -10,4 +10,10 @@ describe Aitch::Utils do
|
|
10
10
|
expect(Aitch::Utils.underscore("RequestURITooLong")).to eql("request_uri_too_long")
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
describe ".symbolize_keys" do
|
15
|
+
it "converts keys to symbols" do
|
16
|
+
expect(Aitch::Utils.symbolize_keys("a" => 1)).to eql(a: 1)
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
metadata
CHANGED
@@ -1,158 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nando Vieira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: nokogiri
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.6.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.6.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: bundler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
75
|
+
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
82
|
+
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: pry-meta
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: test_notifier
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: fakeweb
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - '>='
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '0'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - '>='
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '0'
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: nokogiri
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
|
-
- -
|
129
|
+
- - '>='
|
148
130
|
- !ruby/object:Gem::Version
|
149
131
|
version: '0'
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
135
|
requirements:
|
155
|
-
- -
|
136
|
+
- - '>='
|
156
137
|
- !ruby/object:Gem::Version
|
157
138
|
version: '0'
|
158
139
|
description: A simple HTTP client
|
@@ -167,12 +148,14 @@ files:
|
|
167
148
|
- .rspec
|
168
149
|
- .travis.yml
|
169
150
|
- Gemfile
|
151
|
+
- Gemfile.lock
|
170
152
|
- LICENSE.txt
|
171
153
|
- README.md
|
172
154
|
- Rakefile
|
173
155
|
- aitch.gemspec
|
174
156
|
- lib/aitch.rb
|
175
157
|
- lib/aitch/configuration.rb
|
158
|
+
- lib/aitch/dsl.rb
|
176
159
|
- lib/aitch/errors.rb
|
177
160
|
- lib/aitch/html_parser.rb
|
178
161
|
- lib/aitch/namespace.rb
|
@@ -187,6 +170,7 @@ files:
|
|
187
170
|
- lib/aitch/xml_parser.rb
|
188
171
|
- spec/aitch/aitch_spec.rb
|
189
172
|
- spec/aitch/configuration_spec.rb
|
173
|
+
- spec/aitch/dsl_spec.rb
|
190
174
|
- spec/aitch/html_parser_spec.rb
|
191
175
|
- spec/aitch/namespace_spec.rb
|
192
176
|
- spec/aitch/request_spec.rb
|
@@ -199,31 +183,31 @@ files:
|
|
199
183
|
homepage: http://rubygems.org/gems/aitch
|
200
184
|
licenses:
|
201
185
|
- MIT
|
186
|
+
metadata: {}
|
202
187
|
post_install_message:
|
203
188
|
rdoc_options: []
|
204
189
|
require_paths:
|
205
190
|
- lib
|
206
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
-
none: false
|
208
192
|
requirements:
|
209
|
-
- -
|
193
|
+
- - '>='
|
210
194
|
- !ruby/object:Gem::Version
|
211
195
|
version: '0'
|
212
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
|
-
none: false
|
214
197
|
requirements:
|
215
|
-
- -
|
198
|
+
- - '>='
|
216
199
|
- !ruby/object:Gem::Version
|
217
200
|
version: '0'
|
218
201
|
requirements: []
|
219
202
|
rubyforge_project:
|
220
|
-
rubygems_version:
|
203
|
+
rubygems_version: 2.0.3
|
221
204
|
signing_key:
|
222
|
-
specification_version:
|
205
|
+
specification_version: 4
|
223
206
|
summary: A simple HTTP client
|
224
207
|
test_files:
|
225
208
|
- spec/aitch/aitch_spec.rb
|
226
209
|
- spec/aitch/configuration_spec.rb
|
210
|
+
- spec/aitch/dsl_spec.rb
|
227
211
|
- spec/aitch/html_parser_spec.rb
|
228
212
|
- spec/aitch/namespace_spec.rb
|
229
213
|
- spec/aitch/request_spec.rb
|