Sha256: 082287a20764f0a03ab172dae13cd262ad54784c4895ba48c7ba35f56ceaed8f
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module Methods def assert_required_keys!(options, *keys) keys.each do |key| raise 'Required key missing!' if options[key].nil? end end def assert_one_of!(options, *keys) raise 'Missing one of required keys!' unless (options.keys & keys).any? end def generate_uri(*path) encoded_uri = OnlinePaymentPlatform.configuration.base_uri + path.join('/') URI.parse encoded_uri end 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 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
online_payment_platform-0.0.3 | lib/online_payment_platform/methods.rb |
online_payment_platform-0.0.1 | lib/online_payment_platform/methods.rb |