Class: Mercadopago::RequestOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/mercadopago/config/request_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, connection_timeout: 60.0, custom_headers: nil, corporation_id: nil, integrator_id: nil, platform_id: nil, max_retries: 3) ⇒ RequestOptions

Returns a new instance of RequestOptions.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mercadopago/config/request_options.rb', line 9

def initialize(access_token: nil,
               connection_timeout: 60.0,
               custom_headers: nil,
               corporation_id: nil,
               integrator_id: nil,
               platform_id: nil,
               max_retries: 3)
  self.access_token = access_token
  self.connection_timeout = connection_timeout
  self.custom_headers = custom_headers
  self.corporation_id = corporation_id
  self.integrator_id = integrator_id
  self.platform_id = platform_id
  self.max_retries = max_retries

  @config = Config.new
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def access_token
  @access_token
end

#connection_timeoutObject

Returns the value of attribute connection_timeout.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def connection_timeout
  @connection_timeout
end

#corporation_idObject

Returns the value of attribute corporation_id.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def corporation_id
  @corporation_id
end

#custom_headersObject

Returns the value of attribute custom_headers.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def custom_headers
  @custom_headers
end

#integrator_idObject

Returns the value of attribute integrator_id.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def integrator_id
  @integrator_id
end

#max_retriesObject

Returns the value of attribute max_retries.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def max_retries
  @max_retries
end

#platform_idObject

Returns the value of attribute platform_id.



6
7
8
# File 'lib/mercadopago/config/request_options.rb', line 6

def platform_id
  @platform_id
end

Instance Method Details

#get_headersObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mercadopago/config/request_options.rb', line 27

def get_headers
  headers = { 'Authorization': "Bearer #{@access_token}",
              'x-product-id' => @config.product_id,
              'x-tracking-id' => @config.tracking_id,
              'x-idempotency-key' => SecureRandom.uuid,
              'User-Agent' => @config.user_agent,
              'Accept': @config.mime_json }

  headers['x-corporation-id'] = @corporation_id unless @corporation_id.nil?
  headers['x-integrator-id'] = @integrator_id unless @integrator_id.nil?
  headers['x-platform-id'] = @platform_id unless @platform_id.nil?

  headers.merge!(@custom_headers) unless @custom_headers.nil?

  headers
end