Repository navigation
Expand file tree
/
Copy pathtransport.rb
More file actions
64 lines (52 loc) · 1.61 KB
/
Copy pathtransport.rb
File metadata and controls
64 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
# Autogenerated — do not edit manually
require "json"
require "net/http"
require "openssl"
require "uri"
module Paystack
class Transport
BASE_URL = "https://api.paystack.co"
def initialize(api_key)
@api_key = api_key
@uri = URI(BASE_URL)
end
def get(path, query: {})
request(Net::HTTP::Get, path, query: query)
end
def post(path, body: {}, query: {})
request(Net::HTTP::Post, path, body: body, query: query)
end
def put(path, body: {}, query: {})
request(Net::HTTP::Put, path, body: body, query: query)
end
def patch(path, body: {}, query: {})
request(Net::HTTP::Patch, path, body: body, query: query)
end
def delete(path, body: {}, query: {})
request(Net::HTTP::Delete, path, body: body, query: query)
end
private
def request(klass, path, query: {}, body: {})
full_path = query.empty? ? path : "#{path}?#{URI.encode_www_form(query.compact)}"
Net::HTTP.start(@uri.host, @uri.port, **ssl_options) do |http|
req = klass.new(full_path)
req["Authorization"] = "Bearer #{@api_key}"
req["Content-Type"] = "application/json"
req["Accept"] = "application/json"
req["User-Agent"] = "paystack-ruby/#{Paystack::VERSION}"
req.body = body.to_json unless body.empty?
Response.new(http.request(req))
end
end
def ssl_options
{
use_ssl: true,
min_version: OpenSSL::SSL::TLS1_2_VERSION,
verify_mode: OpenSSL::SSL::VERIFY_PEER,
open_timeout: 10,
read_timeout: 30
}
end
end
end