starkbank 0.0.3 → 0.4.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.
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../../utils/resource')
4
- require_relative('../../utils/rest')
5
- require_relative('../../utils/checks')
6
- require_relative('utility')
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('utility_payment')
7
7
 
8
8
  module StarkBank
9
9
  class UtilityPayment
@@ -14,11 +14,11 @@ module StarkBank
14
14
  # be retrieved to check additional information on the UtilityPayment.
15
15
  #
16
16
  # ## Attributes:
17
- # - id [string]: unique id returned when the log is created. ex: "5656565656565656"
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
18
  # - payment [UtilityPayment]: UtilityPayment entity to which the log refers to.
19
- # - errors [list of strings]: list of errors linked to this BoletoPayment event.
20
- # - type [string]: type of the UtilityPayment event which triggered the log creation. ex: "registered" or "paid"
21
- # - created [DateTime]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ # - errors [list of strings]: list of errors linked to this UtilityPayment event.
20
+ # - type [string]: type of the UtilityPayment event which triggered the log creation. ex: 'processing' or 'success'
21
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
22
  class Log < StarkBank::Utils::Resource
23
23
  attr_reader :id, :created, :type, :errors, :payment
24
24
  def initialize(id:, created:, type:, errors:, payment:)
@@ -34,14 +34,14 @@ module StarkBank
34
34
  # Receive a single Log object previously created by the Stark Bank API by passing its id
35
35
  #
36
36
  # ## Parameters (required):
37
- # - id [string]: object unique id. ex: "5656565656565656"
37
+ # - id [string]: object unique id. ex: '5656565656565656'
38
38
  #
39
39
  # ## Parameters (optional):
40
40
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
41
41
  #
42
42
  # ## Return:
43
43
  # - Log object with updated attributes
44
- def self.get(id:, user: nil)
44
+ def self.get(id, user: nil)
45
45
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
46
46
  end
47
47
 
@@ -51,18 +51,26 @@ module StarkBank
51
51
  #
52
52
  # ## Parameters (optional):
53
53
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
54
- # - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
55
- # - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
56
- # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
57
- # - types [list of strings, default nil]: filter retrieved objects by event types. ex: "paid" or "registered"
54
+ # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
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
+ # - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'paid' or 'registered'
57
+ # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
58
58
  # - user [Project object, default nil]: 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
62
- def self.query(limit: nil, after: nil, before: nil, payment_ids: nil, types: nil, user: nil)
62
+ def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
63
63
  after = StarkBank::Utils::Checks.check_date(after)
64
64
  before = StarkBank::Utils::Checks.check_date(before)
65
- StarkBank::Utils::Rest.get_list(user: user, limit: limit, after: after, before: before, payment_ids: payment_ids, types: types, **resource)
65
+ StarkBank::Utils::Rest.get_list(
66
+ user: user,
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ types: types,
71
+ payment_ids: payment_ids,
72
+ **resource
73
+ )
66
74
  end
67
75
 
68
76
  def self.resource
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../../utils/resource')
4
- require_relative('../../utils/rest')
5
- require_relative('../../utils/checks')
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
6
 
7
7
  module StarkBank
8
8
  # # UtilityPayment object
@@ -12,19 +12,19 @@ module StarkBank
12
12
  # to the Stark Bank API and returns the list of created objects.
13
13
  #
14
14
  # ## Parameters (conditionally required):
15
- # - line [string, default nil]: Number sequence that describes the payment. Either 'line' or 'bar_code' parameters are required. If both are sent, they must match. ex: "34191.09008 63571.277308 71444.640008 5 81960000000062"
16
- # - bar_code [string, default nil]: Bar code number that describes the payment. Either 'line' or 'barCode' parameters are required. If both are sent, they must match. ex: "34195819600000000621090063571277307144464000"
15
+ # - line [string, default nil]: Number sequence that describes the payment. Either 'line' or 'bar_code' parameters are required. If both are sent, they must match. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062'
16
+ # - bar_code [string, default nil]: Bar code number that describes the payment. Either 'line' or 'barCode' parameters are required. If both are sent, they must match. ex: '34195819600000000621090063571277307144464000'
17
17
  #
