starkinfra 0.4.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/{brcodepreview/brcodepreview.rb → brcode_preview/brcode_preview.rb} +2 -5
- data/lib/{cardmethod/cardmethod.rb → card_method/card_method.rb} +2 -2
- data/lib/{creditholmes/creditholmes.rb → credit_holmes/credit_holmes.rb} +8 -11
- data/lib/{creditnote/creditnote.rb → credit_note/credit_note.rb} +11 -12
- data/lib/{creditnote → credit_note}/invoice/description.rb +3 -5
- data/lib/{creditnote → credit_note}/invoice/discount.rb +3 -4
- data/lib/{creditnote → credit_note}/invoice/invoice.rb +5 -6
- data/lib/{creditnote → credit_note}/log.rb +9 -10
- data/lib/{creditnote → credit_note}/transfer.rb +4 -5
- data/lib/{creditpreview/creditnotepreview.rb → credit_preview/credit_note_preview.rb} +2 -3
- data/lib/{creditpreview/creditpreview.rb → credit_preview/credit_preview.rb} +3 -4
- data/lib/{creditsigner/creditsigner.rb → credit_signer/credit_signer.rb} +3 -6
- data/lib/{dynamicbrcode/dynamicbrcode.rb → dynamic_brcode/dynamic_brcode.rb} +17 -19
- data/lib/error.rb +7 -40
- data/lib/event/attempt.rb +7 -8
- data/lib/event/event.rb +10 -13
- data/lib/{individualdocument/individualdocument.rb → individual_document/individual_document.rb} +7 -8
- data/lib/{individualdocument → individual_document}/log.rb +9 -10
- data/lib/{individualidentity/individualidentity.rb → individual_identity/individual_identity.rb} +7 -8
- data/lib/{individualidentity → individual_identity}/log.rb +9 -10
- data/lib/{issuingbalance/issuingbalance.rb → issuing_balance/issuing_balance.rb} +2 -3
- data/lib/{issuingcard/issuingcard.rb → issuing_card/issuing_card.rb} +9 -10
- data/lib/{issuingcard → issuing_card}/log.rb +9 -10
- data/lib/{issuingdesign/issuingdesign.rb → issuing_design/issuing_design.rb} +5 -6
- data/lib/{issuingembossingkit/issuingembossingkit.rb → issuing_embossing_kit/issuing_embossing_kit.rb} +4 -5
- data/lib/{issuingembossingrequest/issuingembossingrequest.rb → issuing_embossing_request/issuing_embossing_request.rb} +8 -9
- data/lib/{issuingembossingrequest → issuing_embossing_request}/log.rb +9 -10
- data/lib/{issuingholder/issuingholder.rb → issuing_holder/issuing_holder.rb} +9 -10
- data/lib/{issuingholder → issuing_holder}/log.rb +9 -10
- data/lib/{issuinginvoice/issuinginvoice.rb → issuing_invoice/issuing_invoice.rb} +8 -9
- data/lib/{issuinginvoice → issuing_invoice}/log.rb +9 -10
- data/lib/{issuingproduct/issuingproduct.rb → issuing_product/issuing_product.rb} +3 -4
- data/lib/{issuingpurchase/issuingpurchase.rb → issuing_purchase/issuing_purchase.rb} +32 -24
- data/lib/{issuingpurchase → issuing_purchase}/log.rb +9 -10
- data/lib/{issuingrestock/issuingrestock.rb → issuing_restock/issuing_restock.rb} +8 -9
- data/lib/{issuingrestock → issuing_restock}/log.rb +9 -10
- data/lib/{issuingrule/issuingrule.rb → issuing_rule/issuing_rule.rb} +6 -7
- data/lib/{issuingstock/issuingstock.rb → issuing_stock/issuing_stock.rb} +8 -9
- data/lib/{issuingstock → issuing_stock}/log.rb +9 -10
- data/lib/{issuingtransaction/issuingtransaction.rb → issuing_transaction/issuing_transaction.rb} +7 -8
- data/lib/{issuingwithdrawal/issuingwithdrawal.rb → issuing_withdrawal/issuing_withdrawal.rb} +8 -9
- data/lib/{merchantcategory/merchantcategory.rb → merchant_category/merchant_category.rb} +2 -2
- data/lib/{merchantcountry/merchantcountry.rb → merchant_country/merchant_country.rb} +2 -2
- data/lib/{pixbalance/pixbalance.rb → pix_balance/pix_balance.rb} +2 -3
- data/lib/{pixchargeback → pix_chargeback}/log.rb +9 -10
- data/lib/{pixchargeback/pixchargeback.rb → pix_chargeback/pix_chargeback.rb} +8 -9
- data/lib/{pixclaim → pix_claim}/log.rb +9 -10
- data/lib/{pixclaim/pixclaim.rb → pix_claim/pix_claim.rb} +8 -9
- data/lib/{pixdirector/pixdirector.rb → pix_director/pix_director.rb} +2 -2
- data/lib/{pixdomain → pix_domain}/certificate.rb +2 -2
- data/lib/{pixdomain/pixdomain.rb → pix_domain/pix_domain.rb} +3 -3
- data/lib/{pixinfraction → pix_infraction}/log.rb +9 -10
- data/lib/{pixinfraction/pixinfraction.rb → pix_infraction/pix_infraction.rb} +8 -9
- data/lib/{pixkey → pix_key}/log.rb +9 -10
- data/lib/{pixkey/pixkey.rb → pix_key/pix_key.rb} +8 -9
- data/lib/{pixrequest → pix_request}/log.rb +9 -10
- data/lib/{pixrequest/pixrequest.rb → pix_request/pix_request.rb} +9 -10
- data/lib/{pixreversal → pix_reversal}/log.rb +8 -10
- data/lib/{pixreversal/pixreversal.rb → pix_reversal/pix_reversal.rb} +9 -10
- data/lib/{pixstatement/pixstatement.rb → pix_statement/pix_statement.rb} +6 -7
- data/lib/request/request.rb +152 -0
- data/lib/starkinfra.rb +71 -63
- data/lib/{staticbrcode/staticbrcode.rb → static_brcode/static_brcode.rb} +8 -9
- data/lib/utils/parse.rb +23 -42
- data/lib/utils/rest.rb +211 -110
- data/lib/webhook/webhook.rb +2 -3
- metadata +70 -85
- data/lib/key.rb +0 -33
- data/lib/user/organization.rb +0 -54
- data/lib/user/project.rb +0 -37
- data/lib/user/user.rb +0 -20
- data/lib/utils/api.rb +0 -89
- data/lib/utils/bacenid.rb +0 -19
- data/lib/utils/cache.rb +0 -10
- data/lib/utils/case.rb +0 -21
- data/lib/utils/checks.rb +0 -100
- data/lib/utils/endtoendid.rb +0 -11
- data/lib/utils/environment.rb +0 -14
- data/lib/utils/request.rb +0 -79
- data/lib/utils/resource.rb +0 -13
- data/lib/utils/returnid.rb +0 -11
- data/lib/utils/sub_resource.rb +0 -27
- data/lib/utils/url.rb +0 -28
data/lib/utils/request.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('json')
|
4
|
-
require('starkbank-ecdsa')
|
5
|
-
require('net/http')
|
6
|
-
require_relative('url')
|
7
|
-
require_relative('checks')
|
8
|
-
require_relative('../error')
|
9
|
-
|
10
|
-
module StarkInfra
|
11
|
-
module Utils
|
12
|
-
module Request
|
13
|
-
class Response
|
14
|
-
attr_reader :status, :content
|
15
|
-
def initialize(status, content)
|
16
|
-
@status = status
|
17
|
-
@content = content
|
18
|
-
end
|
19
|
-
|
20
|
-
def json
|
21
|
-
JSON.parse(@content)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.fetch(method:, path:, payload: nil, query: nil, user: nil)
|
26
|
-
user = Checks.check_user(user)
|
27
|
-
language = Checks.check_language
|
28
|
-
|
29
|
-
base_url = {
|
30
|
-
Environment::PRODUCTION => 'https://api.starkinfra.com/',
|
31
|
-
Environment::SANDBOX => 'https://sandbox.api.starkinfra.com/'
|
32
|
-
}[user.environment] + 'v2'
|
33
|
-
|
34
|
-
url = "#{base_url}/#{path}#{StarkInfra::Utils::URL.urlencode(query)}"
|
35
|
-
uri = URI(url)
|
36
|
-
|
37
|
-
access_time = Time.now.to_i
|
38
|
-
body = payload.nil? ? '' : payload.to_json
|
39
|
-
message = "#{user.access_id}:#{access_time}:#{body}"
|
40
|
-
signature = EllipticCurve::Ecdsa.sign(message, user.private_key).toBase64
|
41
|
-
|
42
|
-
case method
|
43
|
-
when 'GET'
|
44
|
-
req = Net::HTTP::Get.new(uri)
|
45
|
-
when 'DELETE'
|
46
|
-
req = Net::HTTP::Delete.new(uri)
|
47
|
-
when 'POST'
|
48
|
-
req = Net::HTTP::Post.new(uri)
|
49
|
-
req.body = body
|
50
|
-
when 'PATCH'
|
51
|
-
req = Net::HTTP::Patch.new(uri)
|
52
|
-
req.body = body
|
53
|
-
when 'PUT'
|
54
|
-
req = Net::HTTP::Put.new(uri)
|
55
|
-
req.body = body
|
56
|
-
else
|
57
|
-
raise(ArgumentError, 'unknown HTTP method ' + method)
|
58
|
-
end
|
59
|
-
|
60
|
-
req['Access-Id'] = user.access_id
|
61
|
-
req['Access-Time'] = access_time
|
62
|
-
req['Access-Signature'] = signature
|
63
|
-
req['Content-Type'] = 'application/json'
|
64
|
-
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.4.0"
|
65
|
-
req['Accept-Language'] = language
|
66
|
-
|
67
|
-
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
68
|
-
|
69
|
-
response = Response.new(Integer(request.code, 10), request.body)
|
70
|
-
|
71
|
-
raise(StarkInfra::Error::InternalServerError) if response.status == 500
|
72
|
-
raise(StarkInfra::Error::InputErrors, response.json['errors']) if response.status == 400
|
73
|
-
raise(StarkInfra::Error::UnknownError, response.content) unless response.status == 200
|
74
|
-
|
75
|
-
response
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
data/lib/utils/resource.rb
DELETED
data/lib/utils/returnid.rb
DELETED
data/lib/utils/sub_resource.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module StarkInfra
|
4
|
-
module Utils
|
5
|
-
class SubResource
|
6
|
-
def to_s
|
7
|
-
string_vars = []
|
8
|
-
instance_variables.each do |key|
|
9
|
-
value = instance_variable_get(key).to_s.lines.map(&:chomp).join("\n ")
|
10
|
-
string_vars << "#{key[1..-1]}: #{value}"
|
11
|
-
end
|
12
|
-
fields = string_vars.join(",\n ")
|
13
|
-
"#{class_name}(\n #{fields}\n)"
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
"#{class_name}[#{@id}]"
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def class_name
|
23
|
-
self.class.name.split('::').last.downcase
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/utils/url.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
|
5
|
-
module StarkInfra
|
6
|
-
module Utils
|
7
|
-
module URL
|
8
|
-
# generates query string from hash
|
9
|
-
def self.urlencode(params)
|
10
|
-
return '' if params.nil?
|
11
|
-
|
12
|
-
params = StarkInfra::Utils::API.cast_json_to_api_format(params)
|
13
|
-
return '' if params.empty?
|
14
|
-
|
15
|
-
string_params = {}
|
16
|
-
params.each do |key, value|
|
17
|
-
string_params[key] = value.is_a?(Array) ? value.join(',') : value
|
18
|
-
end
|
19
|
-
|
20
|
-
query_list = []
|
21
|
-
string_params.each do |key, value|
|
22
|
-
query_list << "#{key}=#{ERB::Util.url_encode(value)}"
|
23
|
-
end
|
24
|
-
'?' + query_list.join('&')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|