http_mini 0.1.0 → 0.1.1
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 +7 -0
- data/README.md +5 -4
- data/lib/http_mini.rb +24 -8
- metadata +9 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c14ebc6a6a6761adaf2059bb214850352ecc1192
|
4
|
+
data.tar.gz: d343592b5140e93b5fafda7ffaff3923bd9022ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37ffe22641095826163b6279fa61b3060d6db430be8decace7bda021ff05eb88fd7f47ee81775443ef000629c368a59a45a9592cf223290befc8bb67a739ad4b
|
7
|
+
data.tar.gz: 244cd5069a0b6ae89a5897cb02167e957a629c0c2758f9f6be2b50e86a8853f899af23ffa450a8cd8c608b16517469639040f22527918c98d753ed7d3afbaca2
|
data/README.md
CHANGED
@@ -9,14 +9,15 @@ a one liner to ping or get the response.
|
|
9
9
|
|
10
10
|
## Usage
|
11
11
|
|
12
|
-
response = HttpMini.new('http://www.google.com').
|
13
|
-
puts response.
|
12
|
+
response = HttpMini.new('http://www.google.com').head
|
13
|
+
puts response.code
|
14
14
|
|
15
|
-
By default, HttpMini
|
15
|
+
By default, HttpMini ignores errors and will return nil in case of error.
|
16
16
|
If you want to raise error, you can set the option on initialization.
|
17
17
|
You can also set values for timeouts.
|
18
18
|
|
19
|
-
response = HttpMini.new('http://www.google.com', {ignore_error: false, open_timeout: 5}).
|
19
|
+
response = HttpMini.new('http://www.google.com', {ignore_error: false, open_timeout: 5}).get
|
20
|
+
puts response.body
|
20
21
|
|
21
22
|
## Author
|
22
23
|
|
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.1.
|
14
|
+
'0.1.1'
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize(url, opts = {})
|
@@ -43,26 +43,34 @@ class HttpMini
|
|
43
43
|
request { |http| http.options(path) }
|
44
44
|
end
|
45
45
|
|
46
|
+
def ping
|
47
|
+
success? head
|
48
|
+
end
|
49
|
+
|
46
50
|
private
|
47
51
|
|
48
52
|
def request
|
49
53
|
begin
|
50
|
-
Net::HTTP.start(host, port) {|http| set_timeout(http) and yield(http) }
|
54
|
+
Net::HTTP.start(host, port, :use_ssl => ssl?) {|http| set_timeout(http) and yield(http) }
|
51
55
|
rescue Exception => e
|
52
56
|
raise e unless ignore_error?
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
|
-
def set_timeout(http)
|
57
|
-
http.open_timeout, http.read_timeout = timeouts
|
58
|
-
end
|
59
|
-
|
60
60
|
def uri=(uri)
|
61
61
|
@uri = URI.parse(uri)
|
62
62
|
end
|
63
63
|
|
64
|
+
def ssl?
|
65
|
+
uri.scheme == 'https'
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_timeout(http)
|
69
|
+
http.open_timeout, http.read_timeout = timeouts
|
70
|
+
end
|
71
|
+
|
64
72
|
def host
|
65
|
-
uri.host
|
73
|
+
uri.host || uri.path.split('/').first
|
66
74
|
end
|
67
75
|
|
68
76
|
def port
|
@@ -70,7 +78,11 @@ class HttpMini
|
|
70
78
|
end
|
71
79
|
|
72
80
|
def path
|
73
|
-
uri.path.
|
81
|
+
root? uri.path.gsub(Regexp.new('^' + host), '')
|
82
|
+
end
|
83
|
+
|
84
|
+
def root?(path)
|
85
|
+
path.empty? ? '/' : path
|
74
86
|
end
|
75
87
|
|
76
88
|
def timeouts
|
@@ -89,4 +101,8 @@ class HttpMini
|
|
89
101
|
opts[:ignore_error].nil? ? IGNORE_ERROR : opts[:ignore_error]
|
90
102
|
end
|
91
103
|
|
104
|
+
def success?(response)
|
105
|
+
response && response.code.to_i >= 200 && response.code.to_i < 300 ? true : false
|
106
|
+
end
|
107
|
+
|
92
108
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_mini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jerome Touffe-Blin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sinatra
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.3.0
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.3.0
|
30
27
|
description: A minimalist wrapper over Http::Net
|
@@ -40,27 +37,26 @@ files:
|
|
40
37
|
- README.md
|
41
38
|
homepage: https://github.com/jtblin/http_mini
|
42
39
|
licenses: []
|
40
|
+
metadata: {}
|
43
41
|
post_install_message:
|
44
42
|
rdoc_options:
|
45
43
|
- --charset=UTF-8
|
46
44
|
require_paths:
|
47
45
|
- lib
|
48
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
47
|
requirements:
|
51
|
-
- -
|
48
|
+
- - '>='
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '0'
|
54
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
52
|
requirements:
|
57
|
-
- -
|
53
|
+
- - '>='
|
58
54
|
- !ruby/object:Gem::Version
|
59
55
|
version: 1.3.6
|
60
56
|
requirements: []
|
61
57
|
rubyforge_project:
|
62
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.0.5
|
63
59
|
signing_key:
|
64
|
-
specification_version:
|
60
|
+
specification_version: 4
|
65
61
|
summary: A truly minimalist Http Ruby client
|
66
62
|
test_files: []
|