http_mini 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +9 -0
- data/lib/http_mini.rb +21 -21
- data/lib/request.rb +17 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2043cd9aeffdf055e5fde5eadcc7f0b41f77e15
|
4
|
+
data.tar.gz: fe4aa4a6c61b5e69adb0e507389264e89d2a83d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c28d37b8acafd27471987a48633b3fe36c27e052ff80cd8f879603963078bab050a29e55b0509324a1e5ef236fb896bdfbf571dc9e7809c4cc397209af2e88
|
7
|
+
data.tar.gz: 32119819d2015104e88e0aeb377522a0e2eede3d5dbf20172fc9d439c658b09b93b4b893f9b61b09616998947a9fcca11075a109b5d660d8abf9c24bb6c80aec
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -31,6 +31,9 @@ a one liner to ping or get the response from a web server.
|
|
31
31
|
# or just the path
|
32
32
|
http_request_html = http.path('/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTPRequest.html').get.body
|
33
33
|
|
34
|
+
# Set http headers
|
35
|
+
puts HttpMini.new('http://www.google.com', headers: {'user-agent' => 'Fancy UserAgent Name'}).head.code
|
36
|
+
|
34
37
|
## HTTP verbs Support
|
35
38
|
|
36
39
|
* HEAD
|
@@ -40,6 +43,12 @@ a one liner to ping or get the response from a web server.
|
|
40
43
|
* DELETE
|
41
44
|
* OPTIONS
|
42
45
|
|
46
|
+
## Request options
|
47
|
+
|
48
|
+
* `:headers` - http headers, defaults to {}
|
49
|
+
* `:open_timeout` - number of seconds to wait for the connection to open, defaults to 2
|
50
|
+
* `:read_timeout` - number of seconds to wait for one block to be read, defaults to 2
|
51
|
+
|
43
52
|
## Author
|
44
53
|
|
45
54
|
Jerome Touffe-Blin, [@jtblin](https://twitter.com/jtlbin), [http://www.linkedin.com/in/jtblin](http://www.linkedin.com/in/jtblin)
|
data/lib/http_mini.rb
CHANGED
@@ -10,36 +10,36 @@ class HttpMini
|
|
10
10
|
IGNORE_ERROR = true
|
11
11
|
|
12
12
|
def self.VERSION
|
13
|
-
'0.2.
|
13
|
+
'0.2.3'
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(
|
17
|
-
self.uri =
|
16
|
+
def initialize(uri, opts = {})
|
17
|
+
self.uri = uri
|
18
18
|
self.opts = opts
|
19
19
|
end
|
20
20
|
|
21
21
|
def head
|
22
|
-
request
|
22
|
+
request Net::HTTP::Head.new(full_path)
|
23
23
|
end
|
24
24
|
|
25
25
|
def get
|
26
|
-
request
|
26
|
+
request Net::HTTP::Get.new(full_path)
|
27
27
|
end
|
28
28
|
|
29
29
|
def post(data)
|
30
|
-
request
|
30
|
+
request Net::HTTP::Post.new(full_path), data
|
31
31
|
end
|
32
32
|
|
33
33
|
def put(data)
|
34
|
-
request
|
34
|
+
request Net::HTTP::Put.new(full_path), data
|
35
35
|
end
|
36
36
|
|
37
37
|
def delete
|
38
|
-
request
|
38
|
+
request Net::HTTP::Delete.new(full_path)
|
39
39
|
end
|
40
40
|
|
41
41
|
def options
|
42
|
-
request
|
42
|
+
request Net::HTTP::Options.new(full_path)
|
43
43
|
end
|
44
44
|
|
45
45
|
def poke
|
@@ -57,7 +57,7 @@ class HttpMini
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def host
|
60
|
-
@uri.host
|
60
|
+
@uri.host
|
61
61
|
end
|
62
62
|
|
63
63
|
def port
|
@@ -65,7 +65,7 @@ class HttpMini
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def path(path=nil)
|
68
|
-
path.nil? ?
|
68
|
+
path.nil? ? default_path(@uri.path) : set_path(path)
|
69
69
|
end
|
70
70
|
|
71
71
|
private
|
@@ -78,8 +78,8 @@ class HttpMini
|
|
78
78
|
uri.match(/https?:\/\//) ? uri : "http://#{uri}"
|
79
79
|
end
|
80
80
|
|
81
|
-
def request
|
82
|
-
Net::HTTP.start(host, port, :use_ssl => ssl?) {|http| set_timeout(http) and
|
81
|
+
def request(req, data=nil)
|
82
|
+
Net::HTTP.start(host, port, :use_ssl => ssl?) { |http| set_timeout(http) and http.request(set_headers(req), data) }
|
83
83
|
end
|
84
84
|
|
85
85
|
def ssl?
|
@@ -90,20 +90,20 @@ class HttpMini
|
|
90
90
|
http.open_timeout, http.read_timeout = timeouts
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
93
|
+
def set_headers(req)
|
94
|
+
headers.each { |key, value| req[key] = value } and return req
|
95
95
|
end
|
96
96
|
|
97
|
-
def
|
98
|
-
|
97
|
+
def headers
|
98
|
+
opts[:headers] || {}
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
102
|
-
|
101
|
+
def full_path
|
102
|
+
@uri.query ? path + '?' + @uri.query : path
|
103
103
|
end
|
104
104
|
|
105
|
-
def
|
106
|
-
path.to_s.
|
105
|
+
def default_path(path)
|
106
|
+
path.to_s.empty? ? '/' : path
|
107
107
|
end
|
108
108
|
|
109
109
|
def set_path(path)
|
data/lib/request.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_mini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerome Touffe-Blin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -76,6 +76,7 @@ extra_rdoc_files:
|
|
76
76
|
- CHANGELOG.md
|
77
77
|
files:
|
78
78
|
- lib/http_mini.rb
|
79
|
+
- lib/request.rb
|
79
80
|
- LICENSE
|
80
81
|
- README.md
|
81
82
|
- CHANGELOG.md
|