Class: RelaxDB::Server
- Inherits:
-
Object
- Object
- RelaxDB::Server
- Defined in:
- lib/relaxdb/net_http_server.rb,
lib/relaxdb/taf2_curb_server.rb
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #close_connection ⇒ Object
- #cx ⇒ Object
- #delete(uri) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize(host, port) ⇒ Server
constructor
A new instance of Server.
- #post(uri, json) ⇒ Object
- #put(uri, json) ⇒ Object
- #request(uri, method) {|c| ... } ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
7 8 9 10 |
# File 'lib/relaxdb/net_http_server.rb', line 7 def initialize(host, port) @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/relaxdb/net_http_server.rb', line 5 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/relaxdb/net_http_server.rb', line 5 def port @port end |
Instance Method Details
#close_connection ⇒ Object
19 20 21 |
# File 'lib/relaxdb/net_http_server.rb', line 19 def close_connection @cx.finish if @cx end |
#cx ⇒ Object
12 13 14 15 16 17 |
# File 'lib/relaxdb/net_http_server.rb', line 12 def cx unless @cx && @cx.active? @cx = Net::HTTP.start(@host, @port) end @cx end |
#delete(uri) ⇒ Object
23 24 25 |
# File 'lib/relaxdb/net_http_server.rb', line 23 def delete(uri) request(Net::HTTP::Delete.new(uri)) end |
#get(uri) ⇒ Object
27 28 29 |
# File 'lib/relaxdb/net_http_server.rb', line 27 def get(uri) request(Net::HTTP::Get.new(uri)) end |
#post(uri, json) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/relaxdb/net_http_server.rb', line 38 def post(uri, json) req = Net::HTTP::Post.new(uri) req["content-type"] = "application/json" req.body = json request(req) end |
#put(uri, json) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/relaxdb/net_http_server.rb', line 31 def put(uri, json) req = Net::HTTP::Put.new(uri) req["content-type"] = "application/json" req.body = json request(req) end |
#request(uri, method) {|c| ... } ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/relaxdb/net_http_server.rb', line 45 def request(req) begin res = cx.request(req) rescue @cx = nil res = cx.request(req) end if (not res.kind_of?(Net::HTTPSuccess)) handle_error(req, res) end res end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/relaxdb/net_http_server.rb', line 59 def to_s "http://#{@host}:#{@port}/" end |