Class: Twitter::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, url, options = {}) ⇒ Headers

Returns a new instance of Headers.



7
8
9
10
11
12
13
# File 'lib/twitter/headers.rb', line 7

def initialize(client, request_method, url, options = {})
  @client = client
  @request_method = request_method.to_sym
  @uri = Addressable::URI.parse(url)
  @options = options
  @signature_options = @request_method == :post && @options.values.any? { |value| value.respond_to?(:to_io) } ? {} : @options
end

Instance Method Details

#oauth_auth_headerObject



15
16
17
# File 'lib/twitter/headers.rb', line 15

def oauth_auth_header
  SimpleOAuth::Header.new(@request_method, @uri, @signature_options, @client.credentials)
end

#request_headersObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twitter/headers.rb', line 19

def request_headers
  bearer_token_request = @options.delete(:bearer_token_request)
  headers = {}
  if bearer_token_request
    headers[:accept]        = '*/*'
    headers[:authorization] = bearer_token_credentials_auth_header
    headers[:content_type]  = 'application/x-www-form-urlencoded; charset=UTF-8'
  else
    headers[:authorization] = auth_header
  end
  headers
end