unit-ruby 0.2.4 → 0.2.6

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: 3de97a1740f4eccb8b4afba7feee092d42f7aec1a1a17125b0a512b12b704fac
4
+ data.tar.gz: 8eaec1f14a300006bf99dea3336db46295f875f55b23d9d637372c6df123424a
5
5
  SHA512:
6
- metadata.gz: 8ac97dd5692904c8c2fd902343ea29f7c0da8d9e12fb8d042d5671795f4d221d9f3600415412cd4f6562c294f6549615a5d158781a9addceeae2ad3e971f8dea
7
- data.tar.gz: 7263a5879b85e666707d506f10f0b0e4ad7b0023fd3e2760163d687268b865f6713bc437e1bedba9153517687fe5a07294a370e9d6e310befc31692b815c4ef4
6
+ metadata.gz: e8599644fb9e58615349538b9a6b73c99200c555b59504d68bcf405fcf95a30bc6d7a1da2f517eb258fa9fa3b5a6a21427f1993249ae8da12ac27df0788bf10c
7
+ data.tar.gz: 647419597cc13b8062bc5baf98f8693ec2ba52415694c4df7ee0aaf87444abaeb3fbcab96b791fb78bc52f131293c3ce93a1f05d5266da5309d2f892be639bce
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit-ruby (0.2.4)
5
- activesupport
4
+ unit-ruby (0.2.5)
5
+ activesupport (~> 6.1.5)
6
6
  faraday (~> 1.8.0)
7
7
  faraday_middleware (~> 1.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.1.5)
12
+ activesupport (6.1.7.1)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
@@ -41,11 +41,11 @@ GEM
41
41
  faraday-rack (1.0.0)
42
42
  faraday_middleware (1.0.0)
43
43
  faraday (~> 1.0)
44
- i18n (1.10.0)
44
+ i18n (1.12.0)
45
45
  concurrent-ruby (~> 1.0)
46
46
  method_source (1.0.0)
47
- minitest (5.15.0)
48
- multipart-post (2.1.1)
47
+ minitest (5.17.0)
48
+ multipart-post (2.2.3)
49
49
  parallel (1.21.0)
50
50
  parser (3.1.0.0)
51
51
  ast (~> 2.4.1)
@@ -82,10 +82,10 @@ GEM
82
82
  parser (>= 3.0.1.1)
83
83
  ruby-progressbar (1.11.0)
84
84
  ruby2_keywords (0.0.5)
85
- tzinfo (2.0.4)
85
+ tzinfo (2.0.5)
86
86
  concurrent-ruby (~> 1.0)
87
87
  unicode-display_width (2.1.0)
88
- zeitwerk (2.5.4)
88
+ zeitwerk (2.6.6)
89
89
 
90
90
  PLATFORMS
91
91
  ruby
data/README.md CHANGED
@@ -37,7 +37,20 @@ end
37
37
 
38
38
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
39
 
40
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+ To install this gem onto your local machine, run `bundle exec rake install`.
41
+
42
+ ## Releasing
43
+
44
+ In order to publish this gem on [RubyGems.org](https://rubygems.org/), you will need to create a RubyGems account. Note that multi-factor authentication must be set up on your account before a gem can be published.
45
+
46
+ Once your account is set up, the following operations will facilitate publishing the latest version of the gem:
47
+
48
+ 1. Ensure that PR request is approved by appropriate member(s) of the engineering team
49
+ 2. Update the gem version number in `version.rb`
50
+ 3. Run `gem build unit-ruby`. This will build a version of the gem called `unit-ruby-[gem version number].gem`
51
+ 4. Push this latest version of the gem to RubyGems.org by calling `gem push unit-ruby-[gem version number].gem`
52
+ 5. Commit `version.rb` file
53
+ 6. Merge PR into `main` branch
41
54
 
42
55
  ## Contributing
43
56
 
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,
@@ -63,17 +63,17 @@ module Unit
63
63
  end
64
64
 
65
65
  module Save
66
- def save
66
+ def save(attributes)
67
+ resource = self.class.new(attributes.except(:id))
67
68
  updated_resource = self.class.connection.patch(
68
- resource_path,
69
+ self.class.resource_path(id),
69
70
  {
70
71
  data: {
71
72
  type: resource_type,
72
- attributes: as_json_api.slice(*dirty_attributes)
73
+ attributes: resource.as_json_api.slice(*resource.dirty_attributes)
73
74
  }
74
75
  }
75
76
  )
76
-
77
77
  update_resource_from_json_api(updated_resource)
78
78
  end
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module Unit
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.6'
3
3
  end
data/unit-ruby.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ['lib']
36
36
 
37
- spec.add_dependency 'activesupport'
37
+ spec.add_dependency 'activesupport', '~> 6.1.5'
38
38
  spec.add_dependency 'faraday', '~> 1.8.0'
39
39
  spec.add_dependency 'faraday_middleware', '~> 1.0.0'
40
40
 
metadata CHANGED
@@ -1,30 +1,30 @@
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.6
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-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 6.1.5
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 6.1.5
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -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.7
223
+ signing_key:
224
224
  specification_version: 4
225
225
  summary: A Ruby gem for communicating with the Unit API.
226
226
  test_files: []