Class: CouchObject::Server
- Inherits:
-
Object
- Object
- CouchObject::Server
- Defined in:
- lib/couch_object/server.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#delete(path) ⇒ Object
Send a DELETE request to
path
. -
#get(path) ⇒ Object
Send a GET request to
path
. -
#initialize(uri) ⇒ Server
constructor
Create a new Server object,
uri
is the full URI of the server, eg. -
#post(path, data, content_type = "application/json") ⇒ Object
Send a POST request to
path
with the body payload ofdata
content_type
is the Content-Type header to send along (defaults to application/json). -
#put(path, data, content_type = "application/json") ⇒ Object
Send a PUT request to
path
with the body payload ofdata
content_type
is the Content-Type header to send along (defaults to application/json). -
#request(req) ⇒ Object
send off a
req
object to the host.
Constructor Details
#initialize(uri) ⇒ Server
Create a new Server object, uri
is the full URI of the server, eg. “localhost:5984”
7 8 9 10 11 12 13 |
# File 'lib/couch_object/server.rb', line 7 def initialize(uri) @uri = URI.parse(uri) @host = @uri.host @port = @uri.port @connection = Net::HTTP.new(@host, @port) @connection.set_debug_output($stderr) if $debug end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/couch_object/server.rb', line 14 def connection @connection end |
#host ⇒ Object
Returns the value of attribute host.
14 15 16 |
# File 'lib/couch_object/server.rb', line 14 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
14 15 16 |
# File 'lib/couch_object/server.rb', line 14 def port @port end |
Instance Method Details
#delete(path) ⇒ Object
Send a DELETE request to path
42 43 44 45 |
# File 'lib/couch_object/server.rb', line 42 def delete(path) req = Net::HTTP::Delete.new(path) request(req) end |
#get(path) ⇒ Object
Send a GET request to path
17 18 19 |
# File 'lib/couch_object/server.rb', line 17 def get(path) request(Net::HTTP::Get.new(path)) end |
#post(path, data, content_type = "application/json") ⇒ Object
Send a POST request to path
with the body payload of data
content_type
is the Content-Type header to send along (defaults to application/json)
24 25 26 27 28 29 |
# File 'lib/couch_object/server.rb', line 24 def post(path, data, content_type="application/json") post = Net::HTTP::Post.new(path) post["content-type"] = content_type post.body = data request(post) end |
#put(path, data, content_type = "application/json") ⇒ Object
Send a PUT request to path
with the body payload of data
content_type
is the Content-Type header to send along (defaults to application/json)
34 35 36 37 38 39 |
# File 'lib/couch_object/server.rb', line 34 def put(path, data, content_type="application/json") put = Net::HTTP::Put.new(path) put["content-type"] = content_type put.body = data request(put) end |
#request(req) ⇒ Object
- send off a
req
object to the host. req is a Net::Http -
request class
(eg Net::Http::Get/Net::Http::Post etc)
49 50 51 |
# File 'lib/couch_object/server.rb', line 49 def request(req) connection.request(req) end |