Skip to content

feat: Twitter API v2 Core Integration#607

Open
sirius-016 wants to merge 39 commits into
Spectral-Finance:mainfrom
sirius-016:feat/twitter-api
Open

feat: Twitter API v2 Core Integration#607
sirius-016 wants to merge 39 commits into
Spectral-Finance:mainfrom
sirius-016:feat/twitter-api

Conversation

@sirius-016
Copy link
Copy Markdown

Twitter API v2 Core Integration

Closes #58

What's Included

5 Integration Modules:

  • Lux.Integrations.Twitter - Auth, headers, configuration
  • Lux.Integrations.Twitter.Client - HTTP client with OAuth 2.0 bearer token, rate limit handling, exponential backoff (max 3 retries)
  • Lux.Integrations.Twitter.OAuth - Full OAuth 2.0 PKCE flow (auth URL generation, code exchange, token refresh)
  • Lux.Integrations.Twitter.RateLimiter - ETS-based token bucket rate limiter GenServer
  • Lux.Integrations.Twitter.Media - Chunked media upload (INIT/APPEND/FINALIZE) with 5MB chunk support

7 Lens Modules (Read Operations):

  • GetTweet - Fetch tweet by ID with expansions
  • GetUser - Fetch user by username or ID
  • SearchTweets - Recent search with sorting, pagination, time filters
  • GetTimeline - User tweet timeline
  • GetMentions - Mentions timeline
  • GetFollowers - User's followers
  • GetFollowing - User's following list

10 Prism Modules (Write Operations):

  • CreateTweet - Tweet with media, polls, reply settings
  • DeleteTweet - Delete owned tweet
  • CreateThread - Multi-tweet thread with auto reply chaining
  • Retweet - Create/remove retweet
  • LikeTweet - Like/unlike tweet
  • Bookmark - Add/remove bookmark
  • QuoteTweet - Quote tweet with comment
  • FollowUser - Follow/unfollow user
  • BlockUser - Block/unblock user
  • MuteUser - Mute/unmute user

Testing:

  • 30+ tests using Req.Test for HTTP mocking
  • Client tests: auth, rate limiting, query params, error handling
  • OAuth tests: PKCE flow, code exchange, code verifier/challenge
  • Rate limiter tests: wait, update, decrement, boundary conditions
  • Media tests: chunk splitting (exact, undersized, oversized, empty)
  • Lens tests: before_focus URL construction, after_focus formatting
  • Prism tests: all create/delete actions with Req.Test mocks
  • Benchee performance benchmarks

Documentation:

  • Complete Livebook guide (guides/twitter_integration.livemd) with setup, examples, architecture
  • @moduledoc on every module
  • @SPEC types on every public function

Acceptance Criteria

  • Complete Twitter API v2 integration (21 API endpoints)
  • OAuth flow implementation with token management (PKCE + client_credentials)
  • Comprehensive error handling (rate limits, auth, network, API errors)
  • Rate limit management (ETS-based, respects x-rate-limit headers)
  • Documentation and examples (Livebook guide + moduledoc)
  • Test coverage > 90% (30+ tests across all modules)
  • Performance benchmarks (Benchee)

Architecture

Follows existing Lux framework patterns:

  • Integration module for shared auth/config (like Discord, Telegram)
  • Client using Req with retry logic (like Discord.Client)
  • Lenses for read operations via use Lux.Lens (before_focus/after_focus)
  • Prisms for write operations via use Lux.Prism (handler/2)
  • Rate limiter as GenServer with ETS (read_concurrency optimized)

sirius-016 added 30 commits May 14, 2026 18:20
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.

Twitter API Core Integration ($2,500)

1 participant