Module: Restfolia::HTTP::Configuration
- Included in:
- EntryPoint
- Defined in:
- lib/restfolia/http/configuration.rb
Overview
Internal: Simply a bag of HTTP options like headers, cookies, auth … etc.
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Public: Sets/Returns cookies values as String.
Instance Method Summary collapse
-
#as(content_type) ⇒ Object
Public: A fluent way to add Content-Type and Accept headers.
-
#headers ⇒ Object
Public: Returns Hash to be used as Headers on request.
-
#set_cookies(cookies) ⇒ Object
Public: A fluent way to add Cookies to Request.
-
#with_headers(new_headers) ⇒ Object
Public: A fluent way to add HTTP headers.
Instance Attribute Details
#cookies ⇒ Object
Public: Sets/Returns cookies values as String.
7 8 9 |
# File 'lib/restfolia/http/configuration.rb', line 7 def @cookies end |
Instance Method Details
#as(content_type) ⇒ Object
Public: A fluent way to add Content-Type and Accept headers.
content_type - String value. Ex: “application/json”
Returns self, always!
58 59 60 61 62 |
# File 'lib/restfolia/http/configuration.rb', line 58 def as(content_type) headers["Content-Type"] = content_type headers["Accept"] = content_type self end |
#headers ⇒ Object
Public: Returns Hash to be used as Headers on request.
10 11 12 |
# File 'lib/restfolia/http/configuration.rb', line 10 def headers @headers ||= {} end |
#set_cookies(cookies) ⇒ Object
Public: A fluent way to add Cookies to Request.
cookies - String in cookie format.
Examples
# setting cookie from Google Translate
= "PREF=ID=07eb...; expires=Sat, 26-Apr-2014 19:19:36 GMT; path=/; domain=.google.com, NID=59...; expires=Fri, 26-Oct-2012 19:19:36 GMT; path=/; domain=.google.com; HttpOnly"
resource = Restfolia.at("http://fake.com").
().get
Returns self, always!
26 27 28 29 |
# File 'lib/restfolia/http/configuration.rb', line 26 def () self. = self end |
#with_headers(new_headers) ⇒ Object
Public: A fluent way to add HTTP headers. Headers informed here are merged with headers attribute.
new_headers - Hash with headers.
Examples
entry_point = Restfolia.at("http://fake.com")
entry_point.with_headers("X-Custom1" => "value",
"X-Custom2" => "value2").get
Returns self, always! Raises ArgumentError unless new_headers is a Hash.
44 45 46 47 48 49 50 51 |
# File 'lib/restfolia/http/configuration.rb', line 44 def with_headers(new_headers) unless new_headers.is_a?(Hash) raise ArgumentError, "New Headers should Hash object." end headers.merge!(new_headers) self end |