Module: Methods
- Included in:
- OnlinePaymentPlatform::Client, OnlinePaymentPlatform::Client::Merchant, OnlinePaymentPlatform::Client::Transaction
- Defined in:
- lib/online_payment_platform/methods.rb
Instance Method Summary collapse
- #assert_one_of!(options, *keys) ⇒ Object
- #assert_required_keys!(options, *keys) ⇒ Object
- #fetch(uri) ⇒ Object
- #generate_uri(*path) ⇒ Object
- #post(uri, payload = {}) ⇒ Object
Instance Method Details
#assert_one_of!(options, *keys) ⇒ Object
10 11 12 |
# File 'lib/online_payment_platform/methods.rb', line 10 def assert_one_of!(, *keys) raise 'Missing one of required keys!' unless (.keys & keys).any? end |
#assert_required_keys!(options, *keys) ⇒ Object
4 5 6 7 8 |
# File 'lib/online_payment_platform/methods.rb', line 4 def assert_required_keys!(, *keys) keys.each do |key| raise 'Required key missing!' if [key].nil? end end |
#fetch(uri) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/online_payment_platform/methods.rb', line 33 def fetch(uri) config = OnlinePaymentPlatform.configuration req = Net::HTTP::Get.new(uri) req['Authorization'] = "Bearer #{config.api_key}" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request req end JSON.parse response.body end |
#generate_uri(*path) ⇒ Object
14 15 16 17 |
# File 'lib/online_payment_platform/methods.rb', line 14 def generate_uri(*path) encoded_uri = OnlinePaymentPlatform.configuration.base_uri + path.join('/') URI.parse encoded_uri end |
#post(uri, payload = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/online_payment_platform/methods.rb', line 19 def post(uri, payload = {}) config = OnlinePaymentPlatform.configuration req = Net::HTTP::Post.new(uri, { 'Content-Type': 'text/json' }) req['Authorization'] = "Bearer #{config.api_key}" req.body = payload.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request req end JSON.parse response.body end |