-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add deposit account limits API resource #43
Conversation
f0149a4
to
8007226
Compare
lib/unit-ruby/account_limits.rb
Outdated
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def extract_base_resource_details(data) |
There was a problem hiding this comment.
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.
8007226
to
7455235
Compare
There was a problem hiding this 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
lib/unit-ruby/account_limits.rb
Outdated
@@ -0,0 +1,108 @@ | |||
module Unit | |||
class AccountLimits < APIResource |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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 👍 👍
lib/unit-ruby/deposit_account.rb
Outdated
return @limits if @limits | ||
|
||
@limits = Types::AccountLimits.cast( | ||
self.class.connection.get("accounts/#{id}/limits") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")) |
24d97bc
to
c60a721
Compare
c60a721
to
98a975b
Compare
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:ach
orcheckDeposit
). 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.