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.
-
#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.
-
#headers ⇒ Object
Returns a Hash of HTTP headers.
-
#headers=(headers) ⇒ Object
Sets the Hash of HTTP headers.
-
#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.
16 17 18 19 20 21 22 |
# File 'lib/httpi/request.rb', line 16 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.
64 65 66 |
# File 'lib/httpi/request.rb', line 64 def body @body end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
64 65 66 |
# File 'lib/httpi/request.rb', line 64 def open_timeout @open_timeout end |
#proxy ⇒ Object
Returns the proxy
to use.
38 39 40 |
# File 'lib/httpi/request.rb', line 38 def proxy @proxy end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
64 65 66 |
# File 'lib/httpi/request.rb', line 64 def read_timeout @read_timeout end |
#ssl=(value) ⇒ Object (writeonly)
Sets whether to use SSL.
47 48 49 |
# File 'lib/httpi/request.rb', line 47 def ssl=(value) @ssl = value end |
#url ⇒ Object
Returns the url
to access.
30 31 32 |
# File 'lib/httpi/request.rb', line 30 def url @url end |
Instance Method Details
#auth ⇒ Object
Returns the HTTPI::Authentication
object.
67 68 69 |
# File 'lib/httpi/request.rb', line 67 def auth @auth ||= Auth::Config.new end |
#auth? ⇒ Boolean
Returns whether any authentication credentials were specified.
72 73 74 |
# File 'lib/httpi/request.rb', line 72 def auth? !!auth.type end |
#gzip ⇒ Object
Adds a header information to accept gzipped content.
60 61 62 |
# File 'lib/httpi/request.rb', line 60 def gzip headers["Accept-Encoding"] = "gzip,deflate" end |
#headers ⇒ Object
Returns a Hash of HTTP headers. Defaults to return an empty Hash.
50 51 52 |
# File 'lib/httpi/request.rb', line 50 def headers @headers ||= Rack::Utils::HeaderHash.new end |
#headers=(headers) ⇒ Object
Sets the Hash of HTTP headers.
55 56 57 |
# File 'lib/httpi/request.rb', line 55 def headers=(headers) @headers = Rack::Utils::HeaderHash.new(headers) end |
#mass_assign(args) ⇒ Object
Expects a Hash of args
to assign.
77 78 79 |
# File 'lib/httpi/request.rb', line 77 def mass_assign(args) ATTRIBUTES.each { |key| send("#{key}=", args[key]) if args[key] } end |
#ssl? ⇒ Boolean
Returns whether to use SSL.
41 42 43 44 |
# File 'lib/httpi/request.rb', line 41 def ssl? return @ssl unless @ssl.nil? !!(url.to_s =~ /^https/) end |