AGENTS.md
This file provides guidance to AI coding agents (Claude Code, GitHub Copilot, etc.) when working with code in this repository.
Project Overview
Unofficial Hatena Blog AtomPub API wrapper library for Rust (edition 2021, not published to crates.io).
Build & Test Commands
cargo build # Build (no default TLS feature; use --features native-tls or rustls-tls)
cargo test # Run all tests
cargo test config::test::config_new # Run a single test by name
cargo test -- --test-threads=1 # Run tests single-threaded (needed for env var tests in config)
cargo run --features native-tls --example list_entries # Run an example (requires env vars, see Config)
IMPORTANT: Always run cargo +nightly fmt after editing code to apply formatting.
Architecture
The library wraps Hatena Blog's AtomPub API with async HTTP calls and Atom XML parsing.
Core flow: Client (HTTP layer) → raw XML String → Response wrapper types (MemberResponse, CollectionResponse, etc.) → parsed Rust types via TryFrom conversions.
Key design decisions:
- Response types are opaque wrappers around raw XML strings (
MemberResponse,CollectionResponse,CategoryDocumentResponse,EmptyResponse). Callers convert to domain types (Entry,Vec<String>, etc.) viaTryFrom. - Two XML parsing strategies coexist:
atom_syndicationcrate for entry/feed parsing (response.rs),quick-xmlfor category document parsing (response.rs:124-222). The entry XML from single-entry responses is wrapped in<feed>tags before parsing withatom_syndication. EntryParams.into_xml()manually builds XML with a custom escape function rather than using a serialization library.Configsupports both explicit construction and loading from environment variables (HATENA_ID,HATENA_BLOG_ID,HATENA_API_KEY,HATENA_BLOG_BASE_URL).- TLS is opt-in via cargo features:
native-tlsorrustls-tls(passed through to reqwest).
Module Responsibilities
client.rs—Clientstruct, HTTP methods (CRUD + list), URL construction, basic authconfig.rs— API credentials and base URL configurationresponse.rs— Response wrapper types, Atom/XML parsing,TryFromconversions to domain typesentry.rs—Entrydomain structentry_params.rs—EntryParamsfor create/update with XML serializationentry_id.rs—EntryIdnewtype wrapperfixed_date_time.rs—FixedDateTimenewtype overchrono::DateTime<FixedOffset>
Coding Conventions
- Newtype pattern for domain primitives (
EntryId,FixedDateTime) withFromStr/Displayimplementations - Error types use
thiserrorderive macros - Tests are inline (
#[cfg(test)] mod test) within each module, not in a separatetests/directory - All public types are explicitly re-exported from
lib.rs(do not use wildcard*re-exports)
Maintaining This File
When making changes that affect conventions, architecture, or build/test commands described in this file, update AGENTS.md in the same changeset to keep it in sync.