Sha256: 85eef2dfabb036b04f523a7bb6c13fc333d56c2bfc673d82dc259c774276c211

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

module CouchRest

  #
  # CouchRest RestAPI
  #
  # Backwards compatible wrapper for instantiating a connection and performing
  # a request on demand. Useful for quick requests, but not recommended for general
  # usage due the extra overhead of establishing a connection.
  #

  module RestAPI

    # Send a GET request.
    def get(url, options = {})
      connection(url, options) do |uri, conn|
        conn.get(uri.request_uri, options)
      end
    end

    # Send a PUT request.
    def put(url, doc = nil, options = {})
      connection(url, options) do |uri, conn|
        conn.put(uri.request_uri, doc, options)
      end
    end

    # Send a POST request.
    def post(url, doc = nil, options = {})
      connection(url, options) do |uri, conn|
        conn.post(uri.request_uri, doc, options)
      end
    end

    # Send a DELETE request.
    def delete(url, options = {})
      connection(url, options) do |uri, conn|
        conn.delete(uri.request_uri, options)
      end
    end

    # Send a COPY request to the URI provided.
    def copy(url, destination, options = {})
      connection(url, options) do |uri, conn|
        conn.copy(uri.request_uri, destination, options)
      end
    end

    # Send a HEAD request.
    def head(url, options = {})
      connection(url, options) do |uri, conn|
        conn.head(uri.request_uri, options)
      end
    end

    protected

    def connection(url, options)
      uri = URI url
      conn = CouchRest::Connection.new(uri, options)
      res = yield uri, conn
      res
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
couchrest-2.0.1 lib/couchrest/rest_api.rb
couchrest-2.0.0 lib/couchrest/rest_api.rb
couchrest-2.0.0.rc3 lib/couchrest/rest_api.rb
couchrest-2.0.0.rc2 lib/couchrest/rest_api.rb
couchrest-2.0.0.rc1 lib/couchrest/rest_api.rb
couchrest-2.0.0.beta2 lib/couchrest/rest_api.rb
couchrest-2.0.0.beta1 lib/couchrest/rest_api.rb