Skip to content

[ZL-887] Use Procore Ruby SDK#14

Merged
njbbaer merged 22 commits intomasterfrom
ruby-sdk
Mar 15, 2021
Merged

[ZL-887] Use Procore Ruby SDK#14
njbbaer merged 22 commits intomasterfrom
ruby-sdk

Conversation

@njbbaer
Copy link
Copy Markdown
Collaborator

@njbbaer njbbaer commented Feb 26, 2021

Ticket: ZL-887

This PR rewrites and simplifies the sample app by using the Procore Ruby SDK.

@njbbaer njbbaer self-assigned this Feb 26, 2021
@njbbaer njbbaer marked this pull request as ready for review March 11, 2021 08:14
@njbbaer
Copy link
Copy Markdown
Collaborator Author

njbbaer commented Mar 11, 2021

I'm finally ready to open this up for review 🎉

@njbbaer
Copy link
Copy Markdown
Collaborator Author

njbbaer commented Mar 11, 2021

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.

Copy link
Copy Markdown

@claudioprocore claudioprocore left a comment

Choose a reason for hiding this comment

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

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.

Comment thread .gitignore Outdated
# # Store the parsed response in an instance variable
# @me = JSON.parse(get_me)
# Store the parsed response in an instance variable
@me = request.body
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does this body look like?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From docs https://developers.procore.com/reference/rest/v1/me

{
  "id": 160586,
  "login": "exampleuser@website.com",
  "name": "Carl Contractor"
}

Comment thread app/views/layouts/_flash_message.html.erb Outdated
<% end %>
</ul>
<%= render "layouts/nav_bar" %>
<%= render "layouts/flash_message" %>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 😉

Comment thread app/controllers/login_controller.rb Outdated
# 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."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread app/controllers/login_controller.rb Outdated
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."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is Procore::Error?

Is it something that could be solved by trying again?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The message includes more information now:
Screen Shot 2021-03-15 at 12 28 18 AM

Comment thread app/controllers/login_controller.rb Outdated
# redirect_to login_index_path, danger: "Something went wrong. Please try again."
# end
# end
rescue_from Procore::Error do |exception|
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By default, Rails clears flash messages once they are displayed.

Is there anything that wasn't cleared by the code above?

Copy link
Copy Markdown
Collaborator Author

@njbbaer njbbaer Mar 12, 2021

Choose a reason for hiding this comment

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

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.

rescue Procore::Error
flash[:danger] = "Something went wrong. Please try again."
end

Comment thread app/views/users/home.html.erb Outdated

<div class="form-group">
<label for="version">Version:</label>
<input id="version" type="text" name="version" placeholder="v1.0">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this tag need a closing tag or a self-closing />?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 njbbaer changed the title [WIP] Use Procore Ruby SDK [ZL-887] Use Procore Ruby SDK Mar 11, 2021
Comment thread app/controllers/users_controller.rb Outdated
@gilmcquillan
Copy link
Copy Markdown

@njbbaer I think the README.md needs to be reviewed and updated.

Copy link
Copy Markdown

@davismartin davismartin left a comment

Choose a reason for hiding this comment

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

overall LGTM just one small question

The only other things I might add is

  1. 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.
  2. 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

Comment thread app/controllers/application_controller.rb Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
@njbbaer
Copy link
Copy Markdown
Collaborator Author

njbbaer commented Mar 15, 2021

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.

@njbbaer
Copy link
Copy Markdown
Collaborator Author

njbbaer commented Mar 15, 2021

@claudioprocore @gilmcquillan @davismartin Thanks for all your great comments. I think I've addressed them all, please respond and rereview.

@njbbaer njbbaer merged commit c5deb80 into master Mar 15, 2021
@njbbaer njbbaer deleted the ruby-sdk branch March 15, 2021 21:19
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.

4 participants