Module: RestClientAdapter

Defined in:
lib/aqua/store/couch_db/http_client/adapter/rest_client.rb

Class Method Summary collapse

Class Method Details

.convert_exception(&blk) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 4

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

.copy(uri, headers) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 46

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

.delete(uri, headers = {}) ⇒ Object



40
41
42
43
44
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 40

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

.get(uri, headers = {}) ⇒ Object



22
23
24
25
26
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 22

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

.post(uri, hash, headers = {}) ⇒ Object



28
29
30
31
32
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 28

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

.put(uri, hash, headers = {}) ⇒ Object



34
35
36
37
38
# File 'lib/aqua/store/couch_db/http_client/adapter/rest_client.rb', line 34

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