Class: HTTPI::Request
- Inherits:
-
Object
- Object
- HTTPI::Request
- Defined in:
- lib/httpi/request.rb
Overview
HTTPI::Request
Represents an HTTP request and contains various methods for customizing that request.
Constant Summary collapse
- ATTRIBUTES =
Available attribute writers.
[:url, :proxy, :headers, :body, :open_timeout, :read_timeout]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns a Hash of HTTP headers.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#proxy ⇒ Object
Returns the
proxy
to use. -
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#ssl ⇒ Object
writeonly
Sets whether to use SSL.
-
#url ⇒ Object
Returns the
url
to access.
Instance Method Summary collapse
-
#auth ⇒ Object
Returns the
HTTPI::Authentication
object. -
#auth? ⇒ Boolean
Returns whether any authentication credentials were specified.
-
#gzip ⇒ Object
Adds a header information to accept gzipped content.
-
#initialize(args = {}) ⇒ Request
constructor
Accepts a Hash of
args
to mass assign attributes and authentication credentials. -
#mass_assign(args) ⇒ Object
Expects a Hash of
args
to assign. -
#ssl? ⇒ Boolean
Returns whether to use SSL.
Constructor Details
#initialize(args = {}) ⇒ Request
Accepts a Hash of args
to mass assign attributes and authentication credentials.
15 16 17 18 19 20 21 |
# File 'lib/httpi/request.rb', line 15 def initialize(args = {}) if args.kind_of? String self.url = args elsif args.kind_of?(Hash) && !args.empty? mass_assign args end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
61 62 63 |
# File 'lib/httpi/request.rb', line 61 def body @body end |
#headers ⇒ Object
Returns a Hash of HTTP headers. Defaults to return an empty Hash.
49 50 51 |
# File 'lib/httpi/request.rb', line 49 def headers @headers ||= {} end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
61 62 63 |
# File 'lib/httpi/request.rb', line 61 def open_timeout @open_timeout end |
#proxy ⇒ Object
Returns the proxy
to use.
37 38 39 |
# File 'lib/httpi/request.rb', line 37 def proxy @proxy end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
61 62 63 |
# File 'lib/httpi/request.rb', line 61 def read_timeout @read_timeout end |
#ssl=(value) ⇒ Object (writeonly)
Sets whether to use SSL.
46 47 48 |
# File 'lib/httpi/request.rb', line 46 def ssl=(value) @ssl = value end |
#url ⇒ Object
Returns the url
to access.
29 30 31 |
# File 'lib/httpi/request.rb', line 29 def url @url end |
Instance Method Details
#auth ⇒ Object
Returns the HTTPI::Authentication
object.
64 65 66 |
# File 'lib/httpi/request.rb', line 64 def auth @auth ||= Auth::Config.new end |
#auth? ⇒ Boolean
Returns whether any authentication credentials were specified.
69 70 71 |
# File 'lib/httpi/request.rb', line 69 def auth? !!auth.type end |
#gzip ⇒ Object
Adds a header information to accept gzipped content.
57 58 59 |
# File 'lib/httpi/request.rb', line 57 def gzip headers["Accept-Encoding"] = "gzip,deflate" end |
#mass_assign(args) ⇒ Object
Expects a Hash of args
to assign.
74 75 76 |
# File 'lib/httpi/request.rb', line 74 def mass_assign(args) ATTRIBUTES.each { |key| send("#{key}=", args[key]) if args[key] } end |
#ssl? ⇒ Boolean
Returns whether to use SSL.
40 41 42 43 |
# File 'lib/httpi/request.rb', line 40 def ssl? return @ssl unless @ssl.nil? !!(url.to_s =~ /^https/) end |