Module: Resto::Request::Header
- Included in:
- Base
- Defined in:
- lib/resto/request/header.rb
Instance Method Summary collapse
- #accept(accept) ⇒ Object
- #basic_auth(options) ⇒ Object
- #composed_headers ⇒ Object
- #content_type(content_type) ⇒ Object
- #format(symbol, options = nil) ⇒ Object
- #formatter(formatter, options = nil) ⇒ Object
- #headers(headers) ⇒ Object
Instance Method Details
#accept(accept) ⇒ Object
29 30 31 |
# File 'lib/resto/request/header.rb', line 29 def accept(accept) tap { composed_headers.store('accept', accept) } end |
#basic_auth(options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/resto/request/header.rb', line 37 def basic_auth() = AssertHash.keys(, :username, :password) username = .fetch(:username) password = .fetch(:password) base64_encode = ["#{username}:#{password}"].pack('m').delete("\r\n") basic_encode = 'Basic ' + base64_encode tap { composed_headers.store('authorization', basic_encode) } end |
#composed_headers ⇒ Object
21 22 23 |
# File 'lib/resto/request/header.rb', line 21 def composed_headers @headers ||= { 'accept'=> '*/*' , 'user-agent'=> 'Ruby' } end |
#content_type(content_type) ⇒ Object
33 34 35 |
# File 'lib/resto/request/header.rb', line 33 def content_type(content_type) tap { composed_headers.store('content-type', content_type) } end |
#format(symbol, options = nil) ⇒ Object
9 10 11 |
# File 'lib/resto/request/header.rb', line 9 def format(symbol, =nil) formatter(Resto::Format.get(@symbol = symbol), ) end |
#formatter(formatter, options = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/resto/request/header.rb', line 13 def formatter(formatter, =nil) = AssertHash.keys(, :extension) @add_extension = .fetch(:extension) { false } @formatter = formatter accept(formatter.accept) content_type(formatter.content_type) end |
#headers(headers) ⇒ Object
25 26 27 |
# File 'lib/resto/request/header.rb', line 25 def headers(headers) tap { composed_headers.merge!(headers) } end |