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.



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

#optsObject

Returns the value of attribute opts.



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

def opts
  @opts
end

Class Method Details

.VERSIONObject



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

def self.VERSION
  '0.3.0'
end

Instance Method Details

#deleteObject



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

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

#getObject



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

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

#headObject



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

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

#hostObject



57
58
59
# File 'lib/http_mini.rb', line 57

def host
  @uri.host
end

#optionsObject



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

def options
  request Net::HTTP::Options.new(full_path, headers)
end

#path(path = nil) ⇒ Object



65
66
67
# File 'lib/http_mini.rb', line 65

def path(path=nil)
  path.nil? ? @uri.request_uri : set_path(path)
end

#pokeObject Also known as: ping



43
44
45
46
47
48
49
50
# File 'lib/http_mini.rb', line 43

def poke
  begin
    success? head
  rescue Exception => e
    raise e unless ignore_error?
    false
  end
end

#portObject



61
62
63
# File 'lib/http_mini.rb', line 61

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



53
54
55
# File 'lib/http_mini.rb', line 53

def uri(uri=nil)
  uri.nil? ? @uri : ((self.uri = uri) and self)
end