Add Response Object Pattern and Complete Resource Implementation#13
Merged
Add Response Object Pattern and Complete Resource Implementation#13
Conversation
Implements nb-5 to wrap API responses in typed objects instead of raw hashes, providing better DX with convenient attribute access and type safety. Added: - ResponseObjects::Base - Base class handling both V1 and V2 API formats - Method access to attributes (person.first_name) - Hash-compatible interface for backward compatibility (person[:data]) - Support for both JSON:API (V2) and plain JSON (V1) formats - ResponseObjects::Person - Person-specific response object - Convenient accessors (first_name, last_name, email, etc.) - Computed attributes (full_name) - Taggings extraction from included data - Configuration option `wrap_responses` (default: false) - Opt-in feature for backward compatibility - Can be enabled globally or per-client instance Integration: - Updated People resource to optionally wrap responses - Response objects are backward compatible with hash access - Comprehensive RSpec tests (40 new examples) Benefits: - Better developer experience with typed objects - Convenient method access instead of deep hash navigation - Backward compatible - doesn't break existing code - Works with both V1 and V2 API responses Test coverage: 93.28% (240 examples, 0 failures) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implements list, create, delete, and search methods for complete People resource. Added methods: - list(page:, per_page:, filter:) - List people with pagination/filtering - create(attributes:) - Create new person - delete(id) - Delete person by ID - search(query, **filter) - Search people by name with additional filters All methods support response object wrapping when enabled. Uses V2 API with JSON:API format. Follows TDD approach with comprehensive tests. Tests: 14 new examples, all passing Coverage: 93.42% Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implements bulk tagging operations for managing supporter segments. Added methods: - bulk_apply(tag_name, person_ids) - Apply tag to multiple people - bulk_remove(tag_name, person_ids) - Remove tag from multiple people Both methods handle empty arrays and return array of responses. Uses V1 API for tag management. Follows TDD approach. Tests: 7 new examples, all passing Coverage: 93.48% Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implements comprehensive resource classes for managing donations and events: - Donations: list, show, create, update operations - Events: list, show, create, update, delete operations with RSVP management - RSVP operations: list, create, update, delete RSVPs for events - All resources follow JSON:API format conventions - 310 tests passing with 93.66% coverage Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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
This PR implements the Response Object Pattern (nb-5) and completes the implementation of four major API resources that were unblocked by it. All changes maintain backward compatibility while providing an improved developer experience through optional response wrapping.
Changes
Response Object Pattern (nb-5)
ResponseObjects::Base: Core wrapper class with hash-compatible interface
person.first_name)person[:data])includeddataResponseObjects::Person: Person-specific response object
full_name)Configuration: New
wrap_responsesoption (default:falsefor backward compatibility)People Resource Extensions (nb-7)
list(page:, per_page:, filter:)- List people with pagination and filteringcreate(attributes:)- Create new person recordsdelete(id)- Delete person recordssearch(query, **filter)- Search people by name and filtersupdate(id, attributes:)- Update person attributes (already existed, now uses response wrapping)Tags Resource Extensions (nb-6)
bulk_apply(tag_name, person_ids)- Apply tag to multiple people efficientlybulk_remove(tag_name, person_ids)- Remove tag from multiple people efficientlyDonations Resource (nb-11)
Complete new resource with full CRUD operations:
list(page:, per_page:, filter:)- List donations with pagination and filteringshow(id)- Fetch single donationcreate(attributes:)- Create new donationsupdate(id, attributes:)- Update existing donationsEvents Resource (nb-1)
Complete new resource with event and RSVP management:
Event operations:
list(page:, per_page:, filter:)- List events with pagination and filteringshow(id, include_rsvps:)- Fetch single event with optional RSVP sideloadingcreate(attributes:)- Create new eventsupdate(id, attributes:)- Update existing eventsdelete(id)- Delete eventsRSVP operations:
rsvps(event_id, include_person:)- List RSVPs for an eventcreate_rsvp(event_id, attributes:)- Create RSVP for an eventupdate_rsvp(rsvp_id, attributes:)- Update existing RSVPdelete_rsvp(rsvp_id)- Delete RSVPV2 API with JSON:API format
V1 API Support (nb-f0q)
list_taggings(id)- Get taggings with tag names (V1 API)add_tagging(id, tag_name)- Add tag to person (V1 API)remove_tagging(id, tag_name)- Remove tag from person (V1 API)Test Coverage
New Test Files
spec/nationbuilder_api/response_objects/base_spec.rbspec/nationbuilder_api/response_objects/person_spec.rbspec/nationbuilder_api/resources/donations_spec.rbspec/nationbuilder_api/resources/events_spec.rbExtended Test Files
spec/nationbuilder_api/resources/people_spec.rb- Added tests for new CRUD operationsspec/nationbuilder_api/resources/tags_spec.rb- Added tests for bulk operationsBackward Compatibility
All changes are backward compatible:
config.wrap_responses = trueUsage Examples
With Response Wrapping Enabled
New Resources
Bulk Tag Operations
Test Plan
Related Beads
Closes: nb-5, nb-7, nb-6, nb-11, nb-1, nb-f0q
🤖 Generated with Claude Code