class DeziResponse

Attributes

results[RW]

most attributes are assigned dynamically in initialize(). Try:

puts response.inspect

to see them.

Public Class Methods

new(http_resp) click to toggle source
# File lib/dezi/response.rb, line 35
def initialize(http_resp)
    @http_resp = http_resp
    
    #warn http_resp.headers.inspect
    #warn "code=" + http_resp.status.to_s
    
    @is_ok = false
    if (http_resp.status.to_s =~ /^2\d\d/)
        @is_ok = true
    end
    
    if (!@is_ok)
        return
    end
    
    #warn "is_ok=#{@is_ok}"
    
    body = http_resp.body
    
    #warn body.inspect
    
    # set body keys as attributes in the object
    body.each {|k,v|
    
        # results are special
        if k == 'results'
            next
        end
    
        # create the attribute
        self.instance_eval { class << self; self end }.send(:attr_accessor, k)
        
        # assign the value
        send("#{k}=",v)
    }
    
    if body['results'].nil?
        @results = []
        return
    end

    #warn 'body[results] is not nil'
    
    # make each result Hash into a DeziDoc object
    @results = body['results'].map {|r|
        rhash = r.to_hash
        res_fields = rhash.keys
        result = { 'fields' => {} }
        res_fields.each {|f|
            result['fields'][f] = rhash.delete(f)
            if (DeziDoc.method_defined? f)
                result[f] = result['fields'][f]
            end
        }
        DeziDoc.new(result)
    }

end

Public Instance Methods

is_success() click to toggle source
# File lib/dezi/response.rb, line 98
def is_success()
    return @is_ok
end
status() click to toggle source
# File lib/dezi/response.rb, line 94
def status()
    return @http_resp.status
end