Class: Yp::Base
- Inherits:
-
Object
- Object
- Yp::Base
- Defined in:
- lib/base.rb
Constant Summary collapse
- TYPE =
{ ecom: 1, moto: 2, ca: 9 }.freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #create_signing_hash ⇒ Object
-
#initialize(signature_key, type: :ecom, **params) ⇒ Base
constructor
A new instance of Base.
- #send ⇒ Object
Constructor Details
#initialize(signature_key, type: :ecom, **params) ⇒ Base
Returns a new instance of Base.
13 14 15 16 |
# File 'lib/base.rb', line 13 def initialize(signature_key, type: :ecom, **params) @params = transaction_params(params, type) @signature_key = signature_key end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/base.rb', line 11 def params @params end |
Class Method Details
.digest(str_params) ⇒ Object
64 65 66 |
# File 'lib/base.rb', line 64 def digest(str_params) Digest::SHA512.hexdigest str_params end |
.parse(response) ⇒ Object
72 73 74 75 76 |
# File 'lib/base.rb', line 72 def parse(response) ruby_hash_from_response(CGI::parse(response)).tap do |parsed| TransactionLogger.log_response(parsed) end end |
.serialize_params(params) ⇒ Object
68 69 70 |
# File 'lib/base.rb', line 68 def serialize_params(params) uri_string_from_hash(params) end |
Instance Method Details
#body ⇒ Object
18 19 20 21 22 23 |
# File 'lib/base.rb', line 18 def body @params.clone.tap do |params| params[:signature] = create_signing_hash TransactionLogger.log_request(params) end end |
#create_signing_hash ⇒ Object
25 26 27 |
# File 'lib/base.rb', line 25 def create_signing_hash self.class.digest(self.class.serialize_params(@params) + @signature_key) end |
#send ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/base.rb', line 29 def send if block_given? RestClient.post(URL, body) do |response| yield(self.class.parse response) end else self.class.parse(RestClient.post(URL, body)) end end |