Class: RelaxDB::Server
- Inherits:
-
Object
- Object
- RelaxDB::Server
- Defined in:
- lib/relaxdb/server.rb
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(req) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
9 10 11 12 |
# File 'lib/relaxdb/server.rb', line 9 def initialize(host, port) @host = host @port = port end |
Instance Method Details
#delete(uri) ⇒ Object
14 15 16 |
# File 'lib/relaxdb/server.rb', line 14 def delete(uri) request(Net::HTTP::Delete.new(uri)) end |
#get(uri) ⇒ Object
18 19 20 |
# File 'lib/relaxdb/server.rb', line 18 def get(uri) request(Net::HTTP::Get.new(uri)) end |
#post(uri, json) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/relaxdb/server.rb', line 29 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
22 23 24 25 26 27 |
# File 'lib/relaxdb/server.rb', line 22 def put(uri, json) req = Net::HTTP::Put.new(uri) req["content-type"] = "application/json" req.body = json request(req) end |
#request(req) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/relaxdb/server.rb', line 36 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
46 47 48 |
# File 'lib/relaxdb/server.rb', line 46 def to_s "http://#{@host}:#{@port}/" end |