Class: ActiveCouch::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_couch/connection.rb

Overview

Class to handle connections to remote web services. This class is used by ActiveCouch::Base to interface with REST services.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Connection

The site parameter is required and will set the site attribute to the URI for the remote resource service.

Raises:

  • (ArgumentError)


67
68
69
70
# File 'lib/active_couch/connection.rb', line 67

def initialize(site)
  raise ArgumentError, 'Missing site URI' unless site
  init_site_with_path(site)
end

Instance Attribute Details

#siteObject

Returns the value of attribute site.



57
58
59
# File 'lib/active_couch/connection.rb', line 57

def site
  @site
end

Class Method Details

.requestsObject



60
61
62
# File 'lib/active_couch/connection.rb', line 60

def requests
  @@requests ||= []
end

Instance Method Details

#delete(path, headers = {}) ⇒ Object

Execute a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.



85
86
87
# File 'lib/active_couch/connection.rb', line 85

def delete(path, headers = {})
  request(:delete, path, build_request_headers(headers))
end

#get(path, headers = {}) ⇒ Object

Execute a GET request. Used to get (find) resources.



79
80
81
# File 'lib/active_couch/connection.rb', line 79

def get(path, headers = {})
  request(:get, path, build_request_headers(headers)).body
end

#post(path, body = '', headers = {}) ⇒ Object

Execute a POST request. Used to create new resources.



97
98
99
# File 'lib/active_couch/connection.rb', line 97

def post(path, body = '', headers = {})
  request(:post, path, body.to_s, build_request_headers(headers))
end

#put(path, body = '', headers = {}) ⇒ Object

Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.



91
92
93
# File 'lib/active_couch/connection.rb', line 91

def put(path, body = '', headers = {})
  request(:put, path, body.to_s, build_request_headers(headers))
end