dagger 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/dagger.rb +40 -17
- data/lib/dagger/version.rb +2 -2
- data/{test → spec}/arguments_spec.rb +2 -1
- data/{test → spec}/parsers_spec.rb +1 -1
- data/{test → spec}/persistent_spec.rb +3 -2
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9acd73b4c13d3fbc7d86edc5872e30c64f290c02
|
4
|
+
data.tar.gz: 8ea4011792e0b7b2bd44d5184641c86c6db436df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be7e1806544f1f0212cf64e39614324fbb67f027a3e189ac80292c593ace1adde58ea87f33e80b6fb3b8e4f246cf1556ed69afa39c0a4c8007fb77aff82e07e
|
7
|
+
data.tar.gz: c8d34bf201a266fe07d00f0799b8da950aec0589672aa60d3908a129cd0c733db9cae9aad8cd7604b77c3ca30b5f8182ed2cb251429c88f97319d5e149627803
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ puts resp.code # => 200
|
|
35
35
|
resp = Dagger.put('http://server.com', { foo: 'bar' }, { json: true })
|
36
36
|
|
37
37
|
# now, if the endpoint returned a parseable content-type (e.g. 'application/json')
|
38
|
-
# then `resp.data` will return the parsed result. `body` contains the raw
|
38
|
+
# then `resp.data` will return the parsed result. `body` contains the raw bytes.
|
39
39
|
puts resp.data # => { result: 'GREAT SUCCESS!' }
|
40
40
|
```
|
41
41
|
|
data/lib/dagger.rb
CHANGED
@@ -17,6 +17,7 @@ module Dagger
|
|
17
17
|
module Utils
|
18
18
|
|
19
19
|
def self.parse_uri(uri)
|
20
|
+
raise ArgumentError.new("Empty URI") if uri.to_s.strip == ''
|
20
21
|
uri = 'http://' + uri unless uri.to_s['http']
|
21
22
|
uri = URI.parse(uri)
|
22
23
|
raise ArgumentError.new("Invalid URI: #{uri}") unless uri.is_a?(URI::HTTP)
|
@@ -75,14 +76,32 @@ module Dagger
|
|
75
76
|
request = Net::HTTP::Get.new(path, DEFAULT_HEADERS.merge(opts[:headers] || {}))
|
76
77
|
request.basic_auth(opts.delete(:username), opts.delete(:password)) if opts[:username]
|
77
78
|
|
78
|
-
@
|
79
|
+
@http.start unless @http.started?
|
80
|
+
resp, data = @http.request(request)
|
79
81
|
|
80
|
-
if REDIRECT_CODES.include?(
|
82
|
+
if REDIRECT_CODES.include?(resp.code.to_i) && resp['Location'] && (opts[:follow] && opts[:follow] > 0)
|
81
83
|
opts[:follow] -= 1
|
82
|
-
|
84
|
+
puts "Following redirect to #{resp['Location']}"
|
85
|
+
return get(resp['Location'], nil, opts)
|
83
86
|
end
|
84
87
|
|
85
|
-
response
|
88
|
+
@response = build_response(resp, data || resp.body)
|
89
|
+
end
|
90
|
+
|
91
|
+
def post(uri, data, options = {})
|
92
|
+
request(:post, uri, data, options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def put(uri, data, options = {})
|
96
|
+
request(:put, uri, data, options)
|
97
|
+
end
|
98
|
+
|
99
|
+
def patch(uri, data, options = {})
|
100
|
+
request(:patch, uri, data, options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def delete(uri, data, options = {})
|
104
|
+
request(:delete, uri, data, options)
|
86
105
|
end
|
87
106
|
|
88
107
|
def request(method, uri, data, opts = {})
|
@@ -108,13 +127,23 @@ module Dagger
|
|
108
127
|
args = [method.to_s.downcase, uri.path, query, headers]
|
109
128
|
args.delete_at(2) if args[0] == 'delete' # Net::HTTP's delete does not accept data
|
110
129
|
|
111
|
-
@
|
112
|
-
|
130
|
+
@http.start unless @http.started?
|
131
|
+
resp, data = @http.send(*args)
|
132
|
+
@response = build_response(resp, data || resp.body)
|
113
133
|
end
|
114
134
|
|
115
135
|
def response
|
116
|
-
raise '
|
117
|
-
|
136
|
+
@response or raise 'Request not sent!'
|
137
|
+
end
|
138
|
+
|
139
|
+
def open(&block)
|
140
|
+
@http.start do
|
141
|
+
instance_eval(&block)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def close
|
146
|
+
@http.finish
|
118
147
|
end
|
119
148
|
|
120
149
|
private
|
@@ -130,15 +159,9 @@ module Dagger
|
|
130
159
|
class << self
|
131
160
|
|
132
161
|
def open(uri, opts = {}, &block)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
Net::HTTP.start(uri.host, uri.port, opts) do |http|
|
138
|
-
client = Client.new(http)
|
139
|
-
# yield(client)
|
140
|
-
client.instance_eval(&block)
|
141
|
-
end
|
162
|
+
client = Client.init(uri, opts)
|
163
|
+
client.start(&block) if block_given?
|
164
|
+
client
|
142
165
|
end
|
143
166
|
|
144
167
|
def get(uri, options = {})
|
data/lib/dagger/version.rb
CHANGED
@@ -14,7 +14,8 @@ describe 'arguments' do
|
|
14
14
|
describe 'empty url' do
|
15
15
|
|
16
16
|
it 'raises error' do
|
17
|
-
expect { send_request('') }.to raise_error(URI::InvalidURIError)
|
17
|
+
# expect { send_request('') }.to raise_error(URI::InvalidURIError)
|
18
|
+
expect { send_request('') }.to raise_error(ArgumentError)
|
18
19
|
end
|
19
20
|
|
20
21
|
end
|
@@ -9,7 +9,7 @@ describe 'Parsers' do
|
|
9
9
|
Dagger.post('http://foobar.com/test', { foo: 'bar'})
|
10
10
|
end
|
11
11
|
|
12
|
-
let(:fake_http) { double('Net::HTTP') }
|
12
|
+
let(:fake_http) { double('Net::HTTP', started?: true) }
|
13
13
|
let(:fake_resp) { double('Net::HTTPResponse', code: 200) }
|
14
14
|
|
15
15
|
before do
|
@@ -3,12 +3,13 @@ require './lib/dagger'
|
|
3
3
|
require 'rspec/mocks'
|
4
4
|
require 'rspec/expectations'
|
5
5
|
|
6
|
-
describe '
|
6
|
+
describe 'Persistent mode' do
|
7
7
|
|
8
8
|
it 'works' do
|
9
9
|
fake_client = double('Client')
|
10
10
|
expect(Dagger::Client).to receive(:new).once.and_return(fake_client)
|
11
|
-
expect(fake_client).to receive(:get).twice #.and_return(fake_resp)
|
11
|
+
# expect(fake_client).to receive(:get).twice #.and_return(fake_resp)
|
12
|
+
expect(fake_client).to receive(:start).once #.and_return(fake_resp)
|
12
13
|
|
13
14
|
obj = Dagger.open('https://www.google.com') do
|
14
15
|
get('/search?q=dagger+http+client')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,9 +113,9 @@ files:
|
|
113
113
|
- lib/dagger/parsers.rb
|
114
114
|
- lib/dagger/response.rb
|
115
115
|
- lib/dagger/version.rb
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
116
|
+
- spec/arguments_spec.rb
|
117
|
+
- spec/parsers_spec.rb
|
118
|
+
- spec/persistent_spec.rb
|
119
119
|
homepage: https://github.com/tomas/dagger
|
120
120
|
licenses: []
|
121
121
|
metadata: {}
|
@@ -135,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: 1.3.6
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project: dagger
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.5.1
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Simplified Net::HTTP wrapper.
|
142
142
|
test_files: []
|
143
|
-
has_rdoc:
|