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


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

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

Class Method Details

.user_agentObject


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

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

Instance Method Details

#format_request(payload) ⇒ Object


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

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


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

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


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

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