Class: Rel::Client

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

Overview

Basic HTTP client that sends and receives CSV.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



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

def http
  @http
end

Instance Method Details

#get(fn) ⇒ Object



16
17
18
# File 'lib/rel.rb', line 16

def get(fn)
  reply(http.get("/#{fn}"))
end

#post(fn, csv) ⇒ Object



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

def post(fn, csv)
  reply(http.post("/#{fn}", csv))
end

#reply(res) ⇒ Object



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

def reply(res)
  unless res.code == "200"
    raise RuntimeError, res.inspect
  end

  res.body
end