18
18
  # ## Parameters (required):
19
- # - description [string]: Text to be displayed in your statement (min. 10 characters). ex: "payment ABC"
19
+ # - description [string]: Text to be displayed in your statement (min. 10 characters). ex: 'payment ABC'
20
20
  #
21
21
  # ## Parameters (optional):
22
- # - scheduled [Date, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
22
+ # - scheduled [Date, DateTime, Time or string, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
23
23
  # - tags [list of strings]: list of strings for tagging
24
24
  #
25
25
  # ## Attributes (return-only):
26
- # - id [string, default nil]: unique id returned when payment is created. ex: "5656565656565656"
27
- # - status [string, default nil]: current payment status. ex: "registered" or "paid"
26
+ # - id [string, default nil]: unique id returned when payment is created. ex: '5656565656565656'
27
+ # - status [string, default nil]: current payment status. ex: 'success' or 'failed'
28
28
  # - amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
29
29
  # - fee [integer, default nil]: fee charged when utility payment is created. ex: 200 (= R$ 2.00)
30
30
  # - created [DateTime, default nil]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
@@ -55,7 +55,7 @@ module StarkBank
55
55
  #
56
56
  # ## Return:
57
57
  # - list of UtilityPayment objects with updated attributes
58
- def self.create(payments:, user: nil)
58
+ def self.create(payments, user: nil)
59
59
  StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
60
60
  end
61
61
 
@@ -64,31 +64,31 @@ module StarkBank
64
64
  # Receive a single UtilityPayment object previously created by the Stark Bank API by passing its id
65
65
  #
66
66
  # ## Parameters (required):
67
- # - id [string]: object unique id. ex: "5656565656565656"
67
+ # - id [string]: object unique id. ex: '5656565656565656'
68
68
  #
69
69
  # ## Parameters (optional):
70
70
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
71
71
  #
72
72
  # ## Return:
73
73
  # - UtilityPayment object with updated attributes
74
- def self.get(id:, user: nil)
74
+ def self.get(id, user: nil)
75
75
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
76
76
  end
77
77
 
78
78
  # # Retrieve a specific UtilityPayment pdf file
79
79
  #
80
80
  # Receive a single UtilityPayment pdf file generated in the Stark Bank API by passing its id.
81
- # Only valid for utility payments with "success" status.
81
+ # Only valid for utility payments with 'success' status.
82
82
  #
83
83
  # ## Parameters (required):
84
- # - id [string]: object unique id. ex: "5656565656565656"
84
+ # - id [string]: object unique id. ex: '5656565656565656'
85
85
  #
86
86
  # ## Parameters (optional):
87
87
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
88
88
  #
89
89
  # ## Return:
90
90
  # - UtilityPayment pdf file
91
- def self.pdf(id:, user: nil)
91
+ def self.pdf(id, user: nil)
92
92
  StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
93
93
  end
94
94
 
@@ -98,19 +98,28 @@ module StarkBank
98
98
  #
99
99
  # ## Parameters (optional):
100
100
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
101
- # - status [string, default nil]: filter for status of retrieved objects. ex: "paid"
102
- # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"]
103
- # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
104
- # - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
105
- # - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
101
+ # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
102
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
103
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
104
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
105
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
106
106
  # - user [Project object, default nil]: 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
110
- def self.query(limit: nil, status: nil, tags: nil, ids: nil, after: nil, before: nil, user: nil)
110
+ def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
111
111
  after = StarkBank::Utils::Checks.check_date(after)
112
112
  before = StarkBank::Utils::Checks.check_date(before)
