aitch 0.3.0 → 0.4.0
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/.travis.yml +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +37 -42
- data/README.md +1 -1
- data/aitch.gemspec +0 -1
- data/lib/aitch/request.rb +14 -5
- data/lib/aitch/version.rb +1 -1
- data/spec/aitch/aitch_spec.rb +5 -8
- data/spec/aitch/html_parser_spec.rb +1 -4
- data/spec/aitch/request_spec.rb +19 -3
- data/spec/aitch/response_spec.rb +1 -1
- data/spec/aitch/xml_parser_spec.rb +1 -4
- data/spec/spec_helper.rb +4 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de38868979f48b300cc6c7bcf89867eb5a6c763f
|
4
|
+
data.tar.gz: 44071a93ca9d00f5adb3f8324ae12421818ae63d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f5737e0c0ace3b19f464c54020194d3a7ba5debef88853e6c93248f7ae4845447d830f4852c3fcdcdee351f7afde456df37107dcf2bd309053bf98a9d7d21f
|
7
|
+
data.tar.gz: 6adb9a4df4c44b6ff700ba5e2e9f49fa42d65eed09cfd3800a462b947c1389f414bff7efb9409b88f3aa1abe173fb38c9d75f8c94a9c66879f7ddda685669423
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,69 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aitch (0.
|
4
|
+
aitch (0.4.0)
|
5
5
|
activesupport
|
6
6
|
nokogiri (>= 1.6.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (4.
|
11
|
+
activesupport (4.1.8)
|
12
12
|
i18n (~> 0.6, >= 0.6.9)
|
13
|
-
|
14
|
-
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
15
|
thread_safe (~> 0.1)
|
16
|
-
tzinfo (~>
|
17
|
-
atomic (1.1.16)
|
16
|
+
tzinfo (~> 1.1)
|
18
17
|
awesome_print (1.2.0)
|
19
18
|
coderay (1.1.0)
|
20
|
-
columnize (0.3.6)
|
21
|
-
debugger (1.6.6)
|
22
|
-
columnize (>= 0.3.1)
|
23
|
-
debugger-linecache (~> 1.2.0)
|
24
|
-
debugger-ruby_core_source (~> 1.3.2)
|
25
|
-
debugger-linecache (1.2.0)
|
26
|
-
debugger-ruby_core_source (1.3.2)
|
27
19
|
diff-lcs (1.2.5)
|
28
20
|
fakeweb (1.3.0)
|
29
|
-
i18n (0.6.
|
21
|
+
i18n (0.6.11)
|
22
|
+
json (1.8.1)
|
30
23
|
method_source (0.8.2)
|
31
|
-
mini_portile (0.
|
32
|
-
minitest (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
method_source (~> 0.8)
|
24
|
+
mini_portile (0.6.1)
|
25
|
+
minitest (5.5.0)
|
26
|
+
nokogiri (1.6.5)
|
27
|
+
mini_portile (~> 0.6.0)
|
28
|
+
notifier (0.5.0)
|
29
|
+
pry (0.10.1)
|
30
|
+
coderay (~> 1.1.0)
|
31
|
+
method_source (~> 0.8.1)
|
40
32
|
slop (~> 3.4)
|
41
|
-
pry-
|
42
|
-
debugger (~> 1.3)
|
43
|
-
pry (~> 0.9.10)
|
44
|
-
pry-meta (0.0.6)
|
33
|
+
pry-meta (0.0.9)
|
45
34
|
awesome_print
|
46
35
|
pry
|
47
|
-
pry-
|
36
|
+
pry-nav
|
48
37
|
pry-remote
|
38
|
+
pry-nav (0.2.4)
|
39
|
+
pry (>= 0.9.10, < 0.11.0)
|
49
40
|
pry-remote (0.1.8)
|
50
41
|
pry (~> 0.9)
|
51
42
|
slop (~> 3.0)
|
52
|
-
rake (10.
|
53
|
-
rspec (
|
54
|
-
rspec-core (~>
|
55
|
-
rspec-expectations (~>
|
56
|
-
rspec-mocks (~>
|
57
|
-
rspec-core (
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
rake (10.4.2)
|
44
|
+
rspec (3.1.0)
|
45
|
+
rspec-core (~> 3.1.0)
|
46
|
+
rspec-expectations (~> 3.1.0)
|
47
|
+
rspec-mocks (~> 3.1.0)
|
48
|
+
rspec-core (3.1.7)
|
49
|
+
rspec-support (~> 3.1.0)
|
50
|
+
rspec-expectations (3.1.2)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.1.0)
|
53
|
+
rspec-mocks (3.1.3)
|
54
|
+
rspec-support (~> 3.1.0)
|
55
|
+
rspec-support (3.1.2)
|
56
|
+
slop (3.6.0)
|
57
|
+
test_notifier (2.0.3)
|
63
58
|
notifier
|
64
|
-
thread_safe (0.3.
|
65
|
-
|
66
|
-
|
59
|
+
thread_safe (0.3.4)
|
60
|
+
tzinfo (1.2.2)
|
61
|
+
thread_safe (~> 0.1)
|
67
62
|
|
68
63
|
PLATFORMS
|
69
64
|
ruby
|
data/README.md
CHANGED
data/aitch.gemspec
CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
|
-
spec.add_development_dependency "pry-meta"
|
28
27
|
spec.add_development_dependency "test_notifier"
|
29
28
|
spec.add_development_dependency "fakeweb"
|
30
29
|
end
|
data/lib/aitch/request.rb
CHANGED
@@ -7,12 +7,12 @@ module Aitch
|
|
7
7
|
attr_accessor :options
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
+
self.headers ||= {}
|
11
|
+
self.options ||= {}
|
12
|
+
|
10
13
|
options.each do |name, value|
|
11
14
|
public_send("#{name}=", value)
|
12
15
|
end
|
13
|
-
|
14
|
-
self.headers ||= {}
|
15
|
-
self.options ||= {}
|
16
16
|
end
|
17
17
|
|
18
18
|
def perform
|
@@ -35,6 +35,14 @@ module Aitch
|
|
35
35
|
raise RequestTimeoutError
|
36
36
|
end
|
37
37
|
|
38
|
+
def content_type=(content_type)
|
39
|
+
headers['Content-Type'] = content_type
|
40
|
+
end
|
41
|
+
|
42
|
+
def content_type
|
43
|
+
headers['Content-Type']
|
44
|
+
end
|
45
|
+
|
38
46
|
def request
|
39
47
|
@request ||= http_method_class.new(uri.request_uri).tap do |request|
|
40
48
|
set_body(request) if request.request_body_permitted?
|
@@ -65,13 +73,14 @@ module Aitch
|
|
65
73
|
|
66
74
|
private
|
67
75
|
def set_body(request)
|
76
|
+
body_data = data
|
68
77
|
body_data = data.to_h if data.respond_to?(:to_h)
|
69
|
-
body_data
|
78
|
+
body_data = options[:json_parser].dump(body_data) if content_type.to_s =~ /\bjson\b/
|
70
79
|
|
71
80
|
if body_data.kind_of?(Hash)
|
72
81
|
request.body = Utils.build_query(body_data)
|
73
82
|
else
|
74
|
-
request.body =
|
83
|
+
request.body = body_data.to_s
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
data/lib/aitch/version.rb
CHANGED
data/spec/aitch/aitch_spec.rb
CHANGED
@@ -38,17 +38,14 @@ describe Aitch do
|
|
38
38
|
options: options.merge(Aitch.config.to_h)
|
39
39
|
}
|
40
40
|
|
41
|
-
Aitch::Request
|
42
|
-
.should_receive(:new)
|
43
|
-
.with(expected)
|
44
|
-
.and_return(request)
|
41
|
+
expect(Aitch::Request).to receive(:new).with(expected).and_return(request)
|
45
42
|
|
46
43
|
Aitch.get("URL", "DATA", "HEADERS", options)
|
47
44
|
end
|
48
45
|
|
49
46
|
it "performs request" do
|
50
|
-
Aitch::Request.
|
51
|
-
request.
|
47
|
+
allow(Aitch::Request).to receive(:new).and_return(request)
|
48
|
+
expect(request).to receive(:perform)
|
52
49
|
|
53
50
|
Aitch.get("URL")
|
54
51
|
end
|
@@ -57,14 +54,14 @@ describe Aitch do
|
|
57
54
|
describe "#execute!" do
|
58
55
|
it "returns response when successful" do
|
59
56
|
response = double(error?: false)
|
60
|
-
Aitch::Request.
|
57
|
+
allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)
|
61
58
|
|
62
59
|
expect(Aitch.get!("URL")).to eql(response)
|
63
60
|
end
|
64
61
|
|
65
62
|
it "raises when has errors" do
|
66
63
|
response = double(error?: true, error: "ERROR")
|
67
|
-
Aitch::Request.
|
64
|
+
allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)
|
68
65
|
|
69
66
|
expect {
|
70
67
|
Aitch.get!("URL")
|
data/spec/aitch/request_spec.rb
CHANGED
@@ -9,6 +9,11 @@ describe Aitch::Request do
|
|
9
9
|
}.merge(options))
|
10
10
|
end
|
11
11
|
|
12
|
+
it "sets content type" do
|
13
|
+
request = build_request(content_type: 'application/json')
|
14
|
+
expect(request.content_type).to eq('application/json')
|
15
|
+
end
|
16
|
+
|
12
17
|
it "raises with invalid uri" do
|
13
18
|
expect {
|
14
19
|
build_request(url: "\\").uri
|
@@ -17,7 +22,7 @@ describe Aitch::Request do
|
|
17
22
|
|
18
23
|
it "raises on timeout", ruby: 2.0 do
|
19
24
|
request = build_request(request_method: "post", url: "http://example.org")
|
20
|
-
request.
|
25
|
+
allow(request).to receive_message_chain(:client, :request).and_raise(Net::ReadTimeout)
|
21
26
|
|
22
27
|
expect {
|
23
28
|
request.perform
|
@@ -26,7 +31,7 @@ describe Aitch::Request do
|
|
26
31
|
|
27
32
|
it "raises on timeout", ruby: 1.9 do
|
28
33
|
request = build_request(request_method: "post", url: "http://example.org")
|
29
|
-
request.
|
34
|
+
allow(request).to receive_message_chain(:client, :request).and_raise(Timeout::Error)
|
30
35
|
|
31
36
|
expect {
|
32
37
|
request.perform
|
@@ -59,6 +64,17 @@ describe Aitch::Request do
|
|
59
64
|
expect(request.body).to eql("some body")
|
60
65
|
end
|
61
66
|
|
67
|
+
it "sets json body from object" do
|
68
|
+
request = build_request(
|
69
|
+
request_method: "post",
|
70
|
+
data: {a: 1},
|
71
|
+
content_type: "application/json",
|
72
|
+
options: {json_parser: JSON}
|
73
|
+
).request
|
74
|
+
|
75
|
+
expect(request.body).to eql({a: 1}.to_json)
|
76
|
+
end
|
77
|
+
|
62
78
|
it "sets request body from to_h protocol" do
|
63
79
|
data = double(to_h: {a: 1})
|
64
80
|
request = build_request(request_method: "post", data: data).request
|
@@ -110,7 +126,7 @@ describe Aitch::Request do
|
|
110
126
|
subject(:client) { request.client }
|
111
127
|
|
112
128
|
it "sets https" do
|
113
|
-
expect(client.use_ssl?).to
|
129
|
+
expect(client.use_ssl?).to be_truthy
|
114
130
|
end
|
115
131
|
|
116
132
|
it "sets verification mode" do
|
data/spec/aitch/response_spec.rb
CHANGED
@@ -208,7 +208,7 @@ describe Aitch::Response do
|
|
208
208
|
config = double
|
209
209
|
http_response = double(code: code)
|
210
210
|
response = Aitch::Response.new(config, http_response)
|
211
|
-
expect(response.public_send("#{name}?")).to
|
211
|
+
expect(response.public_send("#{name}?")).to be_truthy
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-meta
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: test_notifier
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|