Conversation
|
I'm finally ready to open this up for review 🎉 |
|
I just need to make sure the latest version of the Ruby SDK is being used once procore-oss/ruby-sdk#39 has been released. |
claudioprocore
left a comment
There was a problem hiding this comment.
Hello there!
The title of this PR is "[WIP] Use Procore Ruby SDK" and the description says that this "is currently a work in progress." so I'm not sure if this was ready for review.
Meanwhile, I left some inline comments based on the existing commits.
| # # Store the parsed response in an instance variable | ||
| # @me = JSON.parse(get_me) | ||
| # Store the parsed response in an instance variable | ||
| @me = request.body |
There was a problem hiding this comment.
From docs https://developers.procore.com/reference/rest/v1/me
{
"id": 160586,
"login": "exampleuser@website.com",
"name": "Carl Contractor"
}| <% end %> | ||
| </ul> | ||
| <%= render "layouts/nav_bar" %> | ||
| <%= render "layouts/flash_message" %> |
There was a problem hiding this comment.
Rails normally refers to layouts as something that "wraps around" the content to display.
For instance, this file is a layout because it renders the head and then <%= yield %> to the content.
Instead, portions of HTML rendered inside another view are called partials.
So I would suggest renaming these files to partials.
There was a problem hiding this comment.
They aren't layouts, but they're also only used by application.html.erb which is a layout. So I figure it's logical to put them in the same folder, like you might put partials next to /users if they were only used on that page. Partials are prefixed by an _ to distinguish them.
I'll also point out Dev Portal puts some partials in /layouts and doesn't have a /partials directory. Doesn't make it right though 😉
| # Redirects user back to the login page | ||
| redirect_to login_index_path, success: "Token was successfully revoked" | ||
| rescue Procore::Error | ||
| redirect_to login_index_path, danger: "Something went wrong. Please try again." |
There was a problem hiding this comment.
Could this cause an infinite loop?
Let me explain: the login_index is displayed to users who are not logged in.
But in this case, if client.revoke raises a Procore::Error, then the reset_sessions line is skipped.
Therefore the user might still have a session, which would try to redirect the user out of the login_index page and possibly cause an infinite redirection.
There was a problem hiding this comment.
That's a good thought, but it isn't a problem because having a session does not cause the user to be redirected out of login_index. They could log in twice, regardless of whether they still have a session.
| redirect_to users_home_path | ||
| redirect_to users_home_path, success: "Access token granted." | ||
| rescue Procore::Error | ||
| redirect_to login_index_path, danger: "Something went wrong. Please try again." |
There was a problem hiding this comment.
What is Procore::Error?
Is it something that could be solved by trying again?
There was a problem hiding this comment.
It's any error from the RubySDK. If this happens something is probably misconfigured, so trying again wouldn't help. I can remove that part.
There was a problem hiding this comment.
There's a list of error types here: https://github.com/procore/ruby-sdk#error-handling
I'm going to change it to print out the message, so the user has more information about what went wrong.
| # redirect_to login_index_path, danger: "Something went wrong. Please try again." | ||
| # end | ||
| # end | ||
| rescue_from Procore::Error do |exception| |
There was a problem hiding this comment.
I saw in the previous commit that Procore::Error was specifically rescued by several controlleres.
What is the case for this "generic" rescue_from?
Which actions might raise a Procore::Error but don't rescue it?
There was a problem hiding this comment.
It's a generic error from the RubySDK. Anything that's making an API request with the SDK could raise it, and those should all be rescued.
| </div> | ||
| <% end %> No newline at end of file | ||
| <% end %> | ||
| <% flash.clear %> No newline at end of file |
There was a problem hiding this comment.
By default, Rails clears flash messages once they are displayed.
Is there anything that wasn't cleared by the code above?
There was a problem hiding this comment.
I found /users/me was not clearing errors. I think this is because they only gets cleared on a redirect, and it doesn't redirect. Let me know if there is a better way to handle this.
Procore-Sample-ROR/app/controllers/users_controller.rb
Lines 12 to 14 in 129277b
|
|
||
| <div class="form-group"> | ||
| <label for="version">Version:</label> | ||
| <input id="version" type="text" name="version" placeholder="v1.0"> |
There was a problem hiding this comment.
Does this tag need a closing tag or a self-closing />?
There was a problem hiding this comment.
Input is a void element, so it doesn't require a closing tag. Most examples don't seem to use it either: https://www.w3schools.com/tags/tag_input.asp
|
@njbbaer I think the README.md needs to be reviewed and updated. |
davismartin
left a comment
There was a problem hiding this comment.
overall LGTM just one small question
The only other things I might add is
- it might be nice to update the readme. To call out this uses the ruby-sdk and also might be nice to guide a user to what they need setup in procore client_id/secret/redirect_uri just to make sure that is setup correctly.
- It might be nice to default the api request to a certain value so when the user auth successfully they can just hit submit and see it working
It would be a nice feature, but I ran into a problem where the default was overwriting the current request. I'm sure it can be fixed, but I'm just going to skip it for now so since it's low value. |
|
@claudioprocore @gilmcquillan @davismartin Thanks for all your great comments. I think I've addressed them all, please respond and rereview. |

Ticket: ZL-887
This PR rewrites and simplifies the sample app by using the Procore Ruby SDK.