paypal-sdk-core 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/paypal-sdk-core.rb +41 -41
- data/lib/paypal-sdk/core/api/base.rb +4 -4
- data/lib/paypal-sdk/core/config.rb +153 -139
- data/lib/paypal-sdk/core/credential/third_party/token.rb +3 -3
- data/lib/paypal-sdk/core/logging.rb +45 -43
- data/lib/paypal-sdk/core/util/oauth_signature.rb +1 -1
- data/lib/paypal-sdk/core/version.rb +1 -1
- data/spec/config/cacert.pem +171 -0
- data/spec/core/config_spec.rb +22 -0
- data/spec/log/test.log +624 -0
- metadata +6 -4
data/README.md
CHANGED
data/lib/paypal-sdk-core.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require "paypal-sdk/core/version"
|
2
|
-
require "paypal-sdk/core/config"
|
3
|
-
require "paypal-sdk/core/logging"
|
4
|
-
|
5
|
-
module PayPal
|
6
|
-
module SDK
|
7
|
-
module Core
|
8
|
-
|
9
|
-
autoload :Authentication, "paypal-sdk/core/authentication"
|
10
|
-
|
11
|
-
module API
|
12
|
-
autoload :Base, "paypal-sdk/core/api/base"
|
13
|
-
autoload :Merchant, "paypal-sdk/core/api/merchant"
|
14
|
-
autoload :Platform, "paypal-sdk/core/api/platform"
|
15
|
-
autoload :IPN, "paypal-sdk/core/api/ipn"
|
16
|
-
|
17
|
-
module DataTypes
|
18
|
-
autoload :Base, "paypal-sdk/core/api/data_types/base"
|
19
|
-
autoload :Enum, "paypal-sdk/core/api/data_types/enum"
|
20
|
-
autoload :SimpleTypes, "paypal-sdk/core/api/data_types/simple_types"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Util
|
25
|
-
autoload :OauthSignature, "paypal-sdk/core/util/oauth_signature"
|
26
|
-
end
|
27
|
-
|
28
|
-
module Credential
|
29
|
-
autoload :Base, "paypal-sdk/core/credential/base"
|
30
|
-
autoload :Certificate, "paypal-sdk/core/credential/certificate"
|
31
|
-
autoload :Signature, "paypal-sdk/core/credential/signature"
|
32
|
-
|
33
|
-
module ThirdParty
|
34
|
-
autoload :Token, "paypal-sdk/core/credential/third_party/token"
|
35
|
-
autoload :Subject, "paypal-sdk/core/credential/third_party/subject"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require "paypal-sdk/core/version"
|
2
|
+
require "paypal-sdk/core/config"
|
3
|
+
require "paypal-sdk/core/logging"
|
4
|
+
|
5
|
+
module PayPal
|
6
|
+
module SDK
|
7
|
+
module Core
|
8
|
+
|
9
|
+
autoload :Authentication, "paypal-sdk/core/authentication"
|
10
|
+
|
11
|
+
module API
|
12
|
+
autoload :Base, "paypal-sdk/core/api/base"
|
13
|
+
autoload :Merchant, "paypal-sdk/core/api/merchant"
|
14
|
+
autoload :Platform, "paypal-sdk/core/api/platform"
|
15
|
+
autoload :IPN, "paypal-sdk/core/api/ipn"
|
16
|
+
|
17
|
+
module DataTypes
|
18
|
+
autoload :Base, "paypal-sdk/core/api/data_types/base"
|
19
|
+
autoload :Enum, "paypal-sdk/core/api/data_types/enum"
|
20
|
+
autoload :SimpleTypes, "paypal-sdk/core/api/data_types/simple_types"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Util
|
25
|
+
autoload :OauthSignature, "paypal-sdk/core/util/oauth_signature"
|
26
|
+
end
|
27
|
+
|
28
|
+
module Credential
|
29
|
+
autoload :Base, "paypal-sdk/core/credential/base"
|
30
|
+
autoload :Certificate, "paypal-sdk/core/credential/certificate"
|
31
|
+
autoload :Signature, "paypal-sdk/core/credential/signature"
|
32
|
+
|
33
|
+
module ThirdParty
|
34
|
+
autoload :Token, "paypal-sdk/core/credential/third_party/token"
|
35
|
+
autoload :Subject, "paypal-sdk/core/credential/third_party/subject"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -125,13 +125,13 @@ module PayPal::SDK::Core
|
|
125
125
|
uri, content, header = format_request(action, params)
|
126
126
|
initheader = default_http_header.merge(header).merge(initheader)
|
127
127
|
initheader.delete_if{|key, val| val.nil? }
|
128
|
-
|
129
|
-
|
128
|
+
response =
|
129
|
+
log_event("Request: #{action}") do
|
130
|
+
@http.post(uri.path, content, initheader)
|
131
|
+
end
|
130
132
|
format_response(action, response)
|
131
133
|
rescue Net::HTTPBadGateway, Errno::ECONNRESET, Errno::ECONNABORTED, SocketError => error
|
132
134
|
format_error(error, error.message)
|
133
|
-
ensure
|
134
|
-
log_event("Request: #{action}", start_time)
|
135
135
|
end
|
136
136
|
|
137
137
|
# Format Request data. It will be override by child class
|
@@ -1,139 +1,153 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module PayPal::SDK::Core
|
5
|
-
|
6
|
-
# Include Configuration module to access configuration from any object
|
7
|
-
# == Examples
|
8
|
-
# # Include in any class
|
9
|
-
# include Configuration
|
10
|
-
#
|
11
|
-
# # Access config object and attributes
|
12
|
-
# config
|
13
|
-
# config.username
|
14
|
-
#
|
15
|
-
# # Change configuration
|
16
|
-
# set_config(:development)
|
17
|
-
module Configuration
|
18
|
-
|
19
|
-
# To get default Config object.
|
20
|
-
def config
|
21
|
-
@config ||= Config.config
|
22
|
-
end
|
23
|
-
|
24
|
-
# To change the configuration to given environment or configuration
|
25
|
-
# === Arguments
|
26
|
-
# * <tt>env</tt> -- Environment
|
27
|
-
# * <tt>override_configurations</tt> (Optional) -- To override the default configuration.
|
28
|
-
def set_config(env, override_configurations = {})
|
29
|
-
@config = env.is_a?(Config) ? env : Config.config(env, override_configurations)
|
30
|
-
end
|
31
|
-
|
32
|
-
alias_method :config=, :set_config
|
33
|
-
end
|
34
|
-
|
35
|
-
# Config class is used to hold the configurations.
|
36
|
-
# == Examples
|
37
|
-
# # To load configurations from file
|
38
|
-
# Config.load('config/paypal.yml', 'development')
|
39
|
-
#
|
40
|
-
# # Get configuration
|
41
|
-
# Config.config # load default configuration
|
42
|
-
# Config.config(:development) # load development configuration
|
43
|
-
# Config.config(:development, :app_id => "XYZ") # Override configuration
|
44
|
-
#
|
45
|
-
# # Read configuration attributes
|
46
|
-
# config = Config.config
|
47
|
-
# config.username
|
48
|
-
# config.end_point
|
49
|
-
class Config
|
50
|
-
attr_accessor :username, :password, :signature, :app_id, :cert_path,
|
51
|
-
:token, :token_secret, :subject,
|
52
|
-
:http_timeout, :http_retry, :http_proxy, :ca_file,
|
53
|
-
:device_ipaddress, :sandbox_email_address,
|
54
|
-
:mode, :end_point, :merchant_end_point, :platform_end_point, :ipn_end_point,
|
55
|
-
:redirect_url, :dev_central_url,
|
56
|
-
:logfile
|
57
|
-
|
58
|
-
# Create Config object
|
59
|
-
# === Options(Hash)
|
60
|
-
# * <tt>username</tt> -- Username
|
61
|
-
# * <tt>password</tt> -- Password
|
62
|
-
# * <tt>signature</tt> (Optional if certificate present) -- Signature
|
63
|
-
# * <tt>app_id</tt> -- Application ID
|
64
|
-
# * <tt>cert_path</tt> (Optional if signature present) -- Certificate file path
|
65
|
-
def initialize(options)
|
66
|
-
options.each do |key, value|
|
67
|
-
send("#{key}=", value)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class << self
|
72
|
-
|
73
|
-
@@config_cache = {}
|
74
|
-
|
75
|
-
# Load configurations from file
|
76
|
-
# === Arguments
|
77
|
-
# * <tt>file_name</tt> -- Configuration file path
|
78
|
-
# * <tt>default_environment</tt> (Optional) -- default environment configuration to load
|
79
|
-
# === Example
|
80
|
-
# Config.load('config/paypal.yml', 'development')
|
81
|
-
def load(file_name, default_env = default_environment)
|
82
|
-
@@
|
83
|
-
@@
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#
|
99
|
-
#
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
if
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
#
|
126
|
-
def
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module PayPal::SDK::Core
|
5
|
+
|
6
|
+
# Include Configuration module to access configuration from any object
|
7
|
+
# == Examples
|
8
|
+
# # Include in any class
|
9
|
+
# include Configuration
|
10
|
+
#
|
11
|
+
# # Access config object and attributes
|
12
|
+
# config
|
13
|
+
# config.username
|
14
|
+
#
|
15
|
+
# # Change configuration
|
16
|
+
# set_config(:development)
|
17
|
+
module Configuration
|
18
|
+
|
19
|
+
# To get default Config object.
|
20
|
+
def config
|
21
|
+
@config ||= Config.config
|
22
|
+
end
|
23
|
+
|
24
|
+
# To change the configuration to given environment or configuration
|
25
|
+
# === Arguments
|
26
|
+
# * <tt>env</tt> -- Environment
|
27
|
+
# * <tt>override_configurations</tt> (Optional) -- To override the default configuration.
|
28
|
+
def set_config(env, override_configurations = {})
|
29
|
+
@config = env.is_a?(Config) ? env : Config.config(env, override_configurations)
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :config=, :set_config
|
33
|
+
end
|
34
|
+
|
35
|
+
# Config class is used to hold the configurations.
|
36
|
+
# == Examples
|
37
|
+
# # To load configurations from file
|
38
|
+
# Config.load('config/paypal.yml', 'development')
|
39
|
+
#
|
40
|
+
# # Get configuration
|
41
|
+
# Config.config # load default configuration
|
42
|
+
# Config.config(:development) # load development configuration
|
43
|
+
# Config.config(:development, :app_id => "XYZ") # Override configuration
|
44
|
+
#
|
45
|
+
# # Read configuration attributes
|
46
|
+
# config = Config.config
|
47
|
+
# config.username
|
48
|
+
# config.end_point
|
49
|
+
class Config
|
50
|
+
attr_accessor :username, :password, :signature, :app_id, :cert_path,
|
51
|
+
:token, :token_secret, :subject,
|
52
|
+
:http_timeout, :http_retry, :http_proxy, :ca_file,
|
53
|
+
:device_ipaddress, :sandbox_email_address,
|
54
|
+
:mode, :end_point, :merchant_end_point, :platform_end_point, :ipn_end_point,
|
55
|
+
:redirect_url, :dev_central_url,
|
56
|
+
:logfile
|
57
|
+
|
58
|
+
# Create Config object
|
59
|
+
# === Options(Hash)
|
60
|
+
# * <tt>username</tt> -- Username
|
61
|
+
# * <tt>password</tt> -- Password
|
62
|
+
# * <tt>signature</tt> (Optional if certificate present) -- Signature
|
63
|
+
# * <tt>app_id</tt> -- Application ID
|
64
|
+
# * <tt>cert_path</tt> (Optional if signature present) -- Certificate file path
|
65
|
+
def initialize(options)
|
66
|
+
options.each do |key, value|
|
67
|
+
send("#{key}=", value)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
|
73
|
+
@@config_cache = {}
|
74
|
+
|
75
|
+
# Load configurations from file
|
76
|
+
# === Arguments
|
77
|
+
# * <tt>file_name</tt> -- Configuration file path
|
78
|
+
# * <tt>default_environment</tt> (Optional) -- default environment configuration to load
|
79
|
+
# === Example
|
80
|
+
# Config.load('config/paypal.yml', 'development')
|
81
|
+
def load(file_name, default_env = default_environment)
|
82
|
+
@@config_cache = {}
|
83
|
+
@@configurations = read_configurations(file_name)
|
84
|
+
@@default_environment = default_env
|
85
|
+
config
|
86
|
+
end
|
87
|
+
|
88
|
+
# Get default environment name
|
89
|
+
def default_environment
|
90
|
+
@@default_environment ||= ENV['PAYPAL_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['ENV'] || "development"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Set default environment
|
94
|
+
def default_environment=(env)
|
95
|
+
@@default_environment = env.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
# Create or Load Config object based on given environment and configurations.
|
99
|
+
# === Attributes
|
100
|
+
# * <tt>env</tt> (Optional) -- Environment name
|
101
|
+
# * <tt>override_configuration</tt> (Optional) -- Override the configuration given in file.
|
102
|
+
# === Example
|
103
|
+
# Config.config
|
104
|
+
# Config.config(:development)
|
105
|
+
# Config.config(:development, { :app_id => "XYZ" })
|
106
|
+
def config(env = default_environment, override_configuration = {})
|
107
|
+
if env.is_a? Hash
|
108
|
+
override_configuration = env
|
109
|
+
env = default_environment
|
110
|
+
end
|
111
|
+
env = (env || default_environment).to_s
|
112
|
+
raise "Configuration[#{env}] NotFound" unless configurations[env]
|
113
|
+
if override_configuration.nil? or override_configuration.empty?
|
114
|
+
@@config_cache[env] ||= new configurations[env]
|
115
|
+
else
|
116
|
+
new configurations[env].merge(override_configuration)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Set logger
|
121
|
+
def logger=(logger)
|
122
|
+
Logging.logger = logger
|
123
|
+
end
|
124
|
+
|
125
|
+
# Get logger
|
126
|
+
def logger
|
127
|
+
Logging.logger
|
128
|
+
end
|
129
|
+
|
130
|
+
# Get raw configurations in Hash format.
|
131
|
+
def configurations
|
132
|
+
@@configurations ||= read_configurations
|
133
|
+
end
|
134
|
+
|
135
|
+
# Set configuration
|
136
|
+
def configurations=(configs)
|
137
|
+
@@config_cache = {}
|
138
|
+
@@configurations = Hash[configs.map{|k,v| [k.to_s, v] }]
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
# Read configurations from the given file name
|
143
|
+
# === Arguments
|
144
|
+
# * <tt>file_name</tt> (Optional) -- Configuration file path
|
145
|
+
def read_configurations(file_name = "config/paypal.yml")
|
146
|
+
erb = ERB.new(File.read(file_name))
|
147
|
+
erb.filename = file_name
|
148
|
+
YAML.load(erb.result)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -21,9 +21,9 @@ module PayPal::SDK::Core
|
|
21
21
|
|
22
22
|
# Return credential properties for authentication.
|
23
23
|
def properties
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
credential_properties = credential.properties
|
25
|
+
credential_properties.delete_if{|k,v| RemoveProperties.include? k }
|
26
|
+
credential_properties.merge( :authorization => oauth_authentication )
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
@@ -1,43 +1,45 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
module PayPal::SDK::Core
|
4
|
-
# Include Logging module to provide logger functionality.
|
5
|
-
# == Configure logger
|
6
|
-
# Logging.logger = Logger.new(STDERR)
|
7
|
-
#
|
8
|
-
# == Example
|
9
|
-
# include Logger
|
10
|
-
# logger.info "Debug message"
|
11
|
-
module Logging
|
12
|
-
|
13
|
-
# Get logger object
|
14
|
-
def logger
|
15
|
-
@logger ||= Logging.logger
|
16
|
-
end
|
17
|
-
|
18
|
-
def log_event(message,
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
# ===
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module PayPal::SDK::Core
|
4
|
+
# Include Logging module to provide logger functionality.
|
5
|
+
# == Configure logger
|
6
|
+
# Logging.logger = Logger.new(STDERR)
|
7
|
+
#
|
8
|
+
# == Example
|
9
|
+
# include Logger
|
10
|
+
# logger.info "Debug message"
|
11
|
+
module Logging
|
12
|
+
|
13
|
+
# Get logger object
|
14
|
+
def logger
|
15
|
+
@logger ||= Logging.logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def log_event(message, &block)
|
19
|
+
start_time = Time.now
|
20
|
+
block.call
|
21
|
+
ensure
|
22
|
+
logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
|
27
|
+
# Get or Create configured logger based on the default environment configuration
|
28
|
+
def logger
|
29
|
+
@logger ||= Logger.new(Config.config.logfile || STDERR)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Set logger directly and clear the loggers cache.
|
33
|
+
# === Attributes
|
34
|
+
# * <tt>logger</tt> -- Logger object
|
35
|
+
# === Example
|
36
|
+
# Logging.logger = Logger.new(STDERR)
|
37
|
+
def logger=(logger)
|
38
|
+
@logger = logger
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|