Repository navigation
Replace rest-client with Faraday, require Ruby 3.3, fix spec mismatches - #92
Closed
posiczko-ferret wants to merge 18 commits into
Closed
posiczko-ferret wants to merge 18 commits into
posiczko-ferret wants to merge 18 commits into
Conversation
Ensure pstore is a explicit dependency when ruby used is >= 4. Ruby 4 removes pstore from stdlib. Ruby 3 uses pstore from stdlib.
Replaced the OpenStruct objects with Structs on OAuthError, DuckResponse and DuckRequest. They use keyword_init: true because the gem still supports Ruby 3
…o require Ruby >= 3.3 Drop EOL-ed rubies <= 3.2
YAML in ruby up to 3.3 reads the file with unsafe_load, which accepts any class, while from 3.4 on, it uses safe_load and only allows Symbol. One way to fix this mess would be to save tokens as hashes and rebuild Token on read. This would break token files written by old gems & require migrating. Instead, subclass YAML::Store, allow old style loading of expires_at (Time) and Procore::Auth::Token for backward compatibility.
- Add `redact` method to replace Bearer tokens with `###` in logs for security. - Introduce tests to verify Bearer token redaction for `log_info`, `log_error`, and token handling in requests. - Fix `delete` request to include dynamic headers from `options`. - Add tests for `delete` with `company_id` and response request matching RestClient values. - Refactor constants and logging methods for maintainability.
- Migrated HTTP logic in `Requestable` from RestClient to Faraday with multipart and retry middleware. - Introduced `Procore::Request` to expose request details while maintaining compatibility with existing behavior. - Updated error handling and connection retries to utilize Faraday's features. - Expanded test coverage, including response metadata, redirects, and retry scenarios. - Adjusted dependencies in `procore.gemspec` to remove RestClient and add Faraday-related gems.
….md for supported Ruby versions
- Set `TargetRubyVersion` to 3.3 and disable `NewCops`. - Replace deprecated cops with their updated equivalents (e.g., `Style/FlipFlop` to `Lint/FlipFlop`). - Adjust options like `ExcludedMethods` to `AllowedMethods`. - Disable Rails-specific cop `Rails/RakeEnvironment`, as the project is a gem. - Refine layout and naming configurations for consistency.
- **Breaking:** Drop support for Ruby < 3.3 (EOL). Require Ruby 3.3+. - **Breaking:** Replace `rest-client` with `Faraday` (`Procore::Request`, improved error handling, TLS/dns failure reporting). - Fix token revoke errors raising `OAuth2::Error` instead of `Procore::OAuthError`. - Fix request logging to include `X-Request-Id` and redact sensitive tokens. - Fix DELETE requests ignoring `options` (e.g., `Procore-Company-Id`). - Add Ruby 3.4/4.0 support (replace `OpenStruct` with `Struct`, add `pstore`, YAML compatibility in `File` store).
The gem only required active_support/hash_with_indifferent_access but
used three core extensions it never loaded. Without a full ActiveSupport
load, the Session, Redis and Dalli stores serialized a token as
"#<Procore::Auth::Token:0x...>" so every request raised
MissingTokenError, sync raised NoMethodError on deep_merge, and
OAuthError raised NoMethodError on presence.
Give Token an explicit to_h/to_json, require the two remaining
extensions where they are used, and require activesupport >= 7.0.
Covered by subprocess tests that load the gem with nothing else.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The raw body defaulted to "{}".to_json, which is the JSON string
literal "\"{}\"", so a 204 No Content response gave a String body.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Response#pagination stripped the rest/vX.Y or vapid prefix from Link header URLs, so client.get(pagination[:next]) always used default_version. Following a next link from a v1.1, v2.0 or vapid response silently requested v1.0. Pagination paths now keep the version segment, and get/delete pass a path that already names its version through without prefixing it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
e.response.errors does not exist; Response exposes the parsed body as e.response.body. Also fix the single-colon Procore:Error rescue. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces rest-client with Faraday, requires Ruby 3.3+, and fixes five bugs found reviewing the gem against Procore's OpenAPI spec. Reasoning for the HTTP client switch is in
docs/adr/0001-replace-rest-client-with-faraday.md.Error mapping for callers:
Bug fixes on top of the migration:
"#<Procore::Auth::Token:0x...>",syncraised ondeep_merge,OAuthErrorraised onpresence."{}".pagination[:next]dropped the API version, so following a v1.1, v2.0 or vapid link requested v1.0.e.response.errorsandrescue Procore:Error, neither of which works.Acceptsinstead ofAccept.deleteignoredcompany_id; DELETE requests logged theAuthorizationheader.Evidence
Before:
rake testonmainpasses, but a bareruby -e 'require "procore"'process shows the breakage the suite hides becausetest_helperloads ActiveRecord:After:
test/procore/standalone_load_test.rbruns those scenarios in a subprocess with onlyrequire "procore".The 3 errors are the Dalli store tests, which need the memcached from
docker-compose.yaml; they pass in CI where memcached is a service.test/procore/rest_client_leakage_test.rbis the migration's acceptance check: nine of its tests failed before the switch and pass now.Merge Danger
Door: two-way until 2.0.0 is pushed to RubyGems. Reverting the merge restores rest-client with no data or external state to unwind.
Blast Radius: consumers
This is the 2.0.0 major. Breaking for gem users:
Response#requestis aProcore::Request, not aRestClient::Request.APIConnectionError#causeandRequestable::HTTP_EXCEPTIONSare Faraday classes; TLS, DNS and unreachable-host failures now raiseAPIConnectionError.Response#paginationpaths include the version segment ("rest/v1.0/projects?page=2").activesupport >= 7.0.RestClienttransitively through this gem must add it themselves.Merging triggers the Release workflow, since
lib/procore/version.rbchanges in this PR. On this fork the RubyGems push step has no credentials and will fail without side effects.Parts generated with Claude Code