Skip to content

Add a JSON API to create social media snippets for a link #42

Closed

Description

@etagwerker

Librarian already stores per-article social copy in social_media_snippets (link_id, social_media_type, content) and shows it on the link page and in GET /links/:id.json. Since #39 removed the ChatGPT step, nothing writes new snippets, and there is no route to create one over the API.

We now draft social copy outside Librarian (several variants per channel for each new article) and want to store it back in Librarian next to the article.

Proposal

  • Route: resources :social_media_snippets, only: [:index, :create] nested under links, giving GET and POST /links/:link_id/social_media_snippets.json.
  • Auth: the same personal access token login SharesController uses.
  • Params: social_media_snippet[social_media_type] (one of LinkedIn, Mastodon, Bluesky, GoogleBusiness, Twitter), and social_media_snippet[content] (required).
  • Validations: content present, and social_media_type from a list (a constant like Share::UTM_SOURCES).
  • Duplicates: reject an exact duplicate (link_id, social_media_type, content) with 422 so client retries are safe.
  • Responses: 201 with { id, link_id, social_media_type, content, created_at }; 422 with { errors: [...] }, matching SharesController.
  • Index: returns the link's snippets as JSON, optionally filtered by ?social_media_type=.

Out of scope

Generating copy inside Librarian (the client writes it), and editing or deleting snippets (the web UI can come later).

Acceptance

  • Request specs for 201, 422 on missing content, 422 on an unknown type, 422 on a duplicate, and 401 without a token.
  • Snippets created this way show up on the link page and in GET /links/:id.json.

Edit: dropped the optional share_id and its migration. social_media_snippets already has the columns the API needs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions