Class: MonopayRuby::Webhooks::PublicKey

Inherits:
Base
  • Object
show all
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

Base::API_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePublicKey

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_messagesObject (readonly)

Returns the value of attribute error_messages.



9
10
11
# File 'lib/monopay-ruby/webhooks/public_key.rb', line 9

def error_messages
  @error_messages
end

#keyObject (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_keyBoolean

Get public key from Monobank API

Returns:

  • (Boolean)

    true if key was successfully received, false otherwise



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)
    error_message = [e.message, response_body].join(", ")

    error_messages << error_message

    false
  end
end