Class: RAWS::HTTP::Typhoeus::Request
- Defined in:
- lib/raws/http/typhoeus.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#method ⇒ Object
Returns the value of attribute method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #before_send(&block) ⇒ Object
-
#initialize(uri) ⇒ Request
constructor
A new instance of Request.
- #send(body = nil, &block) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Request
Returns a new instance of Request.
21 22 23 |
# File 'lib/raws/http/typhoeus.rb', line 21 def initialize(uri) @uri, @header, @method, @before_send = uri, {}, :get , nil end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
18 19 20 |
# File 'lib/raws/http/typhoeus.rb', line 18 def header @header end |
#method ⇒ Object
Returns the value of attribute method.
19 20 21 |
# File 'lib/raws/http/typhoeus.rb', line 19 def method @method end |
#uri ⇒ Object
Returns the value of attribute uri.
19 20 21 |
# File 'lib/raws/http/typhoeus.rb', line 19 def uri @uri end |
Instance Method Details
#before_send(&block) ⇒ Object
25 26 27 |
# File 'lib/raws/http/typhoeus.rb', line 25 def before_send(&block) @before_send = block end |
#send(body = nil, &block) ⇒ Object
29 30 31 32 33 34 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 |
# File 'lib/raws/http/typhoeus.rb', line 29 def send(body=nil, &block) RAWS.logger.debug self @before_send && @before_send.call(self) response = Response.new( ::Typhoeus::Request.__send__( @method.to_s.downcase.to_sym, @uri, :headers => @header, :body => if block_given? # TODO エラーにした方が。。。 io = StringIO.new block.call(io) if io.size > 0 io.rewind io.read end else body end ) ) case response.code when 200...300 response when 300...400 response.parse raise RAWS::HTTP::Redirect.new(response) else response.parse raise RAWS::HTTP::Error.new(response) end end |