unit-ruby 0.2.4 → 0.2.5

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: 3bb24533446bfd10538c49ee2a9c28c6428bcc93c316d64e5278308809ab963f
4
- data.tar.gz: f995e561b1d6c63249dac9d9270ecae0ba01bf00c955a7ba9e07a89e7c082b5d
3
+ metadata.gz: 36a4adc5ac66ecac5eeb0b01a57d131f26ce1457e1aefd766e9c75cc0b11599b
4
+ data.tar.gz: 3c37bdf8d9eb16acb01389838ce8798d7d50b9b4c6d815474ccff1e4f5c37c8c
5
5
  SHA512:
6
- metadata.gz: 8ac97dd5692904c8c2fd902343ea29f7c0da8d9e12fb8d042d5671795f4d221d9f3600415412cd4f6562c294f6549615a5d158781a9addceeae2ad3e971f8dea
7
- data.tar.gz: 7263a5879b85e666707d506f10f0b0e4ad7b0023fd3e2760163d687268b865f6713bc437e1bedba9153517687fe5a07294a370e9d6e310befc31692b815c4ef4
6
+ metadata.gz: 5ce9efd4376713ad8815f69df865baf3137889cc82de088be5fd8951aab2d08613d4a7d3f39106c8f78fe431e6a173144eb413b0bf23f211abd229c9e7af3770
7
+ data.tar.gz: 278d00d967a57090d42038781e8f0bc63437398a33bb1d620301c60d13a81e0583f76e22fc76d7362b0618ac3d1be9efee414848a4014a207abbb6b61560fee2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit-ruby (0.2.4)
4
+ unit-ruby (0.2.5)
5
5
  activesupport
6
6
  faraday (~> 1.8.0)
7
7
  faraday_middleware (~> 1.0.0)
@@ -9,12 +9,11 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.1.5)
12
+ activesupport (7.0.4.1)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
- zeitwerk (~> 2.3)
18
17
  ast (2.4.2)
19
18
  coderay (1.1.3)
20
19
  concurrent-ruby (1.1.10)
@@ -41,11 +40,11 @@ GEM
41
40
  faraday-rack (1.0.0)
42
41
  faraday_middleware (1.0.0)
43
42
  faraday (~> 1.0)
44
- i18n (1.10.0)
43
+ i18n (1.12.0)
45
44
  concurrent-ruby (~> 1.0)
46
45
  method_source (1.0.0)
47
- minitest (5.15.0)
48
- multipart-post (2.1.1)
46
+ minitest (5.17.0)
47
+ multipart-post (2.2.3)
49
48
  parallel (1.21.0)
50
49
  parser (3.1.0.0)
51
50
  ast (~> 2.4.1)
@@ -82,10 +81,9 @@ GEM
82
81
  parser (>= 3.0.1.1)
83
82
  ruby-progressbar (1.11.0)
84
83
  ruby2_keywords (0.0.5)
85
- tzinfo (2.0.4)
84
+ tzinfo (2.0.5)
86
85
  concurrent-ruby (~> 1.0)
87
86
  unicode-display_width (2.1.0)
88
- zeitwerk (2.5.4)
89
87
 
90
88
  PLATFORMS
91
89
  ruby
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -19,6 +19,18 @@ module Unit
19
19
  attribute :close_reason, Types::String, readonly: true # Optional. The reason the account was closed, either ByCustomer or Fraud.
20
20
 
21
21
  belongs_to :customer, class_name: 'Unit::IndividualCustomer'
22
+ has_many :customers, class_name: 'Unit::IndividualCustomer'
23
+
24
+ def add_customer(customer_id)
25
+ self.class.connection.post(
26
+ "accounts/#{id}/relationships/customers",
27
+ {
28
+ data: [{ type: 'customer', id: customer_id }]
29
+ }
30
+ )
31
+
32
+ self.class.find(id)
33
+ end
22
34
 
23
35
  include ResourceOperations::List
24
36
  include ResourceOperations::Create
@@ -101,6 +101,31 @@ module Unit
101
101
  end
102
102
  end
103
103
 
104
+ def self.has_many(resource_name, class_name: nil)
105
+ class_name ||= resource_name.to_s.camelize
106
+
107
+ define_method(resource_name) do
108
+ # if there is only one of the resources, Unit will return the
109
+ # singular name of that relationship in their response.
110
+ # For example, if a deposit account has one customer, `customer`
111
+ # will be returned from Unit as a resource, whereas if there
112
+ # are more than one customer, then customers will be returned from Unit
113
+
114
+ # the below will translate these singular relationship
115
+ # into a plural relationship - ie `customer` -> `customers`
116
+
117
+ singular_resource_name = resource_name.to_s.singularize.to_sym
118
+
119
+ if relationships.keys.include?(resource_name)
120
+ relationships.dig(resource_name.to_sym, :data).map do |resource|
121
+ Kernel.const_get(class_name).find(resource[:id])
122
+ end
123
+ elsif defined?(singular_resource_name)
124
+ [send(singular_resource_name)].compact
125
+ end
126
+ end
127
+ end
128
+
104
129
  # Hyrdates an instance of the resource from data returned from the API
105
130
  def self.build_resource_from_json_api(data_item)
106
131
  new.tap do |resource|
@@ -22,7 +22,7 @@ module Unit
22
22
  module ClassMethods
23
23
  def create(attributes)
24
24
  id = attributes.fetch(:id, nil)
25
- resource = new(attributes.without(:id))
25
+ resource = new(attributes.except(:id))
26
26
 
27
27
  data = {
28
28
  type: resource.resource_type,
@@ -1,3 +1,3 @@
1
1
  module Unit
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chloe Isacke
8
8
  - Ian Yamey
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-04-14 00:00:00.000000000 Z
12
+ date: 2023-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -137,7 +137,7 @@ dependencies:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
139
  version: 1.24.1
140
- description:
140
+ description:
141
141
  email:
142
142
  - chloe@retirable.com
143
143
  - ian@retirable.com
@@ -204,7 +204,7 @@ metadata:
204
204
  source_code_uri: https://github.com/retirable/unit-ruby
205
205
  changelog_uri: https://github.com/retirable/unit-ruby/blob/main/CHANGELOG.md
206
206
  rubygems_mfa_required: 'true'
207
- post_install_message:
207
+ post_install_message:
208
208
  rdoc_options: []
209
209
  require_paths:
210
210
  - lib
@@ -219,8 +219,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.0.3
223
- signing_key:
222
+ rubygems_version: 3.4.4
223
+ signing_key:
224
224
  specification_version: 4
225
225
  summary: A Ruby gem for communicating with the Unit API.
226
226
  test_files: []