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 Method Summary collapse
- #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.
5 6 7 8 |
# File 'lib/relaxdb/net_http_server.rb', line 5 def initialize(host, port) @host = host @port = port end |
Instance Method Details
#delete(uri) ⇒ Object
10 11 12 |
# File 'lib/relaxdb/net_http_server.rb', line 10 def delete(uri) request(Net::HTTP::Delete.new(uri)) end |
#get(uri) ⇒ Object
14 15 16 |
# File 'lib/relaxdb/net_http_server.rb', line 14 def get(uri) request(Net::HTTP::Get.new(uri)) end |
#post(uri, json) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/relaxdb/net_http_server.rb', line 25 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
18 19 20 21 22 23 |
# File 'lib/relaxdb/net_http_server.rb', line 18 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
32 33 34 35 36 37 38 39 40 |
# File 'lib/relaxdb/net_http_server.rb', line 32 def request(req) res = Net::HTTP.start(@host, @port) {|http| http.request(req) } if (not res.kind_of?(Net::HTTPSuccess)) handle_error(req, res) end res end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/relaxdb/net_http_server.rb', line 42 def to_s "http://#{@host}:#{@port}/" end |