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.
14 15 16 17 |
# File 'lib/http_mini.rb', line 14 def initialize(uri, opts = {}) self.uri = uri 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
10 11 12 |
# File 'lib/http_mini.rb', line 10 def self.VERSION '0.3.2' end |
Instance Method Details
#delete ⇒ Object
35 36 37 |
# File 'lib/http_mini.rb', line 35 def delete request Net::HTTP::Delete.new(full_path, headers) end |
#get ⇒ Object
23 24 25 |
# File 'lib/http_mini.rb', line 23 def get request Net::HTTP::Get.new(full_path, headers) end |
#head ⇒ Object
19 20 21 |
# File 'lib/http_mini.rb', line 19 def head request Net::HTTP::Head.new(full_path, headers) end |
#host ⇒ Object
58 59 60 |
# File 'lib/http_mini.rb', line 58 def host @uri.host end |
#options ⇒ Object
39 40 41 |
# File 'lib/http_mini.rb', line 39 def request Net::HTTP::Options.new(full_path, headers) end |
#path(path = nil) ⇒ Object
66 67 68 |
# File 'lib/http_mini.rb', line 66 def path(path=nil) path.nil? ? @uri.request_uri : set_path(path) end |
#poke ⇒ Object Also known as: ping
43 44 45 46 47 48 49 50 51 |
# File 'lib/http_mini.rb', line 43 def poke begin opts[:unsafe] = opts[:unsafe] != false success? head rescue Exception => e raise e unless ignore_error? false end end |
#port ⇒ Object
62 63 64 |
# File 'lib/http_mini.rb', line 62 def port @uri.port end |
#post(data) ⇒ Object
27 28 29 |
# File 'lib/http_mini.rb', line 27 def post(data) request Net::HTTP::Post.new(full_path, headers), data end |
#put(data) ⇒ Object
31 32 33 |
# File 'lib/http_mini.rb', line 31 def put(data) request Net::HTTP::Put.new(full_path, headers), data end |
#uri(uri = nil) ⇒ Object
54 55 56 |
# File 'lib/http_mini.rb', line 54 def uri(uri=nil) uri.nil? ? @uri : ((self.uri = uri) and self) end |