Module: RestAPI
- Included in:
- CouchRest
- Defined in:
- lib/couchrest/core/rest_api.rb
Instance Method Summary collapse
- #copy(uri, destination) ⇒ Object
- #delete(uri) ⇒ Object
- #get(uri) ⇒ Object
- #post(uri, doc = nil) ⇒ Object
- #put(uri, doc = nil) ⇒ Object
Instance Method Details
#copy(uri, destination) ⇒ Object
45 46 47 |
# File 'lib/couchrest/core/rest_api.rb', line 45 def copy(uri, destination) JSON.parse(HttpAbstraction.copy(uri, {'Destination' => destination})) end |
#delete(uri) ⇒ Object
41 42 43 |
# File 'lib/couchrest/core/rest_api.rb', line 41 def delete(uri) JSON.parse(HttpAbstraction.delete(uri)) end |
#get(uri) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/couchrest/core/rest_api.rb', line 16 def get(uri) begin JSON.parse(HttpAbstraction.get(uri), :max_nesting => false) rescue => e if $DEBUG raise "Error while sending a GET request #{uri}\n: #{e}" else raise e end end end |
#post(uri, doc = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/couchrest/core/rest_api.rb', line 28 def post(uri, doc = nil) payload = doc.to_json if doc begin JSON.parse(HttpAbstraction.post(uri, payload)) rescue Exception => e if $DEBUG raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}" else raise e end end end |
#put(uri, doc = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/couchrest/core/rest_api.rb', line 3 def put(uri, doc = nil) payload = doc.to_json if doc begin JSON.parse(HttpAbstraction.put(uri, payload)) rescue Exception => e if $DEBUG raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}" else raise e end end end |