Skip to content

feat: add models module, API helpers, and Post refactoring#46

Open
svaningelgem wants to merge 1 commit intoma2za:mainfrom
svaningelgem:feat/api-refactor
Open

feat: add models module, API helpers, and Post refactoring#46
svaningelgem wants to merge 1 commit intoma2za:mainfrom
svaningelgem:feat/api-refactor

Conversation

@svaningelgem
Copy link
Copy Markdown

Summary

  • Add models.py with Byline, PostMetadata, ScheduledRelease dataclasses for typed API responses
  • Add schedule_release(), get_post_metadata(), make_post_free() high-level API methods
  • Extract _authenticate() / _resolve_publication() from Api.__init__ for clarity
  • Add _get() / _post() / _put() / _delete() HTTP helpers to reduce boilerplate
  • Add _handle_response(allow_empty=...) for endpoints that return empty bodies on success
  • publish_draft() now auto-runs prepublish validation (matches browser flow)
  • Use pathlib.Path instead of os.path/open for file I/O
  • Add _PRODUCTION_SUBDOMAINS safety guard (empty by default)
  • Add paywall() and add_subscribe_button() to Post builder
  • Refactor Post.add() to use dispatch table instead of if/elif chain
  • Extract _parse_markdown_blocks(), _upload_or_passthrough(), _render_image() from from_markdown()
  • Refactored from_markdown() with horizontal rule support, line merging, and inline heading handling
  • code_block() uses match/case
  • Add type annotations throughout all modules
  • Update MCP server: remove separate prepublish_draft tool (now automatic)

Test plan

  • All 17 existing unit tests pass
  • Manual verification of draft creation / publishing workflow
  • Verify MCP server tools work end-to-end

Generated with Claude Code

- Add models.py with Byline, PostMetadata, ScheduledRelease dataclasses
- Add schedule_release(), get_post_metadata(), make_post_free() to Api
- Extract _authenticate() and _resolve_publication() from __init__
- Add _get/_post/_put/_delete HTTP helpers, refactor all methods to use them
- Add _handle_response allow_empty param with proper error chaining
- Add _PRODUCTION_SUBDOMAINS safety guard
- publish_draft now auto-runs prepublish validation
- Use pathlib.Path instead of os.path/open for file operations
- Post: dispatch table _ADD_HANDLERS replaces if/elif chain
- Post: add paywall() and add_subscribe_button() methods
- Post: extract _parse_markdown_blocks, _upload_or_passthrough, _render_image
- Post: code_block uses match/case, _process_line handles inline headings
- Refactored from_markdown() with HR support and better line merging
- MCP: remove separate prepublish_draft tool (now automatic)
- Add type annotations throughout all modules

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@svaningelgem
Copy link
Copy Markdown
Author

svaningelgem commented Apr 6, 2026

I'm using this API as it is here, so it's tested in the wild already. And I backported my vendorized version to yours.

There were also quite a few issues in markdown that I fixed: "---" -> horizontal line, subscriber button vs subscriber widget, grouping of paragraphs, headerizing everything (although that might have been my own intermediate implementation)

Plus I made the code follow a bit more modern python standards.

Enjoy 😉

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