-
Notifications
You must be signed in to change notification settings - Fork 0
Implement transparent client pattern and middleware error handling #147
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
Conversation
| @client = client || Seam::Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options, | ||
| faraday_retry_options) | ||
|
|
||
| initialize_routes(client: @client, defaults: @defaults) |
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.
What does this do? Why is it defined as a private function but called here?
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.
initialize_routes is an internal method to set up route clients by making available @client and @defaults for them. SingleWorkspace can access private initialize_routes because Routes module gets included in the class. While the method will exist on instances, being private it can only be called internally (inside the class/module methods) and not from outside code, unlike public methods like 'devices', 'access_codes' etc. which can be called by anyone using the instance.
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.
Why is this method needed though vs just putting the code inline? I think I must be missing something obvious.
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.
By including it inline, you mean to include the code bellow in the SingleWorkspace class?
def access_codes
@access_codes ||= Seam::Clients::AccessCodes.new(client: @client, defaults: @defaults)
end
...We could have done that, but we decided to generate route-related stuff, so I placed the clients under the Routes module (which is generated) so that we won't need to manually update the SDK when new namespaces are introduced in the Seam API. Let me know if you have a better approach in mind.
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.
I was wondering why not to just do
@client = client
@defaults = defaults
But now I understand what this is doing. Basically this module only works if mixed into classes that define @client and @defaults. And this method is helping clarify that requirement.
I wonder if there is a more standard pattern to handle this.
I think it may be what this question is asking about https://stackoverflow.com/questions/12586051/initializing-instance-variables-in-mixins
Co-authored-by: Evan Sosenko <evan@getseam.com>
… on the faraday connection builder
Closes #137