113
- StarkBank::Utils::Rest.get_list(user: user, limit: limit, status: status, tags: tags, ids: ids, after: after, before: before, **resource)
113
+ StarkBank::Utils::Rest.get_list(
114
+ user: user,
115
+ limit: limit,
116
+ after: after,
117
+ before: before,
118
+ tags: tags,
119
+ ids: ids,
120
+ status: status,
121
+ **resource
122
+ )
114
123
  end
115
124
 
116
125
  # # Delete a UtilityPayment entity
@@ -118,14 +127,14 @@ module StarkBank
118
127
  # Delete a UtilityPayment entity previously created in the Stark Bank API
119
128
  #
120
129
  # ## Parameters (required):
121
- # - id [string]: UtilityPayment unique id. ex: "5656565656565656"
130
+ # - id [string]: UtilityPayment unique id. ex:'5656565656565656'
122
131
  #
123
132
  # ## Parameters (optional):
124
133
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
125
134
  #
126
135
  # ## Return:
127
136
  # - deleted UtilityPayment with updated attributes
128
- def self.delete(id:, user: nil)
137
+ def self.delete(id, user: nil)
129
138
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
130
139
  end
131
140
 
@@ -6,9 +6,13 @@ module StarkBank
6
6
  module Utils
7
7
  module API
8
8
  def self.api_json(entity)
9
- entity_hash = {}
10
- entity.instance_variables.each do |key|
11
- entity_hash[key[1..-1]] = entity.instance_variable_get(key)
9
+ if entity.is_a?(Hash)
10
+ entity_hash = entity
11
+ else
12
+ entity_hash = {}
13
+ entity.instance_variables.each do |key|
14
+ entity_hash[key[1..-1]] = entity.instance_variable_get(key)
15
+ end
12
16
  end
13
17
  cast_json_to_api_format(entity_hash)
14
18
  end
@@ -19,6 +23,15 @@ module StarkBank
19
23
  next if value.nil?
20
24
 
21
25
  value = value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time) ? value.strftime('%Y-%m-%d') : value
26
+
27
+ if value.is_a?(Array)
28
+ list = []
29
+ value.each do |v|
30
+ list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
31
+ end
32
+ value = list
33
+ end
34
+
22
35
  entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = value
23
36
  end
24
37
  entity_hash
@@ -17,6 +17,14 @@ module StarkBank
17
17
  user
18
18
  end
19
19
 
20
+ def self.check_language
21
+ language = StarkBank.language
22
+ accepted_languages = %w[en-US pt-BR]
23
+ raise(ArgumentError, "Select a valid language: #{accepted_languages.join(', ')}") unless accepted_languages.include?(language)
24
+
25
+ language
26
+ end
27
+
20
28
  def self.check_environment(environment)
21
29
  environments = StarkBank::Utils::Environment.constants(false).map { |c| StarkBank::Utils::Environment.const_get(c) }
22
30
  raise(ArgumentError, "Select a valid environment: #{environments.join(', ')}") unless environments.include?(environment)
@@ -24,6 +24,7 @@ module StarkBank
24
24
 
25
25
  def self.fetch(method:, path:, payload: nil, query: nil, user: nil)
26
26
  user = Checks.check_user(user)
27
+ language = Checks.check_language
27
28
 
