Skip to content

Add People API resource (Phase 2 - v0.2.0)#5

Merged
ebrett merged 6 commits intomainfrom
feature/nb-agv-people-api-resources
Dec 5, 2025
Merged

Add People API resource (Phase 2 - v0.2.0)#5
ebrett merged 6 commits intomainfrom
feature/nb-agv-people-api-resources

Conversation

@ebrett
Copy link
Owner

@ebrett ebrett commented Dec 5, 2025

Summary

Implements Phase 2 of the gem roadmap by adding the People API resource wrapper using V2 API endpoints with JSON:API format. This provides a clean, resource-based interface for working with NationBuilder people data instead of requiring raw HTTP calls.

New Methods:

  • client.people.show(id, include_taggings: false) - Fetch person details (V2 API)
  • client.people.taggings(id) - Get person's tags/subscriptions (V2 API with sideloading)
  • client.people.rsvps(id, include_event: true) - Get event RSVPs (V2 API, JSON:API format)
  • client.people.activities(id) - Get recent activities (V1 API - V2 not yet available)

V2 API Migration

Updated to use V2 endpoints per NationBuilder documentation stating that V1 People API is deprecated:

Method Old (V1) New (V2) Format
show() /api/v1/people/:id /api/v2/people/:id JSON:API
taggings() /api/v1/people/:id/taggings /api/v2/people/:id?include=taggings JSON:API sideloading
rsvps() N/A /api/v2/event_rsvps JSON:API (already V2)
activities() /api/v1/people/:id/activities Same (V2 not available yet) V1 format

Response Format

V2 JSON:API Format:

{
  data: {
    type: "person",
    id: "123",
    attributes: { first_name: "John", ... }
  },
  included: [
    { type: "tagging", id: "1", attributes: { tag: "volunteer" } }
  ]
}

Implementation Details

  • ✅ Created Resources::Base class for HTTP method delegation
  • ✅ Implemented Resources::People with V2 endpoints
  • ✅ Added client.people accessor method
  • ✅ Support for sideloading taggings via include_taggings parameter
  • ✅ Comprehensive test coverage (18 specs for People, 177 total, 100% pass rate)
  • ✅ Updated README with V2 usage examples and JSON:API format
  • ✅ Bumped version from 0.1.0 → 0.2.0
  • ✅ All existing tests continue to pass (92.32% coverage)
  • ✅ Fixed StandardRB linting issue (safe navigation operator)

Test Plan

  • All People resource specs pass (18/18)
  • Full test suite passes (177 examples, 0 failures)
  • Code coverage above 90% threshold (92.32%)
  • Linter passing (StandardRB)
  • README updated with V2 examples
  • Version bumped to 0.2.0
  • All CI checks passing

Breaking Changes

Response format changed from V1 to V2 (JSON:API):

  • show(): Returns { data: { type: "person", id: "123", attributes: {...} } } instead of { person: {...} }
  • taggings(): Returns JSON:API format with included array instead of { results: [...] }
  • Consuming apps will need to update parsing logic to handle JSON:API format

Related Issues

  • Closes citizen-agv
  • Unblocks citizen-0b0 (Refactor NationBuilderApiService to use gem)
  • Unblocks citizen-fey (Update WebMock stubs)
  • Unblocks citizen-5 (Profile viewing feature)

Documentation

🤖 Generated with Claude Code

ebrett and others added 6 commits December 4, 2025 10:25
Extract low-level HTTP request logic into shared HttpRequest module that
both OAuth and HttpClient can use. This provides consistent logging and
error handling for all HTTP operations including OAuth token exchanges.

Changes:
- Created lib/nationbuilder_api/http_request.rb with post_form method
- Updated OAuth.exchange_code_for_token to accept logger parameter
- Updated OAuth.refresh_access_token to accept logger parameter
- Replaced direct Net::HTTP calls in OAuth with HttpRequest.post_form
- Updated Client and HttpClient to pass logger to OAuth methods

Benefits:
- OAuth token requests/responses now logged consistently with API calls
- Centralized error handling for network errors across all HTTP operations
- Easier to add future HTTP-level features (retries, metrics, etc.)

All 159 tests passing with 92.51% coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements the People resource wrapper with four key methods:
- people.show(id) - Fetch person details via V1 API
- people.taggings(id) - Get person's tags/subscriptions via V1 API
- people.rsvps(id) - Get event RSVPs via V2 API with JSON:API format
- people.activities(id) - Get recent activities via V1 API

Implementation details:
- Created base resource class for common HTTP method delegation
- Added resources module with autoloading
- Client class now exposes people accessor method
- Comprehensive test coverage (17 specs, all passing)
- Updated README with People API examples
- Bumped version to 0.2.0

This addresses the need for cleaner API interactions in consuming
applications by providing a resource-based interface instead of
raw HTTP calls.

Related: citizen-agv

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Apply safe navigation operator (&.) instead of if-check for logger.
This addresses the Style/SafeNavigation cop warning.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Update People resource to use V2 API endpoints with JSON:API format:
- people.show() now uses /api/v2/people/:id (was /api/v1)
- people.taggings() now uses V2 with sideloading (was /api/v1)
- people.rsvps() already using V2 ✓
- people.activities() still uses V1 (V2 not yet available)

Changes:
- Added include_taggings parameter to show() for sideloading
- Updated taggings() to use V2 sideloading on person endpoint
- Updated all specs to match V2 JSON:API format (18 specs passing)
- Updated README with V2 examples and format clarification
- Added TODO comment for activities V2 migration

V1 People API is deprecated per NationBuilder documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ebrett ebrett merged commit 250a26a into main Dec 5, 2025
3 checks passed
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.

1 participant