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.
11 12 13 14 |
# File 'lib/base.rb', line 11 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.
9 10 11 |
# File 'lib/base.rb', line 9 def params @params end |
Class Method Details
.digest(str_params) ⇒ Object
62 63 64 |
# File 'lib/base.rb', line 62 def digest(str_params) Digest::SHA512.hexdigest str_params end |
.parse(response) ⇒ Object
70 71 72 73 74 |
# File 'lib/base.rb', line 70 def parse(response) ruby_hash_from_response(CGI::parse(response)).tap do |parsed| Yp.logger.info "[YP] Response received with params #{parsed}" end end |
.serialize_params(params) ⇒ Object
66 67 68 |
# File 'lib/base.rb', line 66 def serialize_params(params) uri_string_from_hash(params) end |
Instance Method Details
#body ⇒ Object
16 17 18 19 20 21 |
# File 'lib/base.rb', line 16 def body @params.clone.tap do |params| params[:signature] = create_signing_hash Yp.logger.info "[YP] Sending transaction with params #{params.to_s}" end end |
#create_signing_hash ⇒ Object
23 24 25 |
# File 'lib/base.rb', line 23 def create_signing_hash self.class.digest(self.class.serialize_params(@params) + @signature_key) end |
#send ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/base.rb', line 27 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 |