28
29
  base_url = {
29
30
  Environment::PRODUCTION => 'https://api.starkbank.com/',
@@ -60,7 +61,8 @@ module StarkBank
60
61
  req['Access-Time'] = access_time
61
62
  req['Access-Signature'] = signature
62
63
  req['Content-Type'] = 'application/json'
63
- req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-0.0.3"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-0.4.0"
65
+ req['Accept-Language'] = language
64
66
 
65
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
66
68
 
@@ -47,10 +47,11 @@ module StarkBank
47
47
  StarkBank::Utils::API.from_api_json(resource_maker, entity)
48
48
  end
49
49
 
50
- def self.get_pdf(resource_name:, resource_maker:, id:, user: nil)
50
+ def self.get_pdf(resource_name:, resource_maker:, id:, user: nil, **query)
51
51
  StarkBank::Utils::Request.fetch(
52
52
  method: 'GET',
53
53
  path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/pdf",
54
+ query: StarkBank::Utils::API.cast_json_to_api_format(query),
54
55
  user: user
55
56
  ).content
56
57
  end
@@ -13,10 +13,10 @@ module StarkBank
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', 'boleto-payment']
17
17
  #
18
18
  # ## Attributes:
19
- # - id [string, default nil]: unique id returned when the log is created. ex: "5656565656565656"
19
+ # - id [string, default nil]: unique id returned when the webhook is created. ex: '5656565656565656'
20
20
  class Webhook < StarkBank::Utils::Resource
21
21
  attr_reader :url, :subscriptions, :id
22
22
  def initialize(url:, subscriptions:, id: nil)
@@ -30,8 +30,8 @@ module StarkBank
30
30
  # Send a single Webhook subscription for creation in the Stark Bank API
31
31
  #
32
32
  # ## Parameters (required):
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"]
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']
35
35
  #
36
36
  # ## Parameters (optional):
37
37
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
@@ -47,14 +47,14 @@ module StarkBank
47
47
  # Receive a single Webhook subscription object previously created in the Stark Bank API by passing its id
48
48
  #
49
49
  # ## Parameters (required):
50
- # - id [string]: object unique id. ex: "5656565656565656"
50
+ # - id [string]: object unique id. ex: '5656565656565656'
51
51
  #
52
52
  # ## Parameters (optional):
53
53
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
54
54
  #
55
55
  # ## Return:
56
56
  # - Webhook object with updated attributes
57
- def self.get(id:, user: nil)
57
+ def self.get(id, user: nil)
58
58
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
59
59
  end
60
60
 
@@ -77,14 +77,14 @@ module StarkBank
77
77
  # Delete a Webhook entity previously created in the Stark Bank API
78
78
  #
79
79
  # ## Parameters (required):
80
- # - id [string]: Webhook unique id. ex: "5656565656565656"
80
+ # - id [string]: Webhook unique id. ex: '5656565656565656'
81
81
  #
82
82
  # ## Parameters (optional):
83
83
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
84
84
  #
85
85
  # ## Return:
86
86
  # - deleted Webhook with updated attributes
87
- def self.delete(id:, user: nil)
87
+ def self.delete(id, user: nil)
88
88
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
89
89
  end
90
90
 
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: 0.0.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
@@ -44,21 +44,22 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - lib/balance/balance.rb
47
48
  - lib/boleto/boleto.rb
48
49
  - lib/boleto/log.rb
50
+ - lib/boleto_payment/boleto_payment.rb
51
+ - lib/boleto_payment/log.rb
49
52
  - lib/error.rb
53
+ - lib/event/event.rb
50
54
  - lib/key.rb
51
- - lib/ledger/balance.rb
52
- - lib/ledger/transaction.rb
53
- - lib/payment/boleto/boleto.rb
54
- - lib/payment/boleto/log.rb
55
- - lib/payment/utility/log.rb
56
- - lib/payment/utility/utility.rb
57
55
  - lib/starkbank.rb
56
+ - lib/transaction/transaction.rb
58
57
  - lib/transfer/log.rb
59
58
  - lib/transfer/transfer.rb
60
59
  - lib/user/project.rb
61
60
  - lib/user/user.rb
61
+ - lib/utility_payment/log.rb
62
+ - lib/utility_payment/utility_payment.rb
62
63
  - lib/utils/api.rb
63
64
  - lib/utils/cache.rb
64
65
  - lib/utils/case.rb
@@ -68,7 +69,6 @@ files:
68
69
  - lib/utils/resource.rb
69
70
  - lib/utils/rest.rb
70
71
  - lib/utils/url.rb
71
- - lib/webhook/event.rb
72
72
  - lib/webhook/webhook.rb
73
73
  homepage: https://github.com/starkbank/sdk-ruby
74
74
  licenses: