Skip to content

Instantly share code, notes, and snippets.

@darkobodnaruk
Last active March 29, 2020 07:13
Show Gist options
  • Save darkobodnaruk/fff5b6d40a43bc049fce734cfb4d4a2e to your computer and use it in GitHub Desktop.
Save darkobodnaruk/fff5b6d40a43bc049fce734cfb4d4a2e to your computer and use it in GitHub Desktop.

Problem

We need changes in the API and Admin endpoint in order to serve content to CME clients. This content will be produced by an external app and stored on S3. A new endpoint is needed for this external app to notify when content has changed.

Suggested changes

Data model

  1. Add two new fields Course model:
  • cme_article_url (string)
  • cme_qa_url (string)

These will point to JSON files hosted on S3.

API

Source file: app/api/cme_api_v1.rb

1) Update endpoint GET courses/:course_name

Update endpoint GET courses/:course_name to serve new fields:

  • cme_article (JSON)
  • cme_qa (JSON)

These fields should contain the actual JSON content located at cme_article_url and cme_qa_url URLs.

2) Fetch JSON content

The JSON content should be fetched from S3 (two requests) when handling the API request, using standard Rails caching, with a duration of 1 hour.

3) New endpoint POST courses/:course_name/update_content

Add new endpoint POST courses/:course_name/update_content. Call to this endpoint forces the cache mentioned in 2) to be refreshed.

This endpoint will be called from an external source, so it should require an api_key param which should match Rails.application.secrets.cme_external_api_key (to be put in secrets.yml).

(See authenticated_by_api_key in app/api/api_helpers.rb and app/api/api_v4.rb for example on how we use api_key).

Admin

  1. Show new editable fields cme_article_url and cme_qa_url in Course edit form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment