Module: Khalti::RequestHelper
- Defined in:
- lib/khalti/request_helper.rb
Overview
Handles API calls
Constant Summary collapse
- SECRET_KEY =
ENV['KHALTI_SECRET_KEY']
Class Method Summary collapse
Class Method Details
.get(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/khalti/request_helper.rb', line 8 def get(path) validate_secret_key uri = URI.parse(path) req = Net::HTTP::Get.new(uri) req['authorization'] = "Key #{SECRET_KEY}" res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end extract_response(res) end |
.post(path, params) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/khalti/request_helper.rb', line 19 def post(path, params) validate_secret_key uri = URI.parse(path) req = Net::HTTP::Post.new(uri) req['authorization'] = "Key #{SECRET_KEY}" req.set_form_data(params) res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end extract_response(res) end |