lib/khalti/transaction.rb in khalti-0.1.4 vs lib/khalti/transaction.rb in khalti-0.1.5

- old
+ new

@@ -1,38 +1,17 @@ require 'uri' require 'net/http' require 'json' -API_URL = 'https://khalti.com/api/merchant-transaction' - module Khalti class Transaction + API_URL = 'https://khalti.com/api/merchant-transaction' def self.find(idx) - secret_key = ENV['KHALTI_SECRET_KEY'] #test_secret_key_f59e8b7d18b4499ca40f68195a846e9b - headers = { - Authorization: "Key #{secret_key}" - } - uri = URI.parse("#{API_URL}/#{idx}/") - puts uri - https = Net::HTTP.new(uri.host, uri.port) - https.use_ssl = true - request = Net::HTTP::Get.new(uri.request_uri, headers) - response = https.request(request) - - JSON.parse(response.body) || {} + raise Errors::BlankError.new('Ensure idx is not blank.') if idx.nil? || idx.strip.empty? + RequestHelper.get("#{API_URL}/#{idx}/") end def self.all - secret_key = ENV['KHALTI_SECRET_KEY'] #test_secret_key_f59e8b7d18b4499ca40f68195a846e9b - headers = { - Authorization: "Key #{secret_key}" - } - uri = URI.parse("#{API_URL}/") - https = Net::HTTP.new(uri.host, uri.port) - https.use_ssl = true - request = Net::HTTP::Get.new(uri.request_uri, headers) - response = https.request(request) - - JSON.parse(response.body) || {} + RequestHelper.get("#{API_URL}/") end end end