Class: PayPal::SDK::Core::Util::OauthSignature
- Inherits:
-
Object
- Object
- PayPal::SDK::Core::Util::OauthSignature
- Defined in:
- lib/paypal-sdk/core/util/oauth_signature.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_secret ⇒ Object
Returns the value of attribute token_secret.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #authorization_string ⇒ Object
- #base_string ⇒ Object
-
#initialize(username, password, token, token_secret, url, timestamp = nil) ⇒ OauthSignature
constructor
A new instance of OauthSignature.
- #oauth_signature ⇒ Object
-
#paypal_encode(str) ⇒ Object
The PayPalURLEncoder java class percent encodes everything other than ‘a-zA-Z0-9 _’.
Constructor Details
#initialize(username, password, token, token_secret, url, timestamp = nil) ⇒ OauthSignature
Returns a new instance of OauthSignature.
11 12 13 14 15 16 17 18 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 11 def initialize(username, password, token, token_secret, url, = nil) @username = username @password = password @token = token @token_secret = token_secret @url = url @timestamp = || Time.now.to_i.to_s end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def password @password end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def @timestamp end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def token @token end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def token_secret @token_secret end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 9 def username @username end |
Instance Method Details
#authorization_string ⇒ Object
20 21 22 23 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 20 def signature = oauth_signature "token=#{token},signature=#{signature},timestamp=#{}" end |
#base_string ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 35 def base_string params = { "oauth_consumer_key" => username, "oauth_version" => "1.0", "oauth_signature_method" => "HMAC-SHA1", "oauth_token" => token, "oauth_timestamp" => , } sorted_query_string = params.sort.map{|v| v.join("=") }.join("&") base = [ "POST", paypal_encode(url), paypal_encode(sorted_query_string) ].join("&") base = base.gsub(/%[0-9A-F][0-9A-F]/, &:downcase ) end |
#oauth_signature ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 25 def oauth_signature key = [ paypal_encode(password), paypal_encode(token_secret), ].join("&").gsub(/%[0-9A-F][0-9A-F]/, &:downcase ) digest = OpenSSL::HMAC.digest('sha1', key, base_string) Base64.encode64(digest).chomp end |
#paypal_encode(str) ⇒ Object
The PayPalURLEncoder java class percent encodes everything other than ‘a-zA-Z0-9 _’. Then it converts ‘ ’ to ‘+’. Ruby’s CGI.encode takes care of the ‘ ’ and ‘*’ to satisfy PayPal (but beware, URI.encode percent encodes spaces, and does nothing with ‘*’). Finally, CGI.encode does not encode ‘.-’, which we need to do here.
58 59 60 |
# File 'lib/paypal-sdk/core/util/oauth_signature.rb', line 58 def paypal_encode str CGI.escape(str.to_s).gsub('.', '%2E').gsub('-', '%2D') end |