unit-ruby 0.10.1 → 0.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4771e47bafd526a9a832e0552b1cc67a2e49720a44d87c727e0d2de4b764f1bf
4
- data.tar.gz: d96d783374e42fb21168afd0bf86f809f8fc309de3f6e7a0a0cf7fe4f320ef05
3
+ metadata.gz: 611999a90eb76e2e38260184e44648705f496868a151479b26e723afe6c3934e
4
+ data.tar.gz: 8bb363a47f476ff15efa348e7e1319b05bc80402bfce5afe62355aac8021f0fc
5
5
  SHA512:
6
- metadata.gz: 3e531d141c243bcaf32b651523092c3f543ac7a610026210ac6e165a9018de635bf3408f57dc487a9f66c8044f9659dbb98fe891705820efa413376db9e3242c
7
- data.tar.gz: 1bbaa140de53f9350b48ac53c725b591054abac4427ef1ba6e16eff04b0000bca8357469dc1d91b30bc40e7a0ac7534bc5d46bbcb215360c91615c6668fe52a4
6
+ metadata.gz: 380415c5203e9a65cea4b573215868ec10c5da4d3d0a517ae4d14b5adbbbb7c7b3c96896d0241f531cb8c39aa3c24cdd4f4f1dbd00606fb945d7a6ca2789a0ad
7
+ data.tar.gz: 53d601f49d7821628cdbacfa0759ddd4f74d2a9b29c15f3990da5a35c7e80bd7fd5513ad57cf7bd2c80e3dc9b19766d46d6babf268c2195f7a844facaa68ca2f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit-ruby (0.10.1)
4
+ unit-ruby (0.12.0)
5
5
  activesupport
6
6
  faraday (>= 2.0.1, < 3)
7
7
  faraday-retry
@@ -1,18 +1,22 @@
1
1
  module Unit
2
2
  class ApplicationForm < APIResource
3
3
  path '/application-forms'
4
+ header 'X-Accept-Version' => 'V2024_06'
4
5
 
5
6
  attribute :tags, Types::Hash # Optional
6
7
  attribute :allowed_application_types, Types::Array # Optional. Array of Individual, Business or SoleProprietorship.
7
8
  attribute :applicant_details, Types::ApplicationFormPrefill # Optional. Add data that is already known about the end-customer to be auto populated on the form.
8
9
  attribute :settings_override, Types::ApplicationFormSettingsOverride # Optional. Override disclosure URLs that were defined in the application form settings.
9
-
10
- attribute :stage, Types::String, readonly: true
11
- attribute :url, Types::String, readonly: true
10
+ attribute :idempotency_key, Types::String
12
11
 
13
12
  belongs_to :application, class_name: 'Unit::IndividualApplication'
14
13
 
14
+ def url
15
+ links[:related][:href]
16
+ end
17
+
15
18
  include ResourceOperations::Create
16
19
  include ResourceOperations::Find
20
+ include ResourceOperations::List
17
21
  end
18
22
  end
@@ -0,0 +1,40 @@
1
+ module Unit
2
+ class RecurringCreditAchPayment < APIResource
3
+ path '/recurring-payments'
4
+
5
+ attribute :idempotency_key, Types::String # Optional
6
+ attribute :tags, Types::Hash # Optional
7
+
8
+ attribute :amount, Types::Integer # Amount to transfer in cents.
9
+ attribute :description, Types::String # Description of the transfer. Max of 10 characters.
10
+ attribute :addenda, Types::String # Optional. Additional payment description. Max of 80 characters.
11
+ attribute :schedule, Types::Schedule # Schedule for the transfer.
12
+
13
+ attribute :status, Types::String, readonly: true
14
+ attribute :number_of_payments, Types::Integer, readonly: true
15
+ attribute :created_at, Types::DateTime, readonly: true
16
+
17
+ belongs_to :account, class_name: 'Unit::DepositAccount'
18
+ belongs_to :counterparty, class_name: 'Unit::AchCounterparty'
19
+ belongs_to :customer, class_name: 'Unit::IndividualCustomer'
20
+
21
+ def disable
22
+ updated_resource = self.class.connection.post(
23
+ "#{self.class.resource_path(id)}/disable"
24
+ )
25
+ update_resource_from_json_api(updated_resource)
26
+ end
27
+
28
+ def enable
29
+ updated_resource = self.class.connection.post(
30
+ "#{self.class.resource_path(id)}/enable"
31
+ )
32
+ update_resource_from_json_api(updated_resource)
33
+ end
34
+
35
+ include ResourceOperations::List
36
+ include ResourceOperations::Create
37
+ include ResourceOperations::Find
38
+ include ResourceOperations::Destroy
39
+ end
40
+ end
@@ -5,8 +5,15 @@ module Unit
5
5
  class Date
