Class: HttpMini

Inherits:
Object
  • Object
show all
Defined in:
lib/http_mini.rb

Constant Summary collapse

IGNORE_ERROR =
true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#optsObject

Returns the value of attribute opts.



7
8
9
# File 'lib/http_mini.rb', line 7

def opts
  @opts
end

Class Method Details

.VERSIONObject



11
12
13
# File 'lib/http_mini.rb', line 11

def self.VERSION
  '0.3.3'
end

Instance Method Details

#deleteObject



36
37
38
# File 'lib/http_mini.rb', line 36

def delete
  request Net::HTTP::Delete.new(full_path, headers)
end

#getObject



24
25
26
# File 'lib/http_mini.rb', line 24

def get
  request Net::HTTP::Get.new(full_path, headers)
end

#headObject



20
21
22
# File 'lib/http_mini.rb', line 20

def head
  request Net::HTTP::Head.new(full_path, headers)
end

#hostObject



59
60
61
# File 'lib/http_mini.rb', line 59

def host
  @uri.host
end

#optionsObject



40
41
42
# File 'lib/http_mini.rb', line 40

def options
  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

#pokeObject 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

#portObject



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