This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
BloggerAPI is a Swift package that provides a client library for the Google Blogger API v3. The package is available as both a Swift Package Manager library and a CocoaPod.
- Current branch:
feature/async- Major refactoring to modernize the API with Swift Concurrency (async/await) - Main branch: Contains the legacy callback-based implementation
- Platform: macOS 13+ (uses Swift 6.2 tools version)
# Build the package
swift build
# Run all tests
swift test
# Run a specific test target
swift test --filter BloggerAPITests
# Build for release
swift build -c releaseThe feature/async branch is undergoing a major refactoring. Most implementation files have been deleted and only the Blogger class skeleton remains. This represents a transition from the legacy callback-based architecture to a modern async/await implementation.
The main branch uses a dependency injection pattern with completion handlers:
Core Components:
Blogger: Main entry point for API interactions. Accepts a blog URL, API key, andNetworkFetchprotocol implementationInjector: Singleton-based dependency injection container that manages shared dependencies (API key, fetch handler, blog ID, date formatter)NetworkRequest<T, Result>: Generic base class for all API requests. Handles URL construction, query parameters, and response parsing using Codable
Dependency Injection Pattern:
- Protocols define injectable dependencies:
FetchConsumer,KeyConsumer,BlogIdConsumer,DateFormatterConsumer - Request objects declare conformance to these protocols and receive dependencies through the
Injector - The
InjectionHandlerprotocol + extension pattern enables automatic dependency injection before request execution
Request Flow:
Bloggerclass receives requests (e.g.,fetchUpdates,fetchPost)- Before executing, checks if
blogIdis available; if not, resolves it viaResolveBlogByURLRequest - Creates appropriate request object (e.g.,
ListPostsRequest,RetrievePostRequest) - Injects dependencies via
Injector.sharedInstance.inject(into:) - Request constructs URL with path variables (
:blogId:,:postId:), query parameters, and API key - Executes via injected
NetworkFetchimplementation - Parses JSON response using Codable with custom date formatting
- Invokes completion callback with result
Data Models:
Post: Blog post with id, published date, title, content, images, URLBlog: Blog metadataImage: Post image with URLPostsPage: Paginated response containing posts array and next page tokenNextPageCursor: Pagination state tracking (page token, date filters)
API Requests:
ResolveBlogByURLRequest: Converts blog URL to blog ID (required for other operations)ListPostsRequest: Fetches posts with pagination support (by date or cursor)RetrievePostRequest: Fetches a single post by ID
When implementing async/await:
- Replace
Injectorsingleton with actor-based dependency management or function parameters - Convert
NetworkFetchprotocol to async throws pattern - Replace completion callbacks with async functions returning values or throwing errors
- Use structured concurrency for blog ID resolution flow
- Ensure date formatter thread safety (DateFormatter is not thread-safe, consider using actor isolation)
- Follow Swift Concurrency best practices per ~/.claude/docs/swift-concurrency.md
The package communicates with Google Blogger API v3 at https://www.googleapis.com/blogger/v3.
Authentication: API key-based (passed as key query parameter)
Key Endpoints:
/blogs/:blogId:/posts- List posts with pagination- POST paths follow similar pattern with blog/post ID variables
This package is distributed via:
- Swift Package Manager: Primary distribution method (see Package.swift)
- CocoaPods: See BloggerAPI.podspec (iOS 9.0+)