Sha256: ebfa8f741755d4873d59a8a54dc57767e8539dfc35e5f2e1ef60d6159d5876d4
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 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 = URI.encode(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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
online_payment_platform-0.0.0 | lib/online_payment_platform/methods.rb |