http_mini 0.0.1 → 0.1.0
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.
- data/lib/http_mini.rb +16 -37
- metadata +2 -2
data/lib/http_mini.rb
CHANGED
@@ -11,7 +11,7 @@ class HttpMini
|
|
11
11
|
IGNORE_ERROR = true
|
12
12
|
|
13
13
|
def self.VERSION
|
14
|
-
'0.0
|
14
|
+
'0.1.0'
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize(url, opts = {})
|
@@ -20,56 +20,39 @@ class HttpMini
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def head
|
23
|
-
|
24
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.head(path) }
|
25
|
-
rescue Exception => e
|
26
|
-
raise e unless ignore_error?
|
27
|
-
end
|
23
|
+
request { |http| http.head(path) }
|
28
24
|
end
|
29
25
|
|
30
26
|
def get
|
31
|
-
|
32
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.get(path) }
|
33
|
-
rescue Exception => e
|
34
|
-
raise e unless ignore_error?
|
35
|
-
end
|
27
|
+
request { |http| http.get(path) }
|
36
28
|
end
|
37
29
|
|
38
30
|
def post(data)
|
39
|
-
|
40
|
-
#Net::HTTP.post_form(uri, data)
|
41
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.post(path, data) }
|
42
|
-
rescue Exception => e
|
43
|
-
raise e unless ignore_error?
|
44
|
-
end
|
31
|
+
request { |http| http.post(path, data) }
|
45
32
|
end
|
46
33
|
|
47
34
|
def put(data)
|
48
|
-
|
49
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.put(path, data) }
|
50
|
-
rescue Exception => e
|
51
|
-
raise e unless ignore_error?
|
52
|
-
end
|
35
|
+
request { |http| http.put(path, data) }
|
53
36
|
end
|
54
37
|
|
55
38
|
def delete
|
56
|
-
|
57
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.delete(path) }
|
58
|
-
rescue Exception => e
|
59
|
-
raise e unless ignore_error?
|
60
|
-
end
|
39
|
+
request { |http| http.delete(path) }
|
61
40
|
end
|
62
41
|
|
63
42
|
def options
|
43
|
+
request { |http| http.options(path) }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def request
|
64
49
|
begin
|
65
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and
|
50
|
+
Net::HTTP.start(host, port) {|http| set_timeout(http) and yield(http) }
|
66
51
|
rescue Exception => e
|
67
52
|
raise e unless ignore_error?
|
68
53
|
end
|
69
54
|
end
|
70
55
|
|
71
|
-
private
|
72
|
-
|
73
56
|
def set_timeout(http)
|
74
57
|
http.open_timeout, http.read_timeout = timeouts
|
75
58
|
end
|
@@ -78,20 +61,16 @@ class HttpMini
|
|
78
61
|
@uri = URI.parse(uri)
|
79
62
|
end
|
80
63
|
|
81
|
-
def url
|
82
|
-
host + path unless uri.nil?
|
83
|
-
end
|
84
|
-
|
85
64
|
def host
|
86
|
-
uri.host
|
65
|
+
uri.host
|
87
66
|
end
|
88
67
|
|
89
68
|
def port
|
90
|
-
uri.port
|
69
|
+
uri.port
|
91
70
|
end
|
92
71
|
|
93
72
|
def path
|
94
|
-
uri.
|
73
|
+
uri.path.empty? ? '/' : uri.path
|
95
74
|
end
|
96
75
|
|
97
76
|
def timeouts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_mini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- lib/http_mini.rb
|
39
39
|
- LICENSE
|
40
40
|
- README.md
|
41
|
-
homepage:
|
41
|
+
homepage: https://github.com/jtblin/http_mini
|
42
42
|
licenses: []
|
43
43
|
post_install_message:
|
44
44
|
rdoc_options:
|