Class: MonopayRuby::Webhooks::PublicKey
- Defined in:
- lib/monopay-ruby/webhooks/public_key.rb
Constant Summary collapse
- API_GET_KEY_URL =
"#{API_URL}/merchant/pubkey".freeze
- PUBLIC_KEY_KEY =
"key".freeze
Constants inherited from Base
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize ⇒ PublicKey
constructor
A new instance of PublicKey.
-
#request_key ⇒ Boolean
Get public key from Monobank API.
Constructor Details
#initialize ⇒ PublicKey
Returns a new instance of PublicKey.
14 15 16 |
# File 'lib/monopay-ruby/webhooks/public_key.rb', line 14 def initialize @error_messages = [] end |
Instance Attribute Details
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
9 10 11 |
# File 'lib/monopay-ruby/webhooks/public_key.rb', line 9 def @error_messages end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/monopay-ruby/webhooks/public_key.rb', line 9 def key @key end |
Instance Method Details
#request_key ⇒ Boolean
Get public key from Monobank API
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/monopay-ruby/webhooks/public_key.rb', line 21 def request_key begin response = RestClient.get(API_GET_KEY_URL, headers) response_body = JSON.parse(response.body) base64_key = JSON.parse(response.body)[PUBLIC_KEY_KEY] @key = Base64.decode64(base64_key) true rescue Exception => e # TODO: Check how for example Stripe or Liqpay handle errors response_body = JSON.parse(e.response.body) = [e., response_body].join(", ") << false end end |