starkbank 2.1.0.beta2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,20 +5,21 @@ require_relative('user')
5
5
  module StarkBank
6
6
  # # Project object
7
7
  #
8
- # The Project object is the main authentication entity for the SDK.
9
- # All requests to the Stark Bank API must be authenticated via a project,
8
+ # The Project object is an authentication entity for the SDK that is permanently
9
+ # linked to a specific Workspace.
10
+ # All requests to the Stark Bank API must be authenticated via an SDK user,
10
11
  # which must have been previously created at the Stark Bank website
11
12
  # [https://sandbox.web.starkbank.com] or [https://web.starkbank.com]
12
- # before you can use it in this SDK. Projects may be passed as a parameter on
13
+ # before you can use it in this SDK. Projects may be passed as the user parameter on
13
14
  # each request or may be defined as the default user at the start (See README).
14
15
  #
15
16
  # ## Parameters (required):
16
17
  # - id [string]: unique id required to identify project. ex: '5656565656565656'
17
- # - private_key [EllipticCurve.Project()]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
18
+ # - private_key [string]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
18
19
  # - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
19
20
  #
20
21
  # ## Attributes (return-only):
21
- # - name [string, default ']: project name. ex: 'MyProject'
22
+ # - name [string, default '']: project name. ex: 'MyProject'
22
23
  # - allowed_ips [list of strings]: list containing the strings of the ips allowed to make requests on behalf of this project. ex: ['190.190.0.50']
23
24
  # - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
24
25
  class Project < StarkBank::User
@@ -28,5 +29,9 @@ module StarkBank
28
29
  @name = name
29
30
  @allowed_ips = allowed_ips
30
31
  end
32
+
33
+ def access_id
34
+ "project/#{@id}"
35
+ end
31
36
  end
32
37
  end
@@ -13,10 +13,6 @@ module StarkBank
13
13
  @environment = StarkBank::Utils::Checks.check_environment(environment)
14
14
  end
15
15
 
16
- def access_id
17
- "#{self.class.name.split('::').last.downcase}/#{@id}"
18
- end
19
-
20
16
  def private_key
21
17
  EllipticCurve::PrivateKey.fromPem(@pem)
22
18
  end
@@ -37,7 +37,7 @@ module StarkBank
37
37
  # - id [string]: object unique id. ex: '5656565656565656'
38
38
  #
39
39
  # ## Parameters (optional):
40
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
40
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
41
41
  #
42
42
  # ## Return:
43
43
  # - Log object with updated attributes
@@ -55,7 +55,7 @@ module StarkBank
55
55
  # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
56
56
  # - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'paid' or 'registered'
57
57
  # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
58
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
58
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
59
59
  #
60
60
  # ## Return:
61
61
  # - list of Log objects with updated attributes
@@ -51,7 +51,7 @@ module StarkBank
51
51
  # - payments [list of UtilityPayment objects]: list of UtilityPayment objects to be created in the API
52
52
  #
53
53
  # ## Parameters (optional):
54
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
54
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
55
55
  #
56
56
  # ## Return:
57
57
  # - list of UtilityPayment objects with updated attributes
@@ -67,7 +67,7 @@ module StarkBank
67
67
  # - id [string]: object unique id. ex: '5656565656565656'
68
68
  #
69
69
  # ## Parameters (optional):
70
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
70
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
71
71
  #
72
72
  # ## Return:
73
73
  # - UtilityPayment object with updated attributes
@@ -84,7 +84,7 @@ module StarkBank
84
84
  # - id [string]: object unique id. ex: '5656565656565656'
85
85
  #
86
86
  # ## Parameters (optional):
87
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
87
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
88
88
  #
89
89
  # ## Return:
90
90
  # - UtilityPayment pdf file
@@ -103,7 +103,7 @@ module StarkBank
103
103
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
104
104
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
105
105
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
106
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
106
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
107
107
  #
108
108
  # ## Return:
109
109
  # - generator of UtilityPayment objects with updated attributes
@@ -130,7 +130,7 @@ module StarkBank
130
130
  # - id [string]: UtilityPayment unique id. ex:'5656565656565656'
131
131
  #
132
132
  # ## Parameters (optional):
133
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
133
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
134
134
  #
135
135
  # ## Return:
136
136
  # - deleted UtilityPayment object
@@ -61,7 +61,13 @@ module StarkBank
61
61
  end
62
62
 
63
63
  def self.last_name_plural(resource_name)
64
- "#{last_name(resource_name)}s"
64
+ base = last_name(resource_name)
65
+
66
+ return base if base[-1].eql?('s')
67
+ return "#{base}s" if base[-2..-1].eql?('ey')
68
+ return "#{base[0...-1]}ies" if base[-1].eql?('y')
69
+
70
+ "#{base}s"
65
71
  end
