Class: Varnish::Client

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

Defined Under Namespace

Classes: Ban, Purge

Instance Method Summary collapse

Constructor Details

#initialize(host, port, target) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/varnish/client.rb', line 5

def initialize(host, port, target)
  @http   = Net::HTTP.new(host, port)
  @target = URI.parse(target.to_s)
end

Instance Method Details

#ban(cmd) ⇒ Object



17
18
19
20
21
22
# File 'lib/varnish/client.rb', line 17

def ban(cmd)
  req = Ban.new(cmd)
  req['Host'] = @target.host
  res = @http.request(req)
  res.code == '200'
end

#fetch(path, headers = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/varnish/client.rb', line 24

def fetch(path, headers = {})
  req = Net::HTTP::Get.new(path, headers)
  req['Host'] = @target.host
  res = @http.request(req)
  return nil unless res.code == '200'
  res.body
end

#purge(cmd) ⇒ Object



10
11
12
13
14
15
# File 'lib/varnish/client.rb', line 10

def purge(cmd)
  req = Purge.new(cmd)
  req['Host'] = @target.host
  res = @http.request(req)
  res.code == '200'
end