gerencianet 1.0.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +48 -135
- data/.codeclimate.yml +0 -10
- data/.gitignore +0 -21
- data/.rubocop.yml +0 -18
- data/.travis.yml +0 -4
- data/CHANGELOG.md +0 -74
- data/Gemfile +0 -9
- data/Guardfile +0 -5
- data/LICENSE +0 -21
- data/README.md +0 -96
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/examples/.gitignore +0 -1
- data/examples/certs/developmentCertificate.pem +0 -0
- data/examples/certs/productionCertificate.pem +0 -0
- data/examples/credentials.rb +0 -7
- data/examples/default/carnet/cancel_carnet.rb +0 -15
- data/examples/default/carnet/cancel_parcel.rb +0 -16
- data/examples/default/carnet/create_carnet.rb +0 -32
- data/examples/default/carnet/create_carnet_history.rb +0 -19
- data/examples/default/carnet/detail_carnet.rb +0 -15
- data/examples/default/carnet/resend_carnet.rb +0 -19
- data/examples/default/carnet/resend_parcel.rb +0 -20
- data/examples/default/carnet/settle_carnet_parcel.rb +0 -16
- data/examples/default/carnet/update_carnet_metadata.rb +0 -20
- data/examples/default/carnet/update_parcel.rb +0 -20
- data/examples/default/charge/all_in_one.rb +0 -57
- data/examples/default/charge/cancel_charge.rb +0 -15
- data/examples/default/charge/charge_link.rb +0 -27
- data/examples/default/charge/create_billet_payment.rb +0 -33
- data/examples/default/charge/create_card_payment.rb +0 -39
- data/examples/default/charge/create_charge.rb +0 -24
- data/examples/default/charge/create_charge_balance_sheet.rb +0 -80
- data/examples/default/charge/create_charge_history.rb +0 -19
- data/examples/default/charge/create_charge_onestep.rb +0 -36
- data/examples/default/charge/create_charge_onestep_creditcard.rb +0 -45
- data/examples/default/charge/detail_charge.rb +0 -15
- data/examples/default/charge/resend_billet.rb +0 -19
- data/examples/default/charge/settle_charge.rb +0 -15
- data/examples/default/charge/update_billet.rb +0 -19
- data/examples/default/charge/update_charge_link.rb +0 -27
- data/examples/default/charge/update_charge_metadata.rb +0 -20
- data/examples/default/marketplace/create_charge_onestep_billet_marketplace.rb +0 -45
- data/examples/default/marketplace/create_charge_onestep_creditcard_marketplace.rb +0 -54
- data/examples/default/notification/get_notification.rb +0 -15
- data/examples/default/others/get_installments.rb +0 -16
- data/examples/default/subscriptions/cancel_subscription.rb +0 -15
- data/examples/default/subscriptions/create_plan.rb +0 -17
- data/examples/default/subscriptions/create_subscription.rb +0 -31
- data/examples/default/subscriptions/create_subscription_history.rb +0 -19
- data/examples/default/subscriptions/create_subscription_payment.rb +0 -38
- data/examples/default/subscriptions/delete_plan.rb +0 -15
- data/examples/default/subscriptions/detail_subscription.rb +0 -15
- data/examples/default/subscriptions/get_plans.rb +0 -17
- data/examples/default/subscriptions/update_plan.rb +0 -19
- data/examples/default/subscriptions/update_subscription_metadata.rb +0 -20
- data/examples/gn/account/pix_detail_balance.rb +0 -16
- data/examples/gn/account/pix_detail_settings.rb +0 -17
- data/examples/gn/account/pix_update_settings.rb +0 -33
- data/examples/gn/key/pix_create_evp.rb +0 -17
- data/examples/gn/key/pix_delete_evp.rb +0 -20
- data/examples/gn/key/pix_list_evp.rb +0 -16
- data/examples/pix/charge/pix_create_charge.rb +0 -35
- data/examples/pix/charge/pix_create_immediate_charge.rb +0 -31
- data/examples/pix/charge/pix_detail_charge.rb +0 -21
- data/examples/pix/charge/pix_list_charges.rb +0 -21
- data/examples/pix/charge/pix_update_charge.rb +0 -26
- data/examples/pix/location/pix_create_location.rb +0 -20
- data/examples/pix/location/pix_detail_location.rb +0 -20
- data/examples/pix/location/pix_generate_qrcode.rb +0 -26
- data/examples/pix/location/pix_list_location.rb +0 -21
- data/examples/pix/location/pix_unset_txid.rb +0 -21
- data/examples/pix/pix/pix_detail.rb +0 -20
- data/examples/pix/pix/pix_detail_devolution.rb +0 -22
- data/examples/pix/pix/pix_devolution.rb +0 -27
- data/examples/pix/pix/pix_list_received.rb +0 -21
- data/examples/pix/pix/pix_send.rb +0 -27
- data/examples/pix/webhooks/pix_config_webhook.rb +0 -28
- data/examples/pix/webhooks/pix_delete_webhook.rb +0 -22
- data/examples/pix/webhooks/pix_detail_webhook.rb +0 -21
- data/examples/pix/webhooks/pix_list_webhook.rb +0 -22
- data/gerencianet.gemspec +0 -37
- data/lib/gerencianet/constants.rb +0 -274
- data/lib/gerencianet/endpoints.rb +0 -196
- data/lib/gerencianet/status.rb +0 -7
- data/lib/gerencianet/version.rb +0 -4
- data/lib/gerencianet.rb +0 -9
@@ -1,196 +0,0 @@
|
|
1
|
-
require "http"
|
2
|
-
require "cgi"
|
3
|
-
require "gerencianet/constants"
|
4
|
-
require "gerencianet/status"
|
5
|
-
require "gerencianet/version"
|
6
|
-
|
7
|
-
module Gerencianet
|
8
|
-
# Given the constants file, with the endpoints signatures,
|
9
|
-
# this class maps each one of them to a concerning function
|
10
|
-
class Endpoints
|
11
|
-
attr_accessor :token
|
12
|
-
attr_reader :endpoints
|
13
|
-
attr_reader :urls
|
14
|
-
attr_reader :base_url
|
15
|
-
attr_reader :options
|
16
|
-
|
17
|
-
def initialize(options)
|
18
|
-
@token = nil
|
19
|
-
@options = options
|
20
|
-
@endpoints = Constants::ENDPOINTS
|
21
|
-
@urls = Constants::URL
|
22
|
-
@base_url = current_base_url
|
23
|
-
|
24
|
-
create_methods
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def create_methods
|
31
|
-
if (@options.has_key?(:pix_cert))
|
32
|
-
@endpoints[:PIX].each do |key, settings|
|
33
|
-
self.class.send(:define_method, key) do |args = {}|
|
34
|
-
create(args[:params], args[:body], settings)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
else
|
38
|
-
@endpoints[:DEFAULT].each do |key, settings|
|
39
|
-
self.class.send(:define_method, key) do |args = {}|
|
40
|
-
create(args[:params], args[:body], settings)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def create(params, body, settings)
|
47
|
-
authenticate unless @token
|
48
|
-
response = make_request(params, body, settings)
|
49
|
-
if response.status.to_s == STATUS::UNAUTHORIZED
|
50
|
-
authenticate
|
51
|
-
response = make_request(params, body, settings)
|
52
|
-
end
|
53
|
-
if response.to_s.empty?
|
54
|
-
puts response.status.to_s
|
55
|
-
else
|
56
|
-
respond(response)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def make_request(params, body, settings)
|
61
|
-
url = get_url(params, settings[:route])
|
62
|
-
headers = {
|
63
|
-
"accept" => "application/json",
|
64
|
-
"api-sdk" => "ruby-#{Gerencianet::VERSION}"
|
65
|
-
}
|
66
|
-
|
67
|
-
if @options[:partner_token]
|
68
|
-
headers['partner-token'] = @options[:partner_token]
|
69
|
-
end
|
70
|
-
|
71
|
-
if @options[:"x-skip-mtls-checking"]
|
72
|
-
headers["x-skip-mtls-checking"] = @options[:"x-skip-mtls-checking"]
|
73
|
-
end
|
74
|
-
|
75
|
-
if (@options.has_key?(:pix_cert))
|
76
|
-
|
77
|
-
HTTP
|
78
|
-
.headers(headers)
|
79
|
-
.auth("Bearer #{@token['access_token']}")
|
80
|
-
.method(settings[:method])
|
81
|
-
.call(url, json: body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
82
|
-
ctx.set_params(
|
83
|
-
cert: OpenSSL::X509::Certificate.new(File.read(@options[:pix_cert])),
|
84
|
-
key: OpenSSL::PKey::RSA.new(File.read(@options[:pix_cert]))
|
85
|
-
)
|
86
|
-
end)
|
87
|
-
|
88
|
-
else
|
89
|
-
HTTP
|
90
|
-
.headers(headers)
|
91
|
-
.auth("Bearer #{@token['access_token']}")
|
92
|
-
.method(settings[:method])
|
93
|
-
.call(url, json: body)
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def authenticate
|
99
|
-
if (@options.has_key?(:pix_cert))
|
100
|
-
url = get_url({}, @endpoints[:PIX][:authorize][:route])
|
101
|
-
else
|
102
|
-
url = get_url({}, @endpoints[:DEFAULT][:authorize][:route])
|
103
|
-
end
|
104
|
-
headers = {
|
105
|
-
"accept" => "application/json",
|
106
|
-
"api-sdk" => "ruby-#{Gerencianet::VERSION}"
|
107
|
-
}
|
108
|
-
|
109
|
-
if (@options.has_key?(:pix_cert))
|
110
|
-
|
111
|
-
response =
|
112
|
-
HTTP
|
113
|
-
.headers(headers)
|
114
|
-
.basic_auth(auth_headers)
|
115
|
-
.post(url, json: auth_body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
116
|
-
ctx.set_params(
|
117
|
-
cert: OpenSSL::X509::Certificate.new(File.read(@options[:pix_cert])),
|
118
|
-
key: OpenSSL::PKey::RSA.new(File.read(@options[:pix_cert]))
|
119
|
-
)
|
120
|
-
end)
|
121
|
-
else
|
122
|
-
response =
|
123
|
-
HTTP
|
124
|
-
.headers(headers)
|
125
|
-
.basic_auth(auth_headers)
|
126
|
-
.post(url, json: auth_body)
|
127
|
-
end
|
128
|
-
|
129
|
-
if response.status.to_s == STATUS::UNAUTHORIZED
|
130
|
-
fail "unable to authenticate"
|
131
|
-
else
|
132
|
-
@token = respond(response)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def auth_headers
|
137
|
-
{
|
138
|
-
user: @options[:client_id],
|
139
|
-
pass: @options[:client_secret]
|
140
|
-
}
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
def auth_body
|
145
|
-
{grant_type: :client_credentials}
|
146
|
-
end
|
147
|
-
|
148
|
-
def get_url(params, route)
|
149
|
-
params = {} if params.nil?
|
150
|
-
route = remove_placeholders(params, route)
|
151
|
-
full_url(params, route)
|
152
|
-
end
|
153
|
-
|
154
|
-
def remove_placeholders(params, route)
|
155
|
-
regex = /\:(\w+)/
|
156
|
-
route.scan(regex).each do |key|
|
157
|
-
key = key[0]
|
158
|
-
value = params[key.to_sym].to_s
|
159
|
-
route = route.gsub(":#{key}", value)
|
160
|
-
params.delete(key.to_sym)
|
161
|
-
end
|
162
|
-
|
163
|
-
route
|
164
|
-
end
|
165
|
-
|
166
|
-
def full_url(params, route)
|
167
|
-
mapped = map_params(params)
|
168
|
-
|
169
|
-
if !mapped.empty?
|
170
|
-
"#{@base_url}#{route}?#{mapped}"
|
171
|
-
else
|
172
|
-
"#{@base_url}#{route}"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def map_params(params)
|
177
|
-
params.map do |key|
|
178
|
-
"#{key[0]}=#{CGI.escape(key[1].to_s)}"
|
179
|
-
end.join("&")
|
180
|
-
end
|
181
|
-
|
182
|
-
def current_base_url
|
183
|
-
if (@options.has_key?(:pix_cert))
|
184
|
-
@options[:sandbox] ? @urls[:PIX][:sandbox] : @urls[:PIX][:production]
|
185
|
-
else
|
186
|
-
@options[:sandbox] ? @urls[:DEFAULT][:sandbox] : @urls[:DEFAULT][:production]
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def respond(response)
|
191
|
-
JSON.parse(response)
|
192
|
-
rescue JSON::ParserError
|
193
|
-
raise "unable to parse server response, not a valid json"
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
data/lib/gerencianet/status.rb
DELETED
data/lib/gerencianet/version.rb
DELETED