requests 0.0.1 → 0.0.2
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/lib/requests.rb +15 -24
- data/makefile +2 -0
- data/requests.gemspec +2 -2
- data/tests/requests_test.rb +19 -19
- data/tests/ssl_test.rb +7 -0
- metadata +5 -4
- data/README +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4384da6fa569599a07f1892ee44b3a95d5b46c77
|
4
|
+
data.tar.gz: bd021ee8370d0ee4e49dfc5709803eb38e6e9af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 331205ff6ad5a1fe0c6af031c7941f6017a13d88cbd04c141937925f89c4c07701bbaf55f2c0261be721ec9282ee204741b19ecc907ac6add0a6360fa938c50f
|
7
|
+
data.tar.gz: ea1c2ee5d1b82b5d73400ab934a056b362ee7ce2b072efc54b2b0398ea97a996a8586b3f7b95ef236e33c3a60c8aba6c43eef3add290ca9db33bea6ebce452ef
|
data/lib/requests.rb
CHANGED
@@ -1,31 +1,13 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
+
require 'openssl'
|
3
4
|
require 'uri'
|
4
5
|
|
5
6
|
module Requests
|
6
|
-
|
7
|
-
request('GET', url, **kwargs)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.post(url, data: nil, **kwargs)
|
11
|
-
request('POST', url, data: data, **kwargs)
|
12
|
-
end
|
7
|
+
Error = Class.new(StandardError)
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.delete(url, **kwargs)
|
19
|
-
request('DELETE', url, **kwargs)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.head(url, **kwargs)
|
23
|
-
request('HEAD', url, **kwargs)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.options(url, **kwargs)
|
27
|
-
request('OPTIONS', url, **kwargs)
|
28
|
-
end
|
9
|
+
CA_FILE = ENV.fetch('REQUESTS_CA_FILE',
|
10
|
+
File.expand_path('../cacert.pem', __FILE__))
|
29
11
|
|
30
12
|
def self.request(method, url,
|
31
13
|
headers: {},
|
@@ -40,18 +22,27 @@ module Requests
|
|
40
22
|
|
41
23
|
_basic_auth(headers, *auth) if auth
|
42
24
|
|
43
|
-
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
25
|
+
response = Net::HTTP.start(uri.host, uri.port, opts(uri)) do |http|
|
44
26
|
http.send_request(method, uri, body, headers)
|
45
27
|
end
|
46
28
|
|
47
29
|
if response.is_a?(Net::HTTPSuccess)
|
48
30
|
Response.new(response.code, response.to_hash, response.body)
|
49
31
|
else
|
50
|
-
raise response.inspect
|
32
|
+
raise Error, response.inspect
|
51
33
|
end
|
52
34
|
end
|
53
35
|
|
54
36
|
private
|
37
|
+
def self.opts(uri)
|
38
|
+
if uri.scheme == 'https'
|
39
|
+
{ use_ssl: true,
|
40
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER,
|
41
|
+
ca_file: CA_FILE
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
55
46
|
def self._basic_auth(headers, user, pass)
|
56
47
|
headers['Authorization'] = 'Basic ' + ["#{user}:#{pass}"].pack('m0')
|
57
48
|
end
|
data/makefile
ADDED
data/requests.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "requests"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
s.summary = "Requests: HTTP for Humans (Ruby port)"
|
7
7
|
s.description = "Because Requests for Python is awesome"
|
8
8
|
s.authors = ["Cyril David"]
|
9
9
|
s.email= ["cyx@cyx.is"]
|
10
|
-
s.homepage = "http://
|
10
|
+
s.homepage = "http://github.com/cyx/requests"
|
11
11
|
s.files = Dir[
|
12
12
|
"LICENSE",
|
13
13
|
"README",
|
data/tests/requests_test.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require 'requests/sugar'
|
2
2
|
|
3
|
-
test
|
4
|
-
r = Requests.get(
|
3
|
+
test 'basic auth' do
|
4
|
+
r = Requests.get('http://httpbin.org/basic-auth/u/p', auth: ['u', 'p'])
|
5
5
|
|
6
|
-
assert_equal r.json[
|
7
|
-
assert_equal r.json[
|
6
|
+
assert_equal r.json['authenticated'], true
|
7
|
+
assert_equal r.json['user'], 'u'
|
8
8
|
end
|
9
9
|
|
10
|
-
test
|
11
|
-
r = Requests.get(
|
10
|
+
test 'GET' do
|
11
|
+
r = Requests.get('http://httpbin.org/get', params: { foo: 'bar' })
|
12
12
|
|
13
13
|
assert_equal 200, r.status_code
|
14
|
-
assert_equal [
|
15
|
-
assert_equal
|
14
|
+
assert_equal ['application/json'], r.headers['content-type']
|
15
|
+
assert_equal 'UTF-8', r.encoding.to_s
|
16
16
|
|
17
|
-
assert(r.json[
|
17
|
+
assert(r.json['args'] && r.json['args']['foo'] == 'bar')
|
18
18
|
end
|
19
19
|
|
20
|
-
test
|
21
|
-
r = Requests.post(
|
20
|
+
test 'POST data' do
|
21
|
+
r = Requests.post('http://httpbin.org/post', data: '{ 'plan': 'test' }')
|
22
22
|
|
23
23
|
assert_equal 200, r.status_code
|
24
|
-
assert_equal [
|
25
|
-
assert_equal
|
24
|
+
assert_equal ['application/json'], r.headers['content-type']
|
25
|
+
assert_equal 'UTF-8', r.encoding.to_s
|
26
26
|
|
27
|
-
assert(r.json[
|
27
|
+
assert(r.json['json'] && r.json['json'] == { 'plan' => 'test' })
|
28
28
|
end
|
29
29
|
|
30
|
-
test
|
30
|
+
test 'PUT data' do
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
test
|
34
|
+
test 'POST params' do
|
35
35
|
payload = [
|
36
36
|
['a[]', 'a1'],
|
37
37
|
['a[]', 'a2'],
|
@@ -39,11 +39,11 @@ test "POST params" do
|
|
39
39
|
['c', '4']
|
40
40
|
]
|
41
41
|
|
42
|
-
r = Requests.post(
|
42
|
+
r = Requests.post('http://httpbin.org/post', data: payload)
|
43
43
|
|
44
44
|
assert_equal 200, r.status_code
|
45
45
|
|
46
|
-
form = r.json[
|
46
|
+
form = r.json['form']
|
47
47
|
|
48
48
|
assert_equal form['a[]'], ['a1', 'a2']
|
49
49
|
assert_equal form['b'], '3'
|
data/tests/ssl_test.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: requests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril David
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -32,11 +32,12 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- LICENSE
|
35
|
-
-
|
35
|
+
- makefile
|
36
36
|
- lib/requests.rb
|
37
37
|
- tests/requests_test.rb
|
38
|
+
- tests/ssl_test.rb
|
38
39
|
- requests.gemspec
|
39
|
-
homepage: http://
|
40
|
+
homepage: http://github.com/cyx/requests
|
40
41
|
licenses:
|
41
42
|
- MIT
|
42
43
|
metadata: {}
|
data/README
DELETED