Module: RestAPI

Defined in:
lib/aqua/store/couch_db/http_client/rest_api.rb

Overview

HTTP Adapters should implement the following to be used with the RestAPI module

def self.get(uri, headers=nil) end

def self.post(uri, hash, headers=nil) end

def self.put(uri, hash, headers=nil) end

def self.delete(uri, headers=nil) end

def self.copy(uri, headers) end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapterObject



23
24
25
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 23

def self.adapter
  @adapter
end

.adapter=(klass) ⇒ Object



19
20
21
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 19

def self.adapter=( klass )
  @adapter = klass
end

Instance Method Details

#copy(uri, destination) ⇒ Object



57
58
59
60
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 57

def copy(uri, destination)
  response = RestAPI.adapter.copy(uri, {'Destination' => destination}) 
  JSON.parse( response )
end

#delete(uri) ⇒ Object



52
53
54
55
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 52

def delete(uri) 
  response = RestAPI.adapter.delete(uri)
  JSON.parse( response )
end

#get(uri, streamable = false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 33

def get(uri, streamable=false) 
  response = RestAPI.adapter.get(uri)
  begin
    JSON.parse( response , :max_nesting => false)
  rescue Exception => e 
    if streamable
      response
    else
      raise e
    end    
  end    
end

#post(uri, doc = nil) ⇒ Object



46
47
48
49
50
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 46

def post(uri, doc = nil)
  hash = doc.to_json if doc 
  response = RestAPI.adapter.post(uri, hash)
  JSON.parse( response )
end

#put(uri, doc = nil) ⇒ Object



27
28
29
30
31
# File 'lib/aqua/store/couch_db/http_client/rest_api.rb', line 27

def put(uri, doc = nil)
  hash = doc.to_json if doc 
  response = RestAPI.adapter.put( uri, hash ) 
  JSON.parse( response )
end