Class: HttpMini
- Inherits:
-
Object
- Object
- HttpMini
- Defined in:
- lib/http_mini.rb
Constant Summary collapse
- 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(uri, 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(uri, opts = {}) ⇒ HttpMini
Returns a new instance of HttpMini.
15 16 17 18 |
# File 'lib/http_mini.rb', line 15 def initialize(uri, opts = {}) self.uri = uri self.opts = opts end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
7 8 9 |
# File 'lib/http_mini.rb', line 7 def opts @opts end |
Class Method Details
.VERSION ⇒ Object
11 12 13 |
# File 'lib/http_mini.rb', line 11 def self.VERSION '0.3.3' end |
Instance Method Details
#delete ⇒ Object
36 37 38 |
# File 'lib/http_mini.rb', line 36 def delete request Net::HTTP::Delete.new(full_path, headers) end |
#get ⇒ Object
24 25 26 |
# File 'lib/http_mini.rb', line 24 def get request Net::HTTP::Get.new(full_path, headers) end |
#head ⇒ Object
20 21 22 |
# File 'lib/http_mini.rb', line 20 def head request Net::HTTP::Head.new(full_path, headers) end |
#host ⇒ Object
59 60 61 |
# File 'lib/http_mini.rb', line 59 def host @uri.host end |
#options ⇒ Object
40 41 42 |
# File 'lib/http_mini.rb', line 40 def request Net::HTTP::Options.new(full_path, headers) end |
#path(path = nil) ⇒ Object
67 68 69 |
# File 'lib/http_mini.rb', line 67 def path(path=nil) path.nil? ? @uri.request_uri : set_path(path) end |
#poke ⇒ Object Also known as: ping
44 45 46 47 48 49 50 51 52 |
# File 'lib/http_mini.rb', line 44 def poke begin opts[:unsafe] = opts[:unsafe] != false 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
28 29 30 |
# File 'lib/http_mini.rb', line 28 def post(data) request Net::HTTP::Post.new(full_path, headers), data end |
#put(data) ⇒ Object
32 33 34 |
# File 'lib/http_mini.rb', line 32 def put(data) request Net::HTTP::Put.new(full_path, headers), 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 |