http_mini 0.0.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.
- data/LICENSE +25 -0
- data/README.md +28 -0
- data/lib/http_mini.rb +113 -0
- metadata +66 -0
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Jerome Touffe-Blin
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of Jerome Touffe-Blin nor the names of its contributors
|
13
|
+
may be used to endorse or promote products derived from this software
|
14
|
+
without specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Http mini
|
2
|
+
|
3
|
+
A truly minimalist Http client for Ruby. When all you want is
|
4
|
+
a one liner to ping or get the response.
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
gem install http_mini --no-ri --no-rdoc
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
response = HttpMini.new('http://www.google.com').get
|
13
|
+
puts response.status
|
14
|
+
|
15
|
+
By default, HttpMini ignore errors and return nil in case of error.
|
16
|
+
If you want to raise error, you can set the option on initialization.
|
17
|
+
You can also set values for timeouts.
|
18
|
+
|
19
|
+
response = HttpMini.new('http://www.google.com', {ignore_error: false, open_timeout: 5}).head
|
20
|
+
|
21
|
+
## Author
|
22
|
+
|
23
|
+
Jerome Touffe-Blin, [@jtblin](https://twitter.com/jtlbin), [http://www.linkedin.com/in/jtblin](http://www.linkedin.com/in/jtblin)
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
HttpMini is copyright 2013 Jerome Touffe-Blin and contributors. It is licensed under the BSD license. See the include LICENSE file for details.
|
28
|
+
|
data/lib/http_mini.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
class HttpMini
|
5
|
+
|
6
|
+
attr_reader :uri
|
7
|
+
attr_accessor :opts
|
8
|
+
|
9
|
+
OPEN_TIMEOUT = 2
|
10
|
+
READ_TIMEOUT = 2
|
11
|
+
IGNORE_ERROR = true
|
12
|
+
|
13
|
+
def self.VERSION
|
14
|
+
'0.0.1'
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(url, opts = {})
|
18
|
+
self.uri = url
|
19
|
+
self.opts = opts
|
20
|
+
end
|
21
|
+
|
22
|
+
def head
|
23
|
+
begin
|
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
|
28
|
+
end
|
29
|
+
|
30
|
+
def get
|
31
|
+
begin
|
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
|
36
|
+
end
|
37
|
+
|
38
|
+
def post(data)
|
39
|
+
begin
|
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
|
45
|
+
end
|
46
|
+
|
47
|
+
def put(data)
|
48
|
+
begin
|
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
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete
|
56
|
+
begin
|
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
|
61
|
+
end
|
62
|
+
|
63
|
+
def options
|
64
|
+
begin
|
65
|
+
Net::HTTP.start(host, port) {|http| set_timeout(http) and return http.options(path) }
|
66
|
+
rescue Exception => e
|
67
|
+
raise e unless ignore_error?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def set_timeout(http)
|
74
|
+
http.open_timeout, http.read_timeout = timeouts
|
75
|
+
end
|
76
|
+
|
77
|
+
def uri=(uri)
|
78
|
+
@uri = URI.parse(uri)
|
79
|
+
end
|
80
|
+
|
81
|
+
def url
|
82
|
+
host + path unless uri.nil?
|
83
|
+
end
|
84
|
+
|
85
|
+
def host
|
86
|
+
uri.host unless uri.nil?
|
87
|
+
end
|
88
|
+
|
89
|
+
def port
|
90
|
+
uri.port unless uri.nil?
|
91
|
+
end
|
92
|
+
|
93
|
+
def path
|
94
|
+
uri.nil? || uri.path.empty? ? '/' : uri.path
|
95
|
+
end
|
96
|
+
|
97
|
+
def timeouts
|
98
|
+
[open_timeout, read_timeout]
|
99
|
+
end
|
100
|
+
|
101
|
+
def open_timeout
|
102
|
+
opts[:open_timeout].nil? ? OPEN_TIMEOUT : opts[:open_timeout]
|
103
|
+
end
|
104
|
+
|
105
|
+
def read_timeout
|
106
|
+
opts[:read_timeout].nil? ? READ_TIMEOUT : opts[:read_timeout]
|
107
|
+
end
|
108
|
+
|
109
|
+
def ignore_error?
|
110
|
+
opts[:ignore_error].nil? ? IGNORE_ERROR : opts[:ignore_error]
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_mini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jerome Touffe-Blin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
description: A minimalist wrapper over Http::Net
|
31
|
+
email: jtblin@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
files:
|
38
|
+
- lib/http_mini.rb
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
homepage: http://github.com/jtblin/http_mini
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.3.6
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.25
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: A truly minimalist Http Ruby client
|
66
|
+
test_files: []
|