Class: DeziResponse
- Inherits:
-
Object
- Object
- DeziResponse
- Defined in:
- lib/dezi/response.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
most attributes are assigned dynamically in initialize().
Instance Method Summary collapse
-
#initialize(http_resp) ⇒ DeziResponse
constructor
A new instance of DeziResponse.
- #is_success ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(http_resp) ⇒ DeziResponse
Returns a new instance of DeziResponse.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 |
Instance Attribute Details
#results ⇒ Object
most attributes are assigned dynamically in initialize(). Try:
puts response.inspect
to see them.
33 34 35 |
# File 'lib/dezi/response.rb', line 33 def results @results end |
Instance Method Details
#is_success ⇒ Object
98 99 100 |
# File 'lib/dezi/response.rb', line 98 def is_success() return @is_ok end |
#status ⇒ Object
94 95 96 |
# File 'lib/dezi/response.rb', line 94 def status() return @http_resp.status end |