Class: HttpMini

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

Constant Summary collapse

OPEN_TIMEOUT =
2
READ_TIMEOUT =
2
IGNORE_ERROR =
true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#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



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

def self.VERSION
  '0.2.1'
end

Instance Method Details

#deleteObject



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

def delete
  request { |http| http.delete(full_path) }
end

#getObject



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

def get
  request { |http| http.get(full_path) }
end

#headObject



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

def head
  request { |http| http.head(full_path) }
end

#hostObject



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

def host
  @uri.host || @uri.path.split('/').first
end

#optionsObject



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

def options
  request { |http| http.options(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

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

#portObject



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