Code Monkey home page Code Monkey logo

blog-webhook-api's Introduction

Blog Webhook API

Python FastAPI Databases PyDantic Google Cloud SQLAlchemy Ghost GitHub Last Commit GitHub Issues GitHub Stars GitHub Forks

Blog Webhook API

Webhook-driven API to make maintaining blogs easier. Dynamically handles optimizations including image compression, content sanitation, alerting, and feature enablement via data aggregate (suggested searches, trending posts, etc)

Installation

Get up and running with make deploy:

git clone https://github.com/toddbirchard/blog-webhook-api.git
cd blog-webhook-api
make deploy

Endpoints

Posts

Endpoints to guarantee published posts have proper metadata & embedded URLs.

  • GET /posts/: Bulk update metadata for all posts where applicable. Supports meta titles, og titles & descriptions, and feature images.
  • POST /posts/: Populate metadata for a single post upon publish. Supports meta title, og title & description, and feature image.
  • GET /posts/backup: Fetch JSON backup of all blog data

Analytics

Aggregate data from Google Cloud & Algolia to power “trending” widgets.

  • GET /analytics/: Export site analytics from a data warehouse to a SQL database. Useful for trend-related features ie: "trending this week" widget.
  • GET /analytics/searches/: Fetch top Algolia search queries for the current week. Export results to a “trending searches” SQL table, as well as historical searches.

Image Optimization

Ensure all posts have retina, mobile, and webp variants.

  • POST /images/: Upon post creation, generate optimized retina and mobile variants of post ‘feature_image’ if they do not exist.
  • GET /images/: Generates both retina and mobile varieties of all images in a remote CDN directory. Defaults to directory containing images uploaded within current month, or accepts a ?directory= parameter which accepts a path to recursively optimize images on the given CDN.
  • GET /images/sort: Transverses CDN in a given directory (?directory=) to organize images into subdirectories based on image type (retina or mobile).

Accounts

Handle user account creation & interactions.

  • POST /account/: Create Ghost member from Netlify Auth service (supports auth providers Github, Google, etc.)
  • POST /account/comment/: Accept user-submitted comments for posts. Each submission notifies the post’s author via a Mailgun email.
  • POST /account/comment/upvote/: Increment (or de increment) a comment’s upvote count by 1, with maximum 1 vote per user.

Donate

  • POST /donation/: Adds BuyMeACoffee donation to a historical ledger.
  • DELETE /donation/: Delete a BuyMeACoffee donation from historical ledger.
  • GET /donation/: Get all BuyMeACoffee donations.

Newsletter

Logistics of adding or removing newsletter subscriptions.

  • POST /subscription/: Send welcome email to newsletter subscribers via Mailgun.
  • DELETE /subscription/: Track newsletter unsubscribe events.

Authors

Insight to scenarios where Authors likely need assistance.

  • GET /authors/updated/: Update all authors to have correct CDN urls & sanitized metadata.
  • POST /authors/post/created/: Notify site editor when posts are ready for review
  • POST /authors/post/updated/: Notify original post author when a peer edits a post.

Github

Notifications when user activity is made on project repos.

  • POST /github/pr/: Trigger SMS notification when contributors open a Github PR in a specified Github org.
  • POST /github/issue/: Trigger SMS notification when contributors open a Github issue in a specified Github org.

blog-webhook-api's People

Contributors

dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar toddbirchard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wporganizer

blog-webhook-api's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

FastAPI: Utilize FastAPI's `SQLModel` & `Databases` Plugins

FastAPI Database Libraries

The implementation of FastAPI sister libraries SQLModel and Databases is highly optional. These libraries intend to improve developer experience; they are not required, nor do they offer significant performance benefits.

1. https://sqlmodel.tiangolo.com/

Extends SQLAlchemy’s “model” object with Pydantic syntax to avoid code duplication between Models and Schemas. Such duplication is otherwise nearly inevitable per FastAPI’s default pattern of defining SQLAlchemy https://fastapi.tiangolo.com/tutorial/sql-databases/?h=database#create-sqlalchemy-models-from-the-base-class alongside https://fastapi.tiangolo.com/tutorial/sql-databases/?h=database#create-sqlalchemy-models-from-the-base-class. Such duplication already exists in database/models.py and database/schemas.py, respectively.

2. https://fastapi.tiangolo.com/how-to/async-sql-encode-databases/?h=database#import-and-set-up-databases

FastAPI’s databases library allows predefined SQLAlchemy database models to build API responses defined solely via ORM queries. This is somewhat similar to the native Django behavior of defining model-based views (such as /list/[MODEL_NAME].

┆Issue is synchronized with this Jira Story

Comment creation fails spectacularly

  • All new comments fail due to mailgun
  • No meaningful messages are logged
  • Every request returns inaccurate 200 response code along with incorrect description

┆Issue is synchronized with this Jira Bug

Bump Project Python version to 3.10

​Known Issues

I. Running locally fails to start

Running locally via {{unicorn }}results in the following error:

TypeError: cannot pickle _cffi_backend.FFI object

The make run command previously bypassed the usage of ASGI in development by instantiating the app via Python directly: python -m main.py.

Reverting changes to make run will likely resolve the issue, as main.py already handles uvicorn instantiation via uvicorn.run().

II. Poetry Update fails from apparent timeouts

Poetry fails to resolve package via “pythonhosted.” Attempting to install or update packages via poetry results in infinite failed requests.

Potential resources:

┆Issue is synchronized with this Jira Story

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

┆Issue is synchronized with this Jira Task

Analytics: Consume ‘Plausible’ API for site metrics

Fails as follows:

  • Plausible API returns list of top-visited URLs
  • Logic attempts to fetch corresponding post per URL from ghost admin api
    • “pages” and “posts” are considered different entities
    • Failure to filter page slugs results in error

┆Issue is synchronized with this Jira Bug

New Endpoint

Changes which require a new API endpoint to be created.

Analytics: Create data models for analytics fetched from Plausible & persist via ORM

  • Refactor & cleanup
    • Handle “weekly” and “monthly” analytics as separate endpoints
      • /analytics/weekly
      • /analytics/monthly
      • Point Ghost webhooks to both endpoints
    • Ensure “null” results are never included
  • Define new models & schemas
    • Create FastAPI Pydantic model representing each PageInsight
    • Create SQLAlchemy model representing each PageInsight
    • Modify SQL schema to handle additional insights (bounce rate, visitors, avg duration, etc.)
  • Persist
    • Store results via DB session after fetching (handle in same endpoint)

┆Issue is synchronized with this Jira Story

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.