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)
  @bearer_token_request = options.delete(:bearer_token_request)
  @options = options
end

Instance Method Details

#bearer_token_request?Boolean

Returns:

  • (Boolean)


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

def bearer_token_request?
  !!@bearer_token_request
end

#oauth_auth_headerObject



19
20
21
# File 'lib/twitter/headers.rb', line 19

def oauth_auth_header
  SimpleOAuth::Header.new(@request_method, @uri, @options, @client.credentials.merge(ignore_extra_keys: true))
end

#request_headersObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twitter/headers.rb', line 23

def request_headers
  headers = {}
  headers[:user_agent] = @client.user_agent
  if bearer_token_request?
    headers[:accept]        = "*/*"
    headers[:authorization] = bearer_token_credentials_auth_header
  else
    headers[:authorization] = auth_header
  end
  headers
end