Sha256: c16de7c32e264f4a2f696c88ff47da0b52f32ab62a5c0416c27e037526210e61

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'rest_client'

module RestClientAdapter
  def self.convert_exception(&blk)
    begin
      yield
    rescue Exception => e 
      ending = e.class.to_s.match(/[a-z0-9_]*\z/i)
      if e.message.match(/409\z/)
        raise Aqua::Store::CouchDB::Conflict, e.message
      else  
        begin
          error = "Aqua::Store::CouchDB::#{ending}".constantize
        rescue
          raise e
        end
        raise error, e.message 
      end     
    end    
  end  
  
  def self.get(uri, headers={})
    convert_exception do 
      RestClient.get(uri, headers)
    end    
  end

  def self.post(uri, hash, headers={})
    convert_exception do
      RestClient.post(uri, hash, headers)
    end  
  end

  def self.put(uri, hash, headers={})
    convert_exception do
      RestClient.put(uri, hash, headers)
    end  
  end

  def self.delete(uri, headers={})
    convert_exception do 
      RestClient.delete(uri, headers)
    end  
  end

  def self.copy(uri, headers)
    convert_exception do 
      RestClient::Request.execute(  :method   => :copy,
                                    :url      => uri,
                                    :headers  => headers) 
    end                                
  end 
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
baccigalupi-aqua-0.1.5 lib/aqua/store/couch_db/http_client/adapter/rest_client.rb
aqua-0.2.0 lib/aqua/store/couch_db/http_client/adapter/rest_client.rb
aqua-0.1.6 lib/aqua/store/couch_db/http_client/adapter/rest_client.rb