Class: RAWS::HTTP::Typhoeus::Response

Inherits:
Response
  • Object
show all
Defined in:
lib/raws/http/typhoeus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



66
67
68
69
70
71
72
73
74
# File 'lib/raws/http/typhoeus.rb', line 66

def initialize(response)
  @response, @body, @doc = response, nil, nil
  @header = @response.headers.split("\r\n").inject({}) do |ret, val|
    if md = /(.+?):\s*(.*)/.match(val)
      ret[md[1].downcase] = md[2]
    end
    ret
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



64
65
66
# File 'lib/raws/http/typhoeus.rb', line 64

def body
  @body
end

#docObject (readonly)

Returns the value of attribute doc.



64
65
66
# File 'lib/raws/http/typhoeus.rb', line 64

def doc
  @doc
end

Instance Method Details

#codeObject



76
77
78
# File 'lib/raws/http/typhoeus.rb', line 76

def code
  @response.code
end

#parse(params = {}) ⇒ Object



88
89
90
# File 'lib/raws/http/typhoeus.rb', line 88

def parse(params={})
  @doc = RAWS.xml.parse(receive, params)
end

#receive(&block) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/raws/http/typhoeus.rb', line 80

def receive(&block)
  if block_given?
    block.call(StringIO.new(@response.body)) # TODO エラーにした方が。。。
  else
    @body = @response.body
  end
end