Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deposit account limits API resource #43

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

trevornelson
Copy link
Contributor

@trevornelson trevornelson commented Oct 3, 2024

Adds a new AccountLimits resource for returning an account's limits and current usage against said limits. I decided to decouple this more strongly from the Unit API's schema, which meant I had to override the default API JSON casting abstractions that other resources in the library have. There's a few reasons for this:

  • The limits are broken up into subobjects for each resource (e.g. ach or checkDeposit). Each of these sub-objects have their own unique schema, which means they'd each need to have their own types defined here in order to fit with how the API JSON gets cast to objects. That felt a lil sloppy to me- I'd rather the consumer get a simpler interface.
  • Limits and current usage are stored in separate objects in the API. I was kind of fighting the pre-existing ApiResource's casting.
  • These are all read only fields, so we really only care about mapping from the API to the library resource. Since they're read only, a lot of the value of the casting abstraction isn't really helpful.

Copy link

linear bot commented Oct 3, 2024

@trevornelson trevornelson force-pushed the trevor/ret-3414-show-ach-limits-in-the-dashboard branch 4 times, most recently from f0149a4 to 8007226 Compare October 4, 2024 18:11
@trevornelson trevornelson marked this pull request as ready for review October 4, 2024 18:13
@trevornelson trevornelson requested a review from a team October 4, 2024 18:13
end
# rubocop:enable Metrics/AbcSize

def extract_base_resource_details(data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda silly, but Rubocop was complaining about too many things. I couldn't get around AbcSize as it is.

@trevornelson trevornelson force-pushed the trevor/ret-3414-show-ach-limits-in-the-dashboard branch from 8007226 to 7455235 Compare October 4, 2024 18:46
Copy link
Contributor

@ianyamey ianyamey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works, so I'm okay shipping this. However, we'd be letting in some of our own usage / customizations creep into the base library. I've left some suggestions on how we might keep the implementation closer aligned with Unit's docs

@@ -0,0 +1,108 @@
module Unit
class AccountLimits < APIResource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there was quite a bit of overloading required to mack this quack correctly, what do you think about moving this into the Accounts API resource?

class DepositAccount < APIResource
  def limits
    @cached_limits ||= connection.get("#{resource_path(id)}/limits")
    Types::Limits.cast(cached_limits)
  end
  
  def ach_debit_daily_limit
    limits.dig('ach', 'debit', 'daily')
  end

  def ach_credit_daily_limit
    limits.dig('ach', 'credit', 'daily')
  end
  ...
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's nice intent to remap the Unit structure into something more consumable, it wondering if keeping more closely aligned to the API docs will make this easier to maintain (and fewer edge cases/inconsistencies in the implementation).

You could still remap things to be friendlier in the API consumer (for us, that means in our app) rather than the base library

Copy link
Contributor

@ianyamey ianyamey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much cleaner. While it's got more boiler plate code, it's more aligned with the Unit API 👍 👍

Comment on lines 36 to 38
return @limits if @limits

@limits = Types::AccountLimits.cast(
self.class.connection.get("accounts/#{id}/limits")
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return @limits if @limits
@limits = Types::AccountLimits.cast(
self.class.connection.get("accounts/#{id}/limits")
)
@limits ||= Types::AccountLimits.cast(self.class.connection.get("accounts/#{id}/limits"))

@trevornelson trevornelson force-pushed the trevor/ret-3414-show-ach-limits-in-the-dashboard branch 3 times, most recently from 24d97bc to c60a721 Compare October 8, 2024 22:28
@trevornelson trevornelson force-pushed the trevor/ret-3414-show-ach-limits-in-the-dashboard branch from c60a721 to 98a975b Compare October 9, 2024 20:29
@trevornelson trevornelson merged commit a73988f into main Oct 9, 2024
2 checks passed
@trevornelson trevornelson deleted the trevor/ret-3414-show-ach-limits-in-the-dashboard branch October 9, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants