Class: SMG::HTTP::Request
- Inherits:
-
Object
- Object
- SMG::HTTP::Request
- Defined in:
- lib/smg/http/request.rb
Constant Summary collapse
- DEFAULT_LIMIT =
5
- VERBS =
[Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Put, Net::HTTP::Delete, Net::HTTP::Head]
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(verb, uri, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(verb, uri, options = {}) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/smg/http/request.rb', line 17 def initialize(verb, uri, = {}) raise "unknown verb: #{verb}" unless VERBS.include?(verb) @verb = verb @uri = Addressable::URI.parse(uri) @proxy = [:proxy] ? Addressable::URI.parse([:proxy]) : nil @headers = [:headers] ? [:headers].to_hash : {} @limit = [:no_follow] ? 1 : [:limit] || DEFAULT_LIMIT @body = [:body] @timeout = [:timeout] ? [:timeout].to_i : nil @pem = [:pem] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def headers @headers end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def limit @limit end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def proxy @proxy end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
11 12 13 |
# File 'lib/smg/http/request.rb', line 11 def verb @verb end |
Instance Method Details
#perform ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/smg/http/request.rb', line 30 def perform setup response = http.request(@request) handle_response(response) rescue Timeout::Error => e raise TimeoutError, e. rescue OpenSSL::SSL::SSLError => e raise SSLError, e. end |