starkinfra 0.4.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/lib/{brcodepreview/brcodepreview.rb → brcode_preview/brcode_preview.rb} +2 -5
  3. data/lib/{cardmethod/cardmethod.rb → card_method/card_method.rb} +2 -2
  4. data/lib/{creditholmes/creditholmes.rb → credit_holmes/credit_holmes.rb} +8 -11
  5. data/lib/{creditnote/creditnote.rb → credit_note/credit_note.rb} +11 -12
  6. data/lib/{creditnote → credit_note}/invoice/description.rb +3 -5
  7. data/lib/{creditnote → credit_note}/invoice/discount.rb +3 -4
  8. data/lib/{creditnote → credit_note}/invoice/invoice.rb +5 -6
  9. data/lib/{creditnote → credit_note}/log.rb +9 -10
  10. data/lib/{creditnote → credit_note}/transfer.rb +4 -5
  11. data/lib/{creditpreview/creditnotepreview.rb → credit_preview/credit_note_preview.rb} +2 -3
  12. data/lib/{creditpreview/creditpreview.rb → credit_preview/credit_preview.rb} +3 -4
  13. data/lib/{creditsigner/creditsigner.rb → credit_signer/credit_signer.rb} +3 -6
  14. data/lib/{dynamicbrcode/dynamicbrcode.rb → dynamic_brcode/dynamic_brcode.rb} +17 -19
  15. data/lib/error.rb +7 -40
  16. data/lib/event/attempt.rb +7 -8
  17. data/lib/event/event.rb +10 -13
  18. data/lib/{individualdocument/individualdocument.rb → individual_document/individual_document.rb} +7 -8
  19. data/lib/{individualdocument → individual_document}/log.rb +9 -10
  20. data/lib/{individualidentity/individualidentity.rb → individual_identity/individual_identity.rb} +7 -8
  21. data/lib/{individualidentity → individual_identity}/log.rb +9 -10
  22. data/lib/{issuingbalance/issuingbalance.rb → issuing_balance/issuing_balance.rb} +2 -3
  23. data/lib/{issuingcard/issuingcard.rb → issuing_card/issuing_card.rb} +9 -10
  24. data/lib/{issuingcard → issuing_card}/log.rb +9 -10
  25. data/lib/{issuingdesign/issuingdesign.rb → issuing_design/issuing_design.rb} +5 -6
  26. data/lib/{issuingembossingkit/issuingembossingkit.rb → issuing_embossing_kit/issuing_embossing_kit.rb} +4 -5
  27. data/lib/{issuingembossingrequest/issuingembossingrequest.rb → issuing_embossing_request/issuing_embossing_request.rb} +8 -9
  28. data/lib/{issuingembossingrequest → issuing_embossing_request}/log.rb +9 -10
  29. data/lib/{issuingholder/issuingholder.rb → issuing_holder/issuing_holder.rb} +9 -10
  30. data/lib/{issuingholder → issuing_holder}/log.rb +9 -10
  31. data/lib/{issuinginvoice/issuinginvoice.rb → issuing_invoice/issuing_invoice.rb} +8 -9
  32. data/lib/{issuinginvoice → issuing_invoice}/log.rb +9 -10
  33. data/lib/{issuingproduct/issuingproduct.rb → issuing_product/issuing_product.rb} +3 -4
  34. data/lib/{issuingpurchase/issuingpurchase.rb → issuing_purchase/issuing_purchase.rb} +32 -24
  35. data/lib/{issuingpurchase → issuing_purchase}/log.rb +9 -10
  36. data/lib/{issuingrestock/issuingrestock.rb → issuing_restock/issuing_restock.rb} +8 -9
  37. data/lib/{issuingrestock → issuing_restock}/log.rb +9 -10
  38. data/lib/{issuingrule/issuingrule.rb → issuing_rule/issuing_rule.rb} +6 -7
  39. data/lib/{issuingstock/issuingstock.rb → issuing_stock/issuing_stock.rb} +8 -9
  40. data/lib/{issuingstock → issuing_stock}/log.rb +9 -10
  41. data/lib/{issuingtransaction/issuingtransaction.rb → issuing_transaction/issuing_transaction.rb} +7 -8
  42. data/lib/{issuingwithdrawal/issuingwithdrawal.rb → issuing_withdrawal/issuing_withdrawal.rb} +8 -9
  43. data/lib/{merchantcategory/merchantcategory.rb → merchant_category/merchant_category.rb} +2 -2
  44. data/lib/{merchantcountry/merchantcountry.rb → merchant_country/merchant_country.rb} +2 -2
  45. data/lib/{pixbalance/pixbalance.rb → pix_balance/pix_balance.rb} +2 -3
  46. data/lib/{pixchargeback → pix_chargeback}/log.rb +9 -10
  47. data/lib/{pixchargeback/pixchargeback.rb → pix_chargeback/pix_chargeback.rb} +8 -9
  48. data/lib/{pixclaim → pix_claim}/log.rb +9 -10
  49. data/lib/{pixclaim/pixclaim.rb → pix_claim/pix_claim.rb} +8 -9
  50. data/lib/{pixdirector/pixdirector.rb → pix_director/pix_director.rb} +2 -2
  51. data/lib/{pixdomain → pix_domain}/certificate.rb +2 -2
  52. data/lib/{pixdomain/pixdomain.rb → pix_domain/pix_domain.rb} +3 -3
  53. data/lib/{pixinfraction → pix_infraction}/log.rb +9 -10
  54. data/lib/{pixinfraction/pixinfraction.rb → pix_infraction/pix_infraction.rb} +8 -9
  55. data/lib/{pixkey → pix_key}/log.rb +9 -10
  56. data/lib/{pixkey/pixkey.rb → pix_key/pix_key.rb} +8 -9
  57. data/lib/{pixrequest → pix_request}/log.rb +9 -10
  58. data/lib/{pixrequest/pixrequest.rb → pix_request/pix_request.rb} +9 -10
  59. data/lib/{pixreversal → pix_reversal}/log.rb +8 -10
  60. data/lib/{pixreversal/pixreversal.rb → pix_reversal/pix_reversal.rb} +9 -10
  61. data/lib/{pixstatement/pixstatement.rb → pix_statement/pix_statement.rb} +6 -7
  62. data/lib/request/request.rb +152 -0
  63. data/lib/starkinfra.rb +71 -63
  64. data/lib/{staticbrcode/staticbrcode.rb → static_brcode/static_brcode.rb} +8 -9
  65. data/lib/utils/parse.rb +23 -42
  66. data/lib/utils/rest.rb +211 -110
  67. data/lib/webhook/webhook.rb +2 -3
  68. metadata +70 -85
  69. data/lib/key.rb +0 -33
  70. data/lib/user/organization.rb +0 -54
  71. data/lib/user/project.rb +0 -37
  72. data/lib/user/user.rb +0 -20
  73. data/lib/utils/api.rb +0 -89
  74. data/lib/utils/bacenid.rb +0 -19
  75. data/lib/utils/cache.rb +0 -10
  76. data/lib/utils/case.rb +0 -21
  77. data/lib/utils/checks.rb +0 -100
  78. data/lib/utils/endtoendid.rb +0 -11
  79. data/lib/utils/environment.rb +0 -14
  80. data/lib/utils/request.rb +0 -79
  81. data/lib/utils/resource.rb +0 -13
  82. data/lib/utils/returnid.rb +0 -11
  83. data/lib/utils/sub_resource.rb +0 -27
  84. 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
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative('sub_resource')
3
-
4
- module StarkInfra
5
- module Utils
6
- class Resource < StarkInfra::Utils::SubResource
7
- attr_reader :id
8
- def initialize(id = nil)
9
- @id = id
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- require_relative('bacenid')
4
-
5
- module StarkInfra
6
- module ReturnId
7
- def self.create(bank_code)
8
- 'D' << StarkInfra::Utils::BacenId._create(bank_code)
9
- end
10
- end
11
- end
@@ -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