Module: RockingChair::CouchRestHttpAdapter
- Defined in:
- lib/rocking_chair/couch_rest_http_adapter.rb
Constant Summary collapse
- URL_PARAMETER =
/[a-zA-Z0-9\-\_\%]+/
Class Method Summary collapse
- .copy(uri, headers) ⇒ Object
- .delete(uri, headers = {}) ⇒ Object
- .get(uri, headers = {}) ⇒ Object
- .post(uri, payload, headers = {}) ⇒ Object
- .put(uri, payload = nil, headers = {}) ⇒ Object
Class Method Details
.copy(uri, headers) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/rocking_chair/couch_rest_http_adapter.rb', line 73 def self.copy(uri, headers) puts "COPY: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug url, parameters = RockingChair::Server.normalize_url(uri) if url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/) RockingChair::Server.copy($1, $2, headers.merge(parameters)) else raise "COPY: Unknown url: #{uri.inspect}: #{headers.inspect}" end end |
.delete(uri, headers = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rocking_chair/couch_rest_http_adapter.rb', line 59 def self.delete(uri, headers={}) puts "DELETE: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug url, parameters = RockingChair::Server.normalize_url(uri) if url.match(/\A(#{URL_PARAMETER})\Z/) RockingChair::Server.delete_db(url) elsif url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/) RockingChair::Server.delete($1, $2, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/_design\/(#{URL_PARAMETER})\Z/) RockingChair::Server.delete($1, "_design/#{$2}", parameters) else raise "DELETE: Unknown url: #{uri.inspect}: #{headers.inspect}" end end |
.get(uri, headers = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rocking_chair/couch_rest_http_adapter.rb', line 9 def self.get(uri, headers={}) puts "GET: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug url, parameters = RockingChair::Server.normalize_url(uri) if url == '' RockingChair::Server.info elsif url == '_all_dbs' RockingChair::Server.all_dbs(parameters) elsif url == '_uuids' RockingChair::Server.uuids(parameters) elsif url.match(/\A(#{URL_PARAMETER})\Z/) RockingChair::Server.database($1, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/_all_docs\Z/) RockingChair::Server.load_all($1, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/) RockingChair::Server.load($1, $2, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/_design\/(#{URL_PARAMETER})\Z/) RockingChair::Server.load($1, "_design/#{$2}", parameters) elsif url.match(/\A(#{URL_PARAMETER})\/_design\/(#{URL_PARAMETER})\/_view\/(#{URL_PARAMETER})\Z/) RockingChair::Server.view($1, $2, $3, parameters) else raise "GET: Unknown url: #{url.inspect} headers: #{headers.inspect}" end end |
.post(uri, payload, headers = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rocking_chair/couch_rest_http_adapter.rb', line 33 def self.post(uri, payload, headers={}) puts "POST: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" if @_rocking_chair_debug url, parameters = RockingChair::Server.normalize_url(uri) if url.match(/\A(#{URL_PARAMETER})\/?\Z/) RockingChair::Server.store($1, nil, payload, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/) && $2 == '_bulk_docs' RockingChair::Server.bulk($1, payload) else raise "POST: Unknown url: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" end end |
.put(uri, payload = nil, headers = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rocking_chair/couch_rest_http_adapter.rb', line 45 def self.put(uri, payload=nil, headers={}) puts "PUT: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" if @_rocking_chair_debug url, parameters = RockingChair::Server.normalize_url(uri) if url.match(/\A(#{URL_PARAMETER})\Z/) RockingChair::Server.create_db(url) elsif url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/) RockingChair::Server.store($1, $2, payload, parameters) elsif url.match(/\A(#{URL_PARAMETER})\/_design\/(#{URL_PARAMETER})\Z/) RockingChair::Server.store($1, "_design/#{$2}", payload, parameters) else raise "PUT: Unknown url: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" end end |