requests 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/requests.rb +11 -11
- data/requests.gemspec +1 -1
- data/tests/requests_test.rb +4 -4
- data/tests/ssl_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdcad323fb10dc5bcc26c6ebc615955c31a24871
|
4
|
+
data.tar.gz: e1060f1ab04b7a6be93678dcad0d6be75e47fc71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6641d4c04922f25b2e8fd2ea8f2913798ad8b8de8364a722a5015e625e934894e431cbfe86bccfa4202f2bffe100b8078a2aa6120a0dbbd6fa45574f0902eb19
|
7
|
+
data.tar.gz: 4933cc26746b1fd7ff6861b2b8692573dbe6a6e7f9f2bd2e31fdcc8ff6a68406e8a0d2b757f7f783993e8ce9b2eb4adce19dc6f371d4ec1827e62c225eac0618
|
data/lib/requests.rb
CHANGED
@@ -18,9 +18,9 @@ module Requests
|
|
18
18
|
uri = URI.parse(url)
|
19
19
|
uri.query = URI.encode_www_form(params) if params
|
20
20
|
|
21
|
-
body =
|
21
|
+
body = process_params(headers: headers, data: data) if data
|
22
22
|
|
23
|
-
|
23
|
+
basic_auth(headers, *auth) if auth
|
24
24
|
|
25
25
|
response = Net::HTTP.start(uri.host, uri.port, opts(uri)) do |http|
|
26
26
|
http.send_request(method, uri, body, headers)
|
@@ -43,11 +43,11 @@ private
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.
|
46
|
+
def self.basic_auth(headers, user, pass)
|
47
47
|
headers['Authorization'] = 'Basic ' + ["#{user}:#{pass}"].pack('m0')
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.
|
50
|
+
def self.process_params(headers: nil, data: nil)
|
51
51
|
if not data.kind_of?(Enumerable)
|
52
52
|
data
|
53
53
|
else
|
@@ -58,27 +58,27 @@ private
|
|
58
58
|
end
|
59
59
|
|
60
60
|
class Response
|
61
|
-
attr :
|
61
|
+
attr :status
|
62
62
|
attr :headers
|
63
|
-
attr :
|
63
|
+
attr :body
|
64
64
|
|
65
|
-
def initialize(
|
66
|
-
@
|
65
|
+
def initialize(status, headers, body)
|
66
|
+
@status, @headers, @body = Integer(status), headers, body
|
67
67
|
end
|
68
68
|
|
69
69
|
# TODO Verify that JSON can parse data without encoding stuff
|
70
70
|
def json
|
71
|
-
JSON.parse(@
|
71
|
+
JSON.parse(@body)
|
72
72
|
end
|
73
73
|
|
74
74
|
# TODO Verify that this is based on content-type header
|
75
75
|
def encoding
|
76
|
-
@
|
76
|
+
@body.encoding
|
77
77
|
end
|
78
78
|
|
79
79
|
# TODO this will probably do something related to encoding if necessary
|
80
80
|
def text
|
81
|
-
@
|
81
|
+
@body
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
data/requests.gemspec
CHANGED
data/tests/requests_test.rb
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
test 'GET' do
|
11
11
|
r = Requests.get('http://httpbin.org/get', params: { foo: 'bar' })
|
12
12
|
|
13
|
-
assert_equal 200, r.
|
13
|
+
assert_equal 200, r.status
|
14
14
|
assert_equal ['application/json'], r.headers['content-type']
|
15
15
|
assert_equal 'UTF-8', r.encoding.to_s
|
16
16
|
|
@@ -18,9 +18,9 @@ test 'GET' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'POST data' do
|
21
|
-
r = Requests.post('http://httpbin.org/post', data: '{
|
21
|
+
r = Requests.post('http://httpbin.org/post', data: '{ "plan": "test" }')
|
22
22
|
|
23
|
-
assert_equal 200, r.
|
23
|
+
assert_equal 200, r.status
|
24
24
|
assert_equal ['application/json'], r.headers['content-type']
|
25
25
|
assert_equal 'UTF-8', r.encoding.to_s
|
26
26
|
|
@@ -41,7 +41,7 @@ test 'POST params' do
|
|
41
41
|
|
42
42
|
r = Requests.post('http://httpbin.org/post', data: payload)
|
43
43
|
|
44
|
-
assert_equal 200, r.
|
44
|
+
assert_equal 200, r.status
|
45
45
|
|
46
46
|
form = r.json['form']
|
47
47
|
|
data/tests/ssl_test.rb
CHANGED