6
6
  def self.cast(value)
7
7
  return nil if value.nil?
8
+ return value if value.is_a?(::Date)
8
9
 
9
- ::Date.parse(value).strftime('%F')
10
+ ::Date.parse(value)
11
+ end
12
+
13
+ def self.as_json_api(value)
14
+ return nil if value.nil?
15
+
16
+ value.strftime('%F')
10
17
  end
11
18
  end
12
19
  end
@@ -0,0 +1,45 @@
1
+ module Unit
2
+ module Types
3
+ class Schedule
4
+ attr_reader :start_time, :end_time, :interval,
5
+ :day_of_month, :day_of_week,
6
+ :total_number_of_payments, :next_scheduled_action
7
+
8
+ def initialize(schedule_params)
9
+ @start_time = schedule_params[:start_time]
10
+ @end_time = schedule_params[:end_time]
11
+ @interval = schedule_params[:interval]
12
+ @day_of_month = schedule_params[:day_of_month]
13
+ @day_of_week = schedule_params[:day_of_week]
14
+ @total_number_of_payments = schedule_params[:total_number_of_payments]
15
+ @next_scheduled_action = schedule_params[:next_scheduled_action]
16
+ end
17
+
18
+ def self.cast(val)
19
+ return val if val.is_a? self
20
+ return nil if val.nil?
21
+
22
+ new(
23
+ start_time: Unit::Types::Date.cast(val[:start_time]),
24
+ end_time: Unit::Types::Date.cast(val[:end_time]),
25
+ next_scheduled_action: Unit::Types::Date.cast(val[:next_scheduled_action]),
26
+ interval: val[:interval],
27
+ day_of_month: val[:day_of_month],
28
+ day_of_week: val[:day_of_week],
29
+ total_number_of_payments: val[:total_number_of_payments],
30
+ )
31
+ end
32
+
33
+ def as_json_api
34
+ {
35
+ start_time: Unit::Types::Date.as_json_api(start_time),
36
+ end_time: Unit::Types::Date.as_json_api(end_time),
37
+ interval: interval,
38
+ day_of_month: day_of_month,
39
+ day_of_week: day_of_week,
40
+ total_number_of_payments: total_number_of_payments
41
+ }.compact
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,6 +1,6 @@
1
1
  module Unit
2
2
  class APIResource
3
- attr_accessor :id, :type, :raw_data
3
+ attr_accessor :id, :type, :raw_data, :links
4
4
 
5
5
  def initialize(attributes = {})
6
6
  clear_attributes!
@@ -14,7 +14,7 @@ module Unit
14
14
  # Creates a base http connection to the API
15
15
  #
16
16
  def self.connection
17
- @connection ||= Connection.new
17
+ @connection ||= Connection.new(headers)
18
18
  end
19
19
 
20
20
  # Defines the schema for a resource's attributes
@@ -66,6 +66,21 @@ module Unit
66
66
  @path = route
67
67
  end
68
68
 
69
+ # Sets resource-specific headers
70
+ #
71
+ # Usage:
72
+ # class Customer < Unit::Resource
73
+ # header 'X-Some-Header' => 'Header Value'
74
+ # end
75
+ def self.header(header_key_value_pair)
76
+ key, value = header_key_value_pair.first
77
+ headers[key] = value
78
+ end
79
+
80
+ def self.headers
81
+ @headers ||= {}
82
+ end
83
+
69
84
  def self.resource_path(id)
70
85
  "#{path}/#{id}"
71
86
  end
@@ -149,6 +164,7 @@ module Unit
149
164
  self.type = data[:type]
150
165
  self.raw_data = data
151
166
  self.relationships = data[:relationships]
