Class: HttpMini
- Inherits:
-
Object
- Object
- HttpMini
- Defined in:
- lib/http_mini.rb
Constant Summary collapse
- OPEN_TIMEOUT =
2- READ_TIMEOUT =
2- IGNORE_ERROR =
true
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #get ⇒ Object
- #head ⇒ Object
- #host ⇒ Object
-
#initialize(url, opts = {}) ⇒ HttpMini
constructor
A new instance of HttpMini.
- #options ⇒ Object
- #path(path = nil) ⇒ Object
- #poke ⇒ Object (also: #ping)
- #port ⇒ Object
- #post(data) ⇒ Object
- #put(data) ⇒ Object
- #uri(uri = nil) ⇒ Object
Constructor Details
#initialize(url, opts = {}) ⇒ HttpMini
Returns a new instance of HttpMini.
16 17 18 19 |
# File 'lib/http_mini.rb', line 16 def initialize(url, opts = {}) self.uri = url self.opts = opts end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
6 7 8 |
# File 'lib/http_mini.rb', line 6 def opts @opts end |
Class Method Details
.VERSION ⇒ Object
12 13 14 |
# File 'lib/http_mini.rb', line 12 def self.VERSION '0.2.1' end |
Instance Method Details
#delete ⇒ Object
37 38 39 |
# File 'lib/http_mini.rb', line 37 def delete request { |http| http.delete(full_path) } end |
#get ⇒ Object
25 26 27 |
# File 'lib/http_mini.rb', line 25 def get request { |http| http.get(full_path) } end |
#head ⇒ Object
21 22 23 |
# File 'lib/http_mini.rb', line 21 def head request { |http| http.head(full_path) } end |
#host ⇒ Object
59 60 61 |
# File 'lib/http_mini.rb', line 59 def host @uri.host || @uri.path.split('/').first end |
#options ⇒ Object
41 42 43 |
# File 'lib/http_mini.rb', line 41 def request { |http| http.(full_path) } end |
#path(path = nil) ⇒ Object
67 68 69 |
# File 'lib/http_mini.rb', line 67 def path(path=nil) path.nil? ? clean_path(@uri.path) : set_path(path) end |
#poke ⇒ Object Also known as: ping
45 46 47 48 49 50 51 52 |
# File 'lib/http_mini.rb', line 45 def poke begin success? head rescue Exception => e raise e unless ignore_error? false end end |
#port ⇒ Object
63 64 65 |
# File 'lib/http_mini.rb', line 63 def port @uri.port end |
#post(data) ⇒ Object
29 30 31 |
# File 'lib/http_mini.rb', line 29 def post(data) request { |http| http.post(full_path, data) } end |
#put(data) ⇒ Object
33 34 35 |
# File 'lib/http_mini.rb', line 33 def put(data) request { |http| http.put(full_path, data) } end |
#uri(uri = nil) ⇒ Object
55 56 57 |
# File 'lib/http_mini.rb', line 55 def uri(uri=nil) uri.nil? ? @uri : (self.uri = uri) and self end |