In Files

Parent

YALTools::Main

Description

YALTools::Main class is a wrapper class for the Couch::Server class which is described at the official CouchDB wiki.

It aims to handle errors.

Usage

  @couch = Main.new(Couch::Server.new(host,port))
  json = @couch.get("/example/_design/all/_view/all?reduce=false")

Attributes

debug[RW]

Public Class Methods

new(couch = nil) click to toggle source
    # File yalt/main.rb, line 21
21:     def initialize(couch = nil)
22:       @couch = couch
23:       @debug = false
24:     end

Public Instance Methods

delete(uri) click to toggle source

returns the kind of Net::HTTPResponse instance. When an error occures, it returns nil.

    # File yalt/main.rb, line 73
73:     def delete(uri)
74:       res = nil
75:       begin
76:         res = @couch.delete(URI.escape(uri))
77:       rescue
78:         $stderr.puts $! if @debug
79:       end
80:       return res
81:     end
get(uri) click to toggle source

returns the result of the JSON.parse(Net::HTTPResponse.body)

If the return object contains the “error” key, the {} will be returned.

If it’s failed to parse the (Net::HTTPResponse).body, then return the (Net::HTTPResponse).body.

    # File yalt/main.rb, line 32
32:     def get(uri)
33:       json = {}
34:       begin
35:         res = @couch.get(URI.escape(uri))
36:         json = JSON.parse(res.body)
37:         if json.kind_of?(Hash) and json.has_key?("error")
38:           json = {}
39:         end
40:       rescue
41:         $stderr.puts $! if @debug
42:         json = res.body
43:       end
44:       return json
45:     end
head(uri) click to toggle source
    # File yalt/main.rb, line 83
83:     def head(uri)
84:       res = nil
85:       begin
86:         res = @couch.head(URI.escape(uri))
87:       rescue
88:         $stderr.puts $! if @debug
89:       end
90:       return res
91:     end
post(uri, json) click to toggle source

returns the kind of Net::HTTPResponse instance. When an error occures, it returns nil.

    # File yalt/main.rb, line 61
61:     def post(uri, json)
62:       res = nil
63:       begin
64:         res = @couch.post(URI.escape(uri), json.to_json)
65:       rescue
66:         $stderr.puts $! if @debug
67:       end
68:       return res
69:     end
put(uri, json) click to toggle source

returns the kind of Net::HTTPResponse instance. When an error occures, it returns nil.

    # File yalt/main.rb, line 49
49:     def put(uri, json)
50:       res = nil
51:       begin
52:         res = @couch.put(URI.escape(uri), json.to_json)
53:       rescue
54:         $stderr.puts $! if @debug
55:       end
56:       return res
57:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.