167
+ self.links = data[:links]
152
168
 
153
169
  clear_attributes!
154
170
 
@@ -10,11 +10,12 @@ module Unit
10
10
 
11
11
  attr_reader :connection
12
12
 
13
- def initialize
13
+ def initialize(custom_headers = {})
14
14
  @connection = Faraday.new(self.class.base_url) do |f|
15
15
  f.headers['UNIT_TRUST_TOKEN'] = self.class.trust_token if self.class.trust_token
16
16
  f.headers['Authorization'] = "Bearer #{self.class.api_key}"
17
17
  f.headers['Content-Type'] = 'application/vnd.api+json'
18
+ f.headers.merge!(custom_headers)
18
19
  f.request :json # encode req bodies as JSON
19
20
  f.request :retry # retry transient failures
20
21
  f.response :json # decode response bodies as JSON
@@ -46,6 +47,17 @@ module Unit
46
47
  from_json_api(response.body)
47
48
  end
48
49
 
50
+ # Executes a DELETE request to the API
51
+ #
52
+ # @return boolean
53
+ def delete(path)
54
+ response = connection.delete(path)
55
+
56
+ handle_errors(response)
57
+
58
+ from_json_api(response.body)
59
+ end
60
+
49
61
  # Executes a PATCH request to the API
50
62
  def patch(path, data = nil)
51
63
  response = connection.patch do |req|
@@ -10,5 +10,9 @@ module Unit
10
10
 
11
11
  super(@details)
12
12
  end
13
+
14
+ def to_s
15
+ "#{@status} #{@message}: #{@details}"
16
+ end
13
17
  end
14
18
  end
@@ -97,5 +97,13 @@ module Unit
97
97
  replace(JSON.parse(json_attributes))
98
98
  end
99
99
  end
100
+
101
+ module Destroy
102
+ def destroy
103
+ updated_resource = self.class.connection.delete(self.class.resource_path(id))
104
+
105
+ update_resource_from_json_api(updated_resource)
106
+ end
107
+ end
100
108
  end
101
109
  end
@@ -1,3 +1,3 @@
1
1
  module Unit
2
- VERSION = '0.10.1'
2
+ VERSION = '0.12.0'
3
3
  end
data/lib/unit-ruby.rb CHANGED
@@ -22,6 +22,7 @@ require 'unit-ruby/types/full_name'
22
22
  require 'unit-ruby/types/hash'
23
23
  require 'unit-ruby/types/integer'
24
24
  require 'unit-ruby/types/phone'
25
+ require 'unit-ruby/types/schedule'
25
26
  require 'unit-ruby/types/string'
26
27
 
27
28
  require 'unit-ruby/ach_payment'
@@ -39,6 +40,7 @@ require 'unit-ruby/institution'
39
40
  require 'unit-ruby/customer_bank_migration'
40
41
  require 'unit-ruby/outreach_settings'
41
42
  require 'unit-ruby/received_payment'
43
+ require 'unit-ruby/recurring_credit_ach_payment'
42
44
  require 'unit-ruby/pin_status'
43
45
  require 'unit-ruby/statement'
44
46
  require 'unit-ruby/transaction'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chloe Isacke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-02-11 00:00:00.000000000 Z
12
+ date: 2025-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -183,6 +183,7 @@ files:
183
183
  - lib/unit-ruby/outreach_settings.rb
184
184
  - lib/unit-ruby/pin_status.rb
185
185
  - lib/unit-ruby/received_payment.rb
186
+ - lib/unit-ruby/recurring_credit_ach_payment.rb
186
187
  - lib/unit-ruby/statement.rb
187
188
  - lib/unit-ruby/tax_form.rb
188
189
  - lib/unit-ruby/transaction.rb
@@ -204,6 +205,7 @@ files:
204
205
  - lib/unit-ruby/types/hash.rb
205
206
  - lib/unit-ruby/types/integer.rb
206
207
  - lib/unit-ruby/types/phone.rb
208
+ - lib/unit-ruby/types/schedule.rb
207
209
  - lib/unit-ruby/types/string.rb
208
210
  - lib/unit-ruby/util/api_resource.rb
209
211
  - lib/unit-ruby/util/connection.rb