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/starkinfra.rb CHANGED
@@ -1,74 +1,82 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('key')
4
- require_relative('user/project')
5
- require_relative('user/organization')
6
- require_relative('brcodepreview/brcodepreview')
7
- require_relative('cardmethod/cardmethod')
8
- require_relative('creditnote/invoice/invoice')
9
- require_relative('creditnote/invoice/description')
10
- require_relative('creditnote/invoice/discount')
11
- require_relative('creditnote/creditnote')
12
- require_relative('creditnote/log')
13
- require_relative('creditnote/transfer')
14
- require_relative('creditholmes/creditholmes')
15
- require_relative('creditpreview/creditpreview')
16
- require_relative('creditpreview/creditnotepreview')
17
- require_relative('creditsigner/creditsigner')
18
- require_relative('dynamicbrcode/dynamicbrcode')
19
- require_relative('individualdocument/individualdocument')
20
- require_relative('individualdocument/log')
21
- require_relative('individualidentity/individualidentity')
22
- require_relative('individualidentity/log')
23
- require_relative('issuingbalance/issuingbalance')
24
- require_relative('issuingdesign/issuingdesign')
25
- require_relative('issuingembossingkit/issuingembossingkit')
26
- require_relative('issuingembossingrequest/issuingembossingrequest')
27
- require_relative('issuingembossingrequest/log')
28
- require_relative('issuingstock/issuingstock')
29
- require_relative('issuingstock/log')
30
- require_relative('issuingrestock/issuingrestock')
31
- require_relative('issuingrestock/log')
32
- require_relative('issuingcard/issuingcard')
33
- require_relative('issuingcard/log')
34
- require_relative('issuingholder/issuingholder')
35
- require_relative('issuingholder/log')
36
- require_relative('issuinginvoice/issuinginvoice')
37
- require_relative('issuinginvoice/log')
38
- require_relative('issuingproduct/issuingproduct')
39
- require_relative('issuingpurchase/issuingpurchase')
40
- require_relative('issuingpurchase/log')
41
- require_relative('issuingrule/issuingrule')
42
- require_relative('issuingtransaction/issuingtransaction')
43
- require_relative('issuingwithdrawal/issuingwithdrawal')
44
- require_relative('merchantcategory/merchantcategory')
45
- require_relative('merchantcountry/merchantcountry')
46
- require_relative('pixbalance/pixbalance')
47
- require_relative('pixchargeback/pixchargeback')
48
- require_relative('pixchargeback/log')
49
- require_relative('pixclaim/pixclaim')
50
- require_relative('pixclaim/log')
51
- require_relative('pixdirector/pixdirector')
52
- require_relative('pixdomain/pixdomain')
53
- require_relative('pixinfraction/pixinfraction')
54
- require_relative('pixinfraction/log')
55
- require_relative('pixkey/pixkey')
56
- require_relative('pixkey/log')
57
- require_relative('pixrequest/pixrequest')
58
- require_relative('pixrequest/log')
59
- require_relative('pixreversal/pixreversal')
60
- require_relative('pixreversal/log')
61
- require_relative('pixstatement/pixstatement')
62
- require_relative('staticbrcode/staticbrcode')
3
+ require_relative('brcode_preview/brcode_preview')
4
+ require_relative('card_method/card_method')
5
+ require_relative('credit_note/invoice/invoice')
6
+ require_relative('credit_note/invoice/description')
7
+ require_relative('credit_note/invoice/discount')
8
+ require_relative('credit_note/credit_note')
9
+ require_relative('credit_note/log')
10
+ require_relative('credit_note/transfer')
11
+ require_relative('credit_holmes/credit_holmes')
12
+ require_relative('credit_preview/credit_preview')
13
+ require_relative('credit_preview/credit_note_preview')
14
+ require_relative('credit_signer/credit_signer')
15
+ require_relative('dynamic_brcode/dynamic_brcode')
16
+ require_relative('individual_document/individual_document')
17
+ require_relative('individual_document/log')
18
+ require_relative('individual_identity/individual_identity')
19
+ require_relative('individual_identity/log')
20
+ require_relative('issuing_balance/issuing_balance')
21
+ require_relative('issuing_design/issuing_design')
22
+ require_relative('issuing_embossing_kit/issuing_embossing_kit')
23
+ require_relative('issuing_embossing_request/issuing_embossing_request')
24
+ require_relative('issuing_embossing_request/log')
25
+ require_relative('issuing_stock/issuing_stock')
26
+ require_relative('issuing_stock/log')
27
+ require_relative('issuing_restock/issuing_restock')
28
+ require_relative('issuing_restock/log')
29
+ require_relative('issuing_card/issuing_card')
30
+ require_relative('issuing_card/log')
31
+ require_relative('issuing_holder/issuing_holder')
32
+ require_relative('issuing_holder/log')
33
+ require_relative('issuing_invoice/issuing_invoice')
34
+ require_relative('issuing_invoice/log')
35
+ require_relative('issuing_product/issuing_product')
36
+ require_relative('issuing_purchase/issuing_purchase')
37
+ require_relative('issuing_purchase/log')
38
+ require_relative('issuing_rule/issuing_rule')
39
+ require_relative('issuing_transaction/issuing_transaction')
40
+ require_relative('issuing_withdrawal/issuing_withdrawal')
41
+ require_relative('merchant_category/merchant_category')
42
+ require_relative('merchant_country/merchant_country')
43
+ require_relative('pix_balance/pix_balance')
44
+ require_relative('pix_chargeback/pix_chargeback')
45
+ require_relative('pix_chargeback/log')
46
+ require_relative('pix_claim/pix_claim')
47
+ require_relative('pix_claim/log')
48
+ require_relative('pix_director/pix_director')
49
+ require_relative('pix_domain/pix_domain')
50
+ require_relative('pix_infraction/pix_infraction')
51
+ require_relative('pix_infraction/log')
52
+ require_relative('pix_key/pix_key')
53
+ require_relative('pix_key/log')
54
+ require_relative('pix_request/pix_request')
55
+ require_relative('pix_request/log')
56
+ require_relative('pix_reversal/pix_reversal')
57
+ require_relative('pix_reversal/log')
58
+ require_relative('pix_statement/pix_statement')
59
+ require_relative('static_brcode/static_brcode')
63
60
  require_relative('webhook/webhook')
64
61
  require_relative('event/event')
65
62
  require_relative('event/attempt')
66
- require_relative('utils/endtoendid')
67
- require_relative('utils/returnid')
63
+ require_relative('request/request')
68
64
 
69
65
  # SDK to facilitate Ruby integrations with Stark Infra
70
66
  module StarkInfra
67
+
68
+ API_VERSION = 'v2'
69
+ SDK_VERSION = '0.5.2'
70
+ HOST = "infra"
71
+ public_constant :API_VERSION, :SDK_VERSION, :HOST;
72
+
71
73
  @user = nil
72
74
  @language = 'en-US'
73
- class << self; attr_accessor :user, :language; end
75
+ @timeout = 15
76
+ class << self; attr_accessor :user, :language, :timeout; end
77
+
78
+ Project = StarkCore::Project
79
+ Organization = StarkCore::Organization
80
+ Key = StarkCore::Key
81
+
74
82
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require('starkcore')
3
4
  require_relative('../utils/rest')
4
5
  require_relative('../utils/parse')
5
- require_relative('../utils/checks')
6
- require_relative('../utils/resource')
7
6
 
8
7
  module StarkInfra
9
8
  # # StaticBrcode object
@@ -33,7 +32,7 @@ module StarkInfra
33
32
  # - url [string]: url link to the BR Code image. ex: 'https://brcode-h.development.starkinfra.com/static-qrcode/97756273400d42ce9086404fe10ea0d6.png'
34
33
  # - created [DateTime]: creation datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
35
34
  # - updated [DateTime]: latest update datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
36
- class StaticBrcode < StarkInfra::Utils::Resource
35
+ class StaticBrcode < StarkCore::Utils::Resource
37
36
  attr_reader :name, :key_id, :city, :amount, :cashier_bank_code, :description, :reconciliation_id, :id, :tags, :uuid, :url, :created, :updated
38
37
  def initialize(
39
38
  name:, key_id:, city:, amount:, cashier_bank_code: nil, description: nil, reconciliation_id: nil, id: nil, tags:nil, uuid: nil, url: nil, created: nil, updated: nil
@@ -49,8 +48,8 @@ module StarkInfra
49
48
  @tags = tags
50
49
  @uuid = uuid
51
50
  @url = url
52
- @created = StarkInfra::Utils::Checks.check_datetime(created)
53
- @updated = StarkInfra::Utils::Checks.check_datetime(updated)
51
+ @created = StarkCore::Utils::Checks.check_datetime(created)
52
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
54
53
  end
55
54
 
56
55
  # # Create StaticBrcodes
@@ -100,8 +99,8 @@ module StarkInfra
100
99
  # ## Return:
101
100
  # - generator of StaticBrcode objects with updated attributes
102
101
  def self.query(limit: nil, after: nil, before: nil, uuids: nil, tags: nil, user: nil)
103
- after = StarkInfra::Utils::Checks.check_date(after)
104
- before = StarkInfra::Utils::Checks.check_date(before)
102
+ after = StarkCore::Utils::Checks.check_date(after)
103
+ before = StarkCore::Utils::Checks.check_date(before)
105
104
  StarkInfra::Utils::Rest.get_stream(
106
105
  limit: limit,
107
106
  after: after,
@@ -130,8 +129,8 @@ module StarkInfra
130
129
  # - list of StaticBrcode objects with updated attributes
131
130
  # - cursor to retrieve the next page of StaticBrcode objects
132
131
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil)
133
- after = StarkInfra::Utils::Checks.check_date(after)
134
- before = StarkInfra::Utils::Checks.check_date(before)
132
+ after = StarkCore::Utils::Checks.check_date(after)
133
+ before = StarkCore::Utils::Checks.check_date(before)
135
134
  StarkInfra::Utils::Rest.get_page(
136
135
  cursor: cursor,
137
136
  limit: limit,
data/lib/utils/parse.rb CHANGED
@@ -1,53 +1,34 @@
1
- # frozen_string_literal: true
2
-
3
- require('json')
4
- require('starkbank-ecdsa')
5
- require_relative('api')
6
- require_relative('cache')
7
- require_relative('request')
8
- require_relative('../error')
1
+ require('starkcore')
9
2
 
10
3
  module StarkInfra
11
4
  module Utils
12
5
  module Parse
13
6
  def self.parse_and_verify(content:, signature:, user: nil, resource:, key: nil)
14
- content = verify(content:content, signature: signature, user: user)
15
- json = JSON.parse(content)
16
- json = JSON.parse(content)[key] unless key.nil?
17
-
18
- StarkInfra::Utils::API.from_api_json(resource[:resource_maker], json)
7
+ return StarkCore::Utils::Parse.parse_and_verify(
8
+ content: content,
9
+ signature: signature,
10
+ sdk_version: StarkInfra::SDK_VERSION,
11
+ api_version: StarkInfra::API_VERSION,
12
+ host: StarkInfra::HOST,
13
+ resource: resource,
14
+ user: user ? user : StarkInfra.user,
15
+ language: StarkInfra.language,
16
+ timeout: StarkInfra.timeout,
17
+ key: key
18
+ )
19
19
  end
20
20
 
21
21
  def self.verify(content:, signature:, user: nil)
22
- begin
23
- signature = EllipticCurve::Signature.fromBase64(signature)
24
- rescue
25
- raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature is not valid')
26
- end
27
-
28
- if verify_signature(content: content, signature: signature, user: user)
29
- return content
30
- end
31
-
32
- if verify_signature(content: content, signature: signature, user: user, refresh: true)
33
- return content
34
- end
35
-
36
- raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Infra public key')
37
- end
38
-
39
- def self.verify_signature(content:, signature:, user:, refresh: false)
40
- public_key = StarkInfra::Utils::Cache.starkinfra_public_key
41
- if public_key.nil? || refresh
42
- pem = get_public_key_pem(user)
43
- public_key = EllipticCurve::PublicKey.fromPem(pem)
44
- StarkInfra::Utils::Cache.starkinfra_public_key = public_key
45
- end
46
- EllipticCurve::Ecdsa.verify(content, signature, public_key)
47
- end
48
-
49
- def self.get_public_key_pem(user)
50
- StarkInfra::Utils::Request.fetch(method: 'GET', path: 'public-key', query: { limit: 1 }, user: user).json['publicKeys'][0]['content']
22
+ return StarkCore::Utils::Parse.verify(
23
+ content: content,
24
+ signature: signature,
25
+ sdk_version: StarkInfra::SDK_VERSION,
26
+ api_version: StarkInfra::API_VERSION,
27
+ host: StarkInfra::HOST,
28
+ user: user ? user : StarkInfra.user,
29
+ language: StarkInfra.language,
30
+ timeout: StarkInfra.timeout
31
+ )
51
32
  end
52
33
  end
53
34
  end
data/lib/utils/rest.rb CHANGED
@@ -1,136 +1,237 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('request')
4
- require_relative('api')
3
+ require('starkcore')
5
4
 
6
5
  module StarkInfra
7
6
  module Utils
8
7
  module Rest
9
- def self.get_page(resource_name:, resource_maker:, user: nil, **query)
10
- json = StarkInfra::Utils::Request.fetch(
11
- method: 'GET',
12
- path: StarkInfra::Utils::API.endpoint(resource_name),
13
- query: query,
14
- user: user
15
- ).json
16
- entities = []
17
- json[StarkInfra::Utils::API.last_name_plural(resource_name)].each do |entity_json|
18
- entities << StarkInfra::Utils::API.from_api_json(resource_maker, entity_json)
19
- end
20
- return entities, json['cursor']
8
+
9
+ def self.get_page(resource_name:, resource_maker:, user:, **query)
10
+ return StarkCore::Utils::Rest.get_page(
11
+ resource_name: resource_name,
12
+ resource_maker: resource_maker,
13
+ sdk_version: StarkInfra::SDK_VERSION,
14
+ host: StarkInfra::HOST,
15
+ api_version: StarkInfra::API_VERSION,
16
+ user: user ? user : StarkInfra.user,
17
+ language: StarkInfra.language,
18
+ timeout: StarkInfra.timeout,
19
+ **query
20
+ )
21
21
  end
22
22
 
23
- def self.get_stream(resource_name:, resource_maker:, user: nil, **query)
24
- limit = query[:limit]
25
- query[:limit] = limit.nil? ? limit : [limit, 100].min
26
-
27
- Enumerator.new do |enum|
28
- loop do
29
- json = StarkInfra::Utils::Request.fetch(
30
- method: 'GET',
31
- path: StarkInfra::Utils::API.endpoint(resource_name),
32
- query: query,
33
- user: user
34
- ).json
35
- entities = json[StarkInfra::Utils::API.last_name_plural(resource_name)]
36
-
37
- entities.each do |entity|
38
- enum << StarkInfra::Utils::API.from_api_json(resource_maker, entity)
39
- end
40
-
41
- unless limit.nil?
42
- limit -= 100
43
- query[:limit] = [limit, 100].min
44
- end
45
-
46
- cursor = json['cursor']
47
- query['cursor'] = cursor
48
- break if cursor.nil? || cursor.empty? || (!limit.nil? && limit <= 0)
49
- end
50
- end
23
+ def self.get_stream(resource_name:, resource_maker:, user:, **query)
24
+ return StarkCore::Utils::Rest.get_stream(
25
+ resource_name: resource_name,
26
+ resource_maker: resource_maker,
27
+ sdk_version: StarkInfra::SDK_VERSION,
28
+ host: StarkInfra::HOST,
29
+ api_version: StarkInfra::API_VERSION,
30
+ user: user ? user : StarkInfra.user,
31
+ language: StarkInfra.language,
32
+ timeout: StarkInfra.timeout,
33
+ **query
34
+ )
51
35
  end
52
36
 
53
- def self.get_id(resource_name:, resource_maker:, id:, user: nil, **query)
54
- json = StarkInfra::Utils::Request.fetch(
55
- method: 'GET',
56
- path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}",
57
- query: query,
58
- user: user
59
- ).json
60
- entity = json[StarkInfra::Utils::API.last_name(resource_name)]
61
- StarkInfra::Utils::API.from_api_json(resource_maker, entity)
37
+ def self.get_id(resource_name:, resource_maker:, user:, id:, **query)
38
+ return StarkCore::Utils::Rest.get_id(
39
+ resource_name: resource_name,
40
+ resource_maker: resource_maker,
41
+ sdk_version: StarkInfra::SDK_VERSION,
42
+ host: StarkInfra::HOST,
43
+ api_version: StarkInfra::API_VERSION,
44
+ user: user ? user : StarkInfra.user,
45
+ language: StarkInfra.language,
46
+ timeout: StarkInfra.timeout,
47
+ id: id,
48
+ **query
49
+ )
62
50
  end
63
51
 
64
- def self.get_content(resource_name:, sub_resource_name:, id:, user: nil)
65
- StarkInfra::Utils::Request.fetch(
66
- method: 'GET',
67
- path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{sub_resource_name}",
68
- user: user
69
- ).content
52
+ def self.get_content(resource_name:, resource_maker:, user:, sub_resource_name:, id:, **query)
53
+ return StarkCore::Utils::Rest.get_content(
54
+ resource_name: resource_name,
55
+ resource_maker: resource_maker,
56
+ sdk_version: StarkInfra::SDK_VERSION,
57
+ host: StarkInfra::HOST,
58
+ api_version: StarkInfra::API_VERSION,
59
+ user: user ? user : StarkInfra.user,
60
+ language: StarkInfra.language,
61
+ timeout: StarkInfra.timeout,
62
+ sub_resource_name: sub_resource_name,
63
+ id: id,
64
+ **query
65
+ )
70
66
  end
71
67
 
72
- def self.post(resource_name:, resource_maker:, entities:, user: nil, **query)
73
- jsons = []
74
- entities.each do |entity|
75
- jsons << StarkInfra::Utils::API.api_json(entity)
76
- end
77
- payload = { StarkInfra::Utils::API.last_name_plural(resource_name) => jsons }
78
- json = StarkInfra::Utils::Request.fetch(
79
- method: 'POST',
80
- path: StarkInfra::Utils::API.endpoint(resource_name),
81
- payload: payload,
82
- query: query,
83
- user: user
84
- ).json
85
- returned_jsons = json[StarkInfra::Utils::API.last_name_plural(resource_name)]
86
- entities = []
87
- returned_jsons.each do |returned_json|
88
- entities << StarkInfra::Utils::API.from_api_json(resource_maker, returned_json)
89
- end
90
- entities
68
+ def self.get_sub_resource(resource_name:, sub_resource_maker:, sub_resource_name:, user:, id:, **query)
69
+ return StarkCore::Utils::Rest.get_sub_resource(
70
+ resource_name: resource_name,
71
+ sub_resource_maker: sub_resource_maker,
72
+ sub_resource_name: sub_resource_name,
73
+ sdk_version: StarkInfra::SDK_VERSION,
74
+ host: StarkInfra::HOST,
75
+ api_version: StarkInfra::API_VERSION,
76
+ user: user ? user : StarkInfra.user,
77
+ language: StarkInfra.language,
78
+ timeout: StarkInfra.timeout,
79
+ id: id,
80
+ **query
81
+ )
82
+ end
83
+
84
+ def self.get_sub_resources(resource_name:, sub_resource_maker:, sub_resource_name:, user:, id:, **query)
85
+ return StarkCore::Utils::Rest.get_sub_resource(
86
+ resource_name: resource_name,
87
+ sub_resource_maker: sub_resource_maker,
88
+ sub_resource_name: sub_resource_name,
89
+ sdk_version: StarkInfra::SDK_VERSION,
90
+ host: StarkInfra::HOST,
91
+ api_version: StarkInfra::API_VERSION,
92
+ user: user ? user : StarkInfra.user,
93
+ language: StarkInfra.language,
94
+ timeout: StarkInfra.timeout,
95
+ id: id,
96
+ **query
97
+ )
91
98
  end
92
99
 
93
- def self.post_single(resource_name:, resource_maker:, entity:, user: nil)
94
- json = StarkInfra::Utils::Request.fetch(
95
- method: 'POST',
96
- path: StarkInfra::Utils::API.endpoint(resource_name),
97
- payload: StarkInfra::Utils::API.api_json(entity),
98
- user: user
99
- ).json
100
- entity_json = json[StarkInfra::Utils::API.last_name(resource_name)]
101
- StarkInfra::Utils::API.from_api_json(resource_maker, entity_json)
100
+ def self.post(resource_name:, resource_maker:, user:, entities:, **query)
101
+ return StarkCore::Utils::Rest.post(
102
+ resource_name: resource_name,
103
+ resource_maker: resource_maker,
104
+ sdk_version: StarkInfra::SDK_VERSION,
105
+ host: StarkInfra::HOST,
106
+ api_version: StarkInfra::API_VERSION,
107
+ user: user ? user : StarkInfra.user,
108
+ language: StarkInfra.language,
109
+ timeout: StarkInfra.timeout,
110
+ entities: entities,
111
+ **query
112
+ )
102
113
  end
103
114
 
104
- def self.delete_id(resource_name:, resource_maker:, id:, user: nil)
105
- json = StarkInfra::Utils::Request.fetch(
106
- method: 'DELETE',
107
- path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}",
108
- user: user
109
- ).json
110
- entity = json[StarkInfra::Utils::API.last_name(resource_name)]
111
- StarkInfra::Utils::API.from_api_json(resource_maker, entity)
115
+ def self.post_single(resource_name:, resource_maker:, user:, entity:)
116
+ return StarkCore::Utils::Rest.post_single(
117
+ resource_name: resource_name,
118
+ resource_maker: resource_maker,
119
+ sdk_version: StarkInfra::SDK_VERSION,
120
+ host: StarkInfra::HOST,
121
+ api_version: StarkInfra::API_VERSION,
122
+ user: user ? user : StarkInfra.user,
123
+ language: StarkInfra.language,
124
+ timeout: StarkInfra.timeout,
125
+ entity: entity
126
+ )
112
127
  end
113
128
 
114
- def self.patch_id(resource_name:, resource_maker:, id:, user: nil, **payload)
115
- json = StarkInfra::Utils::Request.fetch(
116
- method: 'PATCH',
117
- path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}",
118
- user: user,
119
- payload: StarkInfra::Utils::API.cast_json_to_api_format(payload)
120
- ).json
121
- entity = json[StarkInfra::Utils::API.last_name(resource_name)]
122
- StarkInfra::Utils::API.from_api_json(resource_maker, entity)
129
+ def self.delete_id(resource_name:, resource_maker:, user:, id:)
130
+ return StarkCore::Utils::Rest.delete_id(
131
+ resource_name: resource_name,
132
+ resource_maker: resource_maker,
133
+ sdk_version: StarkInfra::SDK_VERSION,
134
+ host: StarkInfra::HOST,
135
+ api_version: StarkInfra::API_VERSION,
136
+ user: user ? user : StarkInfra.user,
137
+ language: StarkInfra.language,
138
+ timeout: StarkInfra.timeout,
139
+ id: id
140
+ )
123
141
  end
124
142
 
125
- def self.get_sub_resource(resource_name:, sub_resource_maker:, sub_resource_name:, id:, user: nil, **query)
126
- json = StarkInfra::Utils::Request.fetch(
127
- method: 'GET',
128
- path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{StarkInfra::Utils::API.endpoint(sub_resource_name)}",
129
- user: user,
143
+ def self.patch_id(resource_name:, resource_maker:, user:, id:, **payload)
144
+ return StarkCore::Utils::Rest.patch_id(
145
+ resource_name: resource_name,
146
+ resource_maker: resource_maker,
147
+ sdk_version: StarkInfra::SDK_VERSION,
148
+ host: StarkInfra::HOST,
149
+ api_version: StarkInfra::API_VERSION,
150
+ user: user ? user : StarkInfra.user,
151
+ language: StarkInfra.language,
152
+ timeout: StarkInfra.timeout,
153
+ id: id,
154
+ **payload
155
+ )
156
+ end
157
+
158
+ def self.get_raw(path:, prefix: nil, raiseException: nil, user: nil, query: nil)
159
+ return StarkCore::Utils::Rest.get_raw(
160
+ host: StarkInfra::HOST,
161
+ sdk_version: StarkInfra::SDK_VERSION,
162
+ user: user ? user : StarkInfra.user,
163
+ path: path,
164
+ api_version: StarkInfra::API_VERSION,
165
+ language: StarkInfra.language,
166
+ timeout: StarkInfra.timeout,
167
+ prefix: prefix,
168
+ raiseException: raiseException,
130
169
  query: query
131
- ).json
132
- entity = json[StarkInfra::Utils::API.last_name(sub_resource_name)]
133
- StarkInfra::Utils::API.from_api_json(sub_resource_maker, entity)
170
+ )
171
+ end
172
+
173
+ def self.post_raw(path:, payload:, query: nil, prefix: nil, raiseException: nil, user:)
174
+
175
+ return StarkCore::Utils::Rest.post_raw(
176
+ host: StarkInfra::HOST,
177
+ sdk_version: StarkInfra::SDK_VERSION,
178
+ user: user ? user : StarkInfra.user,
179
+ path: path,
180
+ payload: payload,
181
+ api_version: StarkInfra::API_VERSION,
182
+ language: StarkInfra.language,
183
+ timeout: StarkInfra.timeout,
184
+ query: query,
185
+ prefix: prefix,
186
+ raiseException: raiseException
187
+ )
188
+ end
189
+
190
+ def self.patch_raw(path:, payload:, query: nil, prefix: nil, raiseException: nil, user: nil)
191
+ return StarkCore::Utils::Rest.patch_raw(
192
+ host: StarkInfra::HOST,
193
+ sdk_version: StarkInfra::SDK_VERSION,
194
+ user: user ? user : StarkInfra.user,
195
+ path: path,
196
+ payload: payload,
197
+ api_version: StarkInfra::API_VERSION,
198
+ language: StarkInfra.language,
199
+ timeout: StarkInfra.timeout,
200
+ query: query,
201
+ prefix: prefix,
202
+ raiseException: raiseException
203
+ )
204
+ end
205
+
206
+ def self.put_raw(path:, payload:, query: nil, prefix: nil, raiseException: nil, user: nil)
207
+ return StarkCore::Utils::Rest.put_raw(
208
+ host: StarkInfra::HOST,
209
+ sdk_version: StarkInfra::SDK_VERSION,
210
+ user: user ? user : StarkInfra.user,
211
+ path: path,
212
+ payload: payload,
213
+ api_version: StarkInfra::API_VERSION,
214
+ language: StarkInfra.language,
215
+ timeout: StarkInfra.timeout,
216
+ query: query,
217
+ prefix: prefix,
218
+ raiseException: raiseException
219
+ )
220
+ end
221
+
222
+ def self.delete_raw(path:, query: nil, prefix: nil, raiseException: nil, user: nil)
223
+ return StarkCore::Utils::Rest.delete_raw(
224
+ host: StarkInfra::HOST,
225
+ sdk_version: StarkInfra::SDK_VERSION,
226
+ user: user ? user : StarkInfra.user,
227
+ path: path,
228
+ api_version: StarkInfra::API_VERSION,
229
+ language: StarkInfra.language,
230
+ timeout: StarkInfra.timeout,
231
+ query: query,
232
+ prefix: prefix,
233
+ raiseException: raiseException
234
+ )
134
235
  end
135
236
  end
136
237
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require('starkcore')
3
4
  require_relative('../utils/rest')
4
- require_relative('../utils/checks')
5
- require_relative('../utils/resource')
6
5
 
7
6
  module StarkInfra
8
7
  # # Webhook object
@@ -16,7 +15,7 @@ module StarkInfra
16
15
  #
17
16
  # ## Attributes (return-only):
18
17
  # - id [string]: unique id returned when the webhook is created. ex: '5656565656565656'
19
- class Webhook < StarkInfra::Utils::Resource
18
+ class Webhook < StarkCore::Utils::Resource
20
19
  attr_reader :url, :subscriptions, :id
21
20
  def initialize(url:, subscriptions:, id: nil)
22
21
  super(id)