Class: AmzSpApi::SpApiClient

Inherits:
ApiClient show all
Defined in:
lib/sp_api_client.rb

Instance Attribute Summary

Attributes inherited from ApiClient

#config, #default_headers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiClient

#build_collection_param, #build_request, #build_request_body, #build_request_url, #convert_to_type, default, #deserialize, #download_file, #json_mime?, #object_to_hash, #object_to_http_body, #sanitize_filename, #select_header_accept, #select_header_content_type, #update_params_for_auth!, #user_agent=

Constructor Details

#initialize(config = SpConfiguration.default) ⇒ SpApiClient

Returns a new instance of SpApiClient.



9
10
11
# File 'lib/sp_api_client.rb', line 9

def initialize(config = SpConfiguration.default)
  super(config)
end

Class Method Details

.signed_request_headers(config, http_method, url, body) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sp_api_client.rb', line 21

def self.signed_request_headers(config, http_method, url, body)
  request_config = {
    service: 'execute-api',
    region: config.aws_region
  }
  if config.credentials_provider
    request_config[:credentials_provider] = config.credentials_provider
  else
    request_config[:access_key_id] = config.aws_access_key_id
    request_config[:secret_access_key] = config.aws_secret_access_key
  end
  signer = Aws::Sigv4::Signer.new(request_config)
  signer.sign_request(http_method: http_method.to_s, url: url, body: body).headers
end

Instance Method Details

#call_api(http_method, path, opts = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/sp_api_client.rb', line 14

def call_api(http_method, path, opts = {})
  unsigned_request = build_request(http_method, path, opts)
  aws_headers = auth_headers(http_method, unsigned_request.url, unsigned_request.encoded_body)
  signed_opts = opts.merge(:header_params => aws_headers.merge(opts[:header_params] || {}))
  super(http_method, path, signed_opts)
end

#super_call_apiObject



13
# File 'lib/sp_api_client.rb', line 13

alias_method :super_call_api, :call_api