66
72
 
67
73
  def self.last_name(resource_name)
@@ -39,6 +39,17 @@ module StarkBank
39
39
  raise(ArgumentError, 'Private-key must be a valid secp256k1 ECDSA string in pem format')
40
40
  end
41
41
 
42
+ def self.check_date_or_datetime(data)
43
+ return if data.nil?
44
+
45
+ return data if data.is_a?(Time) || data.is_a?(DateTime)
46
+
47
+ return data if data.is_a?(Date)
48
+
49
+ data, type = check_datetime_string(data)
50
+ type == 'date' ? Date.new(data.year, data.month, data.day) : data
51
+ end
52
+
42
53
  def self.check_datetime(data)
43
54
  return if data.nil?
44
55
 
@@ -61,7 +61,7 @@ module StarkBank
61
61
  req['Access-Time'] = access_time
62
62
  req['Access-Signature'] = signature
63
63
  req['Content-Type'] = 'application/json'
64
- req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.1.0.beta2"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.3.0"
65
65
  req['Accept-Language'] = language
66
66
 
67
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
@@ -31,8 +31,7 @@ module StarkBank
31
31
 
32
32
  cursor = json['cursor']
33
33
  query['cursor'] = cursor
34
-
35
- break if cursor.nil? || (!limit.nil? && limit <= 0)
34
+ break if cursor.nil? || cursor.empty? || (!limit.nil? && limit <= 0)
36
35
  end
37
36
  end
38
37
  end
@@ -56,6 +55,15 @@ module StarkBank
56
55
  ).content
57
56
  end
58
57
 
58
+ def self.get_qrcode(resource_name:, resource_maker:, id:, user: nil, **query)
59
+ StarkBank::Utils::Request.fetch(
60
+ method: 'GET',
61
+ path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/qrcode",
62
+ query: StarkBank::Utils::API.cast_json_to_api_format(query),
63
+ user: user
64
+ ).content
65
+ end
66
+
59
67
  def self.post(resource_name:, resource_maker:, entities:, user: nil)
60
68
  jsons = []
61
69
  entities.each do |entity|
@@ -8,12 +8,12 @@ module StarkBank
8
8
  # # Webhook subscription object
9
9
  #
10
10
  # A Webhook is used to subscribe to notification events on a user-selected endpoint.
11
- # Currently available services for subscription are transfer, boleto, boleto-payment,
12
- # and utility-payment
11
+ # Currently available services for subscription are transfer, invoice, deposit, brcode-payment,
12
+ # boleto, boleto-payment and utility-payment
13
13
  #
14
14
  # ## Parameters (required):
15
15
  # - url [string]: Url that will be notified when an event occurs.
16
- # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'boleto-payment']
16
+ # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'deposit']
17
17
  #
18
18
  # ## Attributes:
19
19
  # - id [string, default nil]: unique id returned when the webhook is created. ex: '5656565656565656'
@@ -31,10 +31,10 @@ module StarkBank
31
31
  #
32
32
  # ## Parameters (required):
33
33
  # - url [string]: url to which notification events will be sent to. ex: 'https://webhook.site/60e9c18e-4b5c-4369-bda1-ab5fcd8e1b29'
34
- # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'boleto-payment']
34
+ # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'invoice']
35
35
  #
36
36
  # ## Parameters (optional):
37
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
37
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
38
38
  #
39
39
  # ## Return:
40
40
  # - Webhook object with updated attributes
@@ -50,7 +50,7 @@ module StarkBank
50
50
  # - id [string]: object unique id. ex: '5656565656565656'
51
51
  #
52
52
  # ## Parameters (optional):
53
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
53
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
54
54
  #
55
55
  # ## Return:
56
56
  # - Webhook object with updated attributes
@@ -64,7 +64,7 @@ module StarkBank
64
64
  #
65
65
  # ## Parameters (optional):
66
66
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
67
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
67
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
68
68
  #
69
69
  # ## Return:
70
70
  # - generator of Webhook objects with updated attributes
@@ -80,7 +80,7 @@ module StarkBank
80
80
  # - id [string]: Webhook unique id. ex: '5656565656565656'
81
81
  #
82
82
  # ## Parameters (optional):
83
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
83
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
84
84
  #
85
85
  # ## Return:
86
86
  # - deleted Webhook object
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ # # Workspace object
9
+ #
10
+ # Workspaces are bank accounts. They have independent balances, statements, operations and permissions.
11
+ # The only property that is shared between your workspaces is that they are linked to your organization,
12
+ # which carries your basic informations, such as tax ID, name, etc..
13
+ #
14
+ # ## Parameters (required):
15
+ # - username [string]: Simplified name to define the workspace URL. This name must be unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
16
+ # - name [string]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
17
+ #
18
+ # ## Attributes:
19
+ # - id [string, default nil]: unique id returned when the workspace is created. ex: '5656565656565656'
20
+ class Workspace < StarkBank::Utils::Resource
21
+ attr_reader :username, :name, :id
22
+ def initialize(username:, name:, id: nil)
23
+ super(id)
24
+ @username = username
25
+ @name = name
26
+ end
27
+
28
+ # # Create Workspace
29
+ #
30
+ # Send a Workspace for creation in the Stark Bank API
31
+ #
32
+ # ## Parameters (required):
33
+ # - username [string]: Simplified name to define the workspace URL. This name must be unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
34
+ # - name [string]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
35
+ #
36
+ # ## Parameters (optional):
37
+ # - user [Organization object]: Organization object. Not necessary if StarkBank.user was set before function call
38
+ #
39
+ # ## Return:
40
+ # - Workspace object with updated attributes
41
+ def self.create(username:, name:, user: nil)
42
+ StarkBank::Utils::Rest.post_single(entity: Workspace.new(username: username, name: name), user: user, **resource)
43
+ end
44
+
45
+ # # Retrieve a specific Workspace
46
+ #
47
+ # Receive a single Workspace object previously created in the Stark Bank API by passing its id
48
+ #
49
+ # ## Parameters (required):
50
+ # - id [string]: object unique id. ex: '5656565656565656'
51
+ #
52
+ # ## Parameters (optional):
53
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
54
+ #
55
+ # ## Return:
56
+ # - Workspace object with updated attributes
57
+ def self.get(id, user: nil)
58
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
59
+ end
60
+
61
+ # # Retrieve Workspaces
62
+ #
63
+ # Receive a generator of Workspace objects previously created in the Stark Bank API.
64
+ # If no filters are passed and the user is an Organization, all of the Organization Workspaces
65
+ # will be retrieved.
66
+ #
67
+ # ## Parameters (optional):
68
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
69
+ # - username [string]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
70
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
71
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
72
+ #
73
+ # ## Return:
74
+ # - generator of Workspace objects with updated attributes
75
+ def self.query(limit: nil, username: nil, ids: nil, user: nil)
76
+ StarkBank::Utils::Rest.get_list(limit: limit, username: username, ids: ids, user: user, **resource)
77
+ end
78
+
79
+ def self.resource
80
+ {
81
+ resource_name: 'Workspace',
82
+ resource_maker: proc { |json|
83
+ Workspace.new(
84
+ id: json['id'],
85
+ username: json['username'],
86
+ name: json['name']
87
+ )
88
+ }
89
+ }
90
+ end
91
+ end
92
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starkbank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
@@ -75,8 +75,16 @@ files:
75
75
  - lib/balance/balance.rb
76
76
  - lib/boleto/boleto.rb
77
77
  - lib/boleto/log.rb
78
+ - lib/boleto_holmes/boleto_holmes.rb
79
+ - lib/boleto_holmes/log.rb
78
80
  - lib/boleto_payment/boleto_payment.rb
79
81
  - lib/boleto_payment/log.rb
82
+ - lib/brcode_payment/brcode_payment.rb
83
+ - lib/brcode_payment/log.rb
84
+ - lib/brcode_preview/brcode_preview.rb
85
+ - lib/deposit/deposit.rb
86
+ - lib/deposit/log.rb
87
+ - lib/dict_key/dict_key.rb
80
88
  - lib/error.rb
81
89
  - lib/event/event.rb
82
90
  - lib/invoice/invoice.rb
@@ -87,6 +95,7 @@ files:
87
95
  - lib/transaction/transaction.rb
88
96
  - lib/transfer/log.rb
89
97
  - lib/transfer/transfer.rb
98
+ - lib/user/organization.rb
90
99
  - lib/user/project.rb
91
100
  - lib/user/user.rb
92
101
  - lib/utility_payment/log.rb
@@ -101,6 +110,7 @@ files:
101
110
  - lib/utils/rest.rb
102
111
  - lib/utils/url.rb
103
112
  - lib/webhook/webhook.rb
113
+ - lib/workspace/workspace.rb
104
114
  homepage: https://github.com/starkbank/sdk-ruby
105
115
  licenses:
106
116
  - MIT
@@ -116,9 +126,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
126
  version: '2.3'
117
127
  required_rubygems_version: !ruby/object:Gem::Requirement
118
128
  requirements:
119
- - - ">"
129
+ - - ">="
120
130
  - !ruby/object:Gem::Version
121
- version: 1.3.1
131
+ version: '0'
122
132
  requirements: []
123
133
  rubygems_version: 3.1.4
124
134
  signing_key: