requests 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d67c50f7401fc9041eb8f16b08678a7e6108af3
4
- data.tar.gz: 5fa1100e1cf5e9fe7e8cc79ed62cd86dcdb8c77a
3
+ metadata.gz: fdcad323fb10dc5bcc26c6ebc615955c31a24871
4
+ data.tar.gz: e1060f1ab04b7a6be93678dcad0d6be75e47fc71
5
5
  SHA512:
6
- metadata.gz: 66ed296c480cfdeac3378899ab157f0eeeda439af19889377fc5cc2b7b1f018fb9ab3f684a61470b8f687c97896132d0a006b25d72322b7356f8f157b166306c
7
- data.tar.gz: 93f73fb42bf94daf8be910c38a1ec2ab05f93b923c4c7379ce8bffcddb471e2384f5bc8fe49c86c38d29353213a6405b7ebeae34774a1880fe596384865a2219
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 = _encode_params(headers: headers, data: data) if data
21
+ body = process_params(headers: headers, data: data) if data
22
22
 
23
- _basic_auth(headers, *auth) if auth
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._basic_auth(headers, user, pass)
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._encode_params(headers: headers, data: data)
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 :status_code
61
+ attr :status
62
62
  attr :headers
63
- attr :content
63
+ attr :body
64
64
 
65
- def initialize(status_code, headers, content)
66
- @status_code, @headers, @content = Integer(status_code), headers, content
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(@content)
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
- @content.encoding
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
- @content
81
+ @body
82
82
  end
83
83
  end
84
84
  end
data/requests.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "requests"
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
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"]
@@ -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.status_code
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: '{ 'plan': 'test' }')
21
+ r = Requests.post('http://httpbin.org/post', data: '{ "plan": "test" }')
22
22
 
23
- assert_equal 200, r.status_code
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.status_code
44
+ assert_equal 200, r.status
45
45
 
46
46
  form = r.json['form']
47
47
 
data/tests/ssl_test.rb CHANGED
@@ -3,5 +3,5 @@ require 'requests'
3
3
  test 'ssl' do
4
4
  response = Requests.request('GET', 'https://httpbin.org/get')
5
5
 
6
- assert_equal 200, response.status_code
6
+ assert_equal 200, response.status
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David