Class: PayPal::SDK::Core::OpenIDConnect::API

Inherits:
API::Base
  • Object
show all
Defined in:
lib/paypal-sdk/core/openid_connect/api.rb

Constant Summary collapse

DEFAULT_OPENID_ENDPOINT =
{
:sandbox => "https://api.sandbox.paypal.com",
:live => "https://api.paypal.com" }

Constants inherited from API::Base

API::Base::API_MODES, API::Base::DEFAULT_API_MODE

Instance Attribute Summary

Attributes inherited from API::Base

#http, #service_name, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from API::Base

#api_call, #api_mode, #default_http_header, #delete, #format_error, #get, #patch, #post, #put, sdk_library_details, #set_config

Methods included from Util::HTTPHelper

#configure_ssl, #create_http_connection, #default_ca_file, #encode_www_form, #handle_response, #http_call, #log_http_call, #map_header_value, #new_http, #url_join

Methods included from Authentication

#add_certificate, #base_credential, #base_credential_type, #credential, #set_config, #third_party_credential

Methods included from Configuration

#config, #set_config

Methods included from Logging

#log_event, #logger, logger, logger=

Constructor Details

#initialize(environment = nil, options = {}) ⇒ API

Returns a new instance of API.



12
13
14
# File 'lib/paypal-sdk/core/openid_connect/api.rb', line 12

def initialize(environment = nil, options = {})
  super("", environment, options)
end

Class Method Details

.user_agentObject



41
42
43
# File 'lib/paypal-sdk/core/openid_connect/api.rb', line 41

def user_agent
  @user_agent ||= "PayPalSDK/openid-connect-ruby #{VERSION} (#{sdk_library_details})"
end

Instance Method Details

#format_request(payload) ⇒ Object



20
21
22
23
24
25
# File 'lib/paypal-sdk/core/openid_connect/api.rb', line 20

def format_request(payload)
  payload[:uri].path = url_join(payload[:uri].path, payload[:action])
  payload[:body]    = encode_www_form(payload[:params]) if payload[:params]
  payload[:header]  = {"Content-Type" => "application/x-www-form-urlencoded" }.merge(payload[:header])
  payload
end

#format_response(payload) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/paypal-sdk/core/openid_connect/api.rb', line 27

def format_response(payload)
  payload[:data] =
    if payload[:response].code >= "200" and payload[:response].code <= "299"
      MultiJson.load(payload[:response].body)
    elsif payload[:response].content_type == "application/json"
      { "error" => MultiJson.load(payload[:response].body) }
    else
      { "error" => { "name" => payload[:response].code, "message" => payload[:response].message,
        "developer_msg" => payload[:response] } }
    end
  payload
end

#service_endpointObject



16
17
18
# File 'lib/paypal-sdk/core/openid_connect/api.rb', line 16

def service_endpoint
  self.config.openid_endpoint || DEFAULT_OPENID_ENDPOINT[self.api_mode] || DEFAULT_OPENID_ENDPOINT[:sandbox]
end