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
- #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 9 |
# File 'lib/relaxdb/net_http_server.rb', line 5 def initialize(host, port) @host = host @port = port @cx = Net::HTTP.start(@host, @port) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/relaxdb/taf2_curb_server.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/relaxdb/taf2_curb_server.rb', line 11 def port @port end |
Instance Method Details
#delete(uri) ⇒ Object
11 12 13 |
# File 'lib/relaxdb/net_http_server.rb', line 11 def delete(uri) request(Net::HTTP::Delete.new(uri)) end |
#get(uri) ⇒ Object
15 16 17 |
# File 'lib/relaxdb/net_http_server.rb', line 15 def get(uri) request(Net::HTTP::Get.new(uri)) end |
#post(uri, json) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/relaxdb/net_http_server.rb', line 26 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
19 20 21 22 23 24 |
# File 'lib/relaxdb/net_http_server.rb', line 19 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/relaxdb/net_http_server.rb', line 33 def request(req) res = Net::HTTP.start(@host, @port) { |http| http.request(req) } # # When using this chunk of code, as opposed to the one above, CouchDB # started throwing emfile errors. I can't imagine they're related, # but worth noting nonetheless. On second thoughts, I think they are! # # The tests don't close the cx after they run - just open new ones, this # could be causing CouchDB to run out of handles. # # begin # # @cx = Net::HTTP.start(@host, @port) unless @cx.active? # res = @cx.request(req) # rescue # @cx = Net::HTTP.start(@host, @port) # res = @cx.request(req) # end if (not res.kind_of?(Net::HTTPSuccess)) handle_error(req, res) end res end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/relaxdb/net_http_server.rb', line 60 def to_s "http://#{@host}:#{@port}/" end |