Skip to content

Instantly share code, notes, and snippets.

@jake-nz
Created June 3, 2015 21:20
Show Gist options
  • Save jake-nz/b89cefc25515cae3c3d4 to your computer and use it in GitHub Desktop.
Save jake-nz/b89cefc25515cae3c3d4 to your computer and use it in GitHub Desktop.
Snapr FX Live Updates

Live Filter & Sticker Pack Updates

Packs

Pack JSON has some new fields for the live update process:

  • id
  • project-slug
  • size - Human readible size of pack with all assets. Eg. "5mb"
  • etag - This is supplied in the HTTP ETag header but provided in the JSON as well.

Checking for new packs

Request the latest pack: https://fx.sna.pr/projects/ project-slug / filter or sticker-packs/latest/ filter or sticker-pack.json

https://fx.sna.pr/projects/cool-cat/sticker-packs/latest/sticker-pack.json

To make this as efficient as possible we use ETags. Requests for latest should include the If-None-Match header. If there is no pack update the server will respond with HTTP 304 (Not Modified). Otherwise the new JSON will be returned with a new ETag in the HTTP ETag header. (See example below)

Use the JSON file contents to find and download the assets.

Assets

Assets are located relative to the JSON file.

You should use the pack ID, not 'latest' - if a new pack is released while you are downloading assets 'latest' will change and break your download.

https://fx.sna.pr/projects/cool-cat/sticker-packs/3/cover.png https://fx.sna.pr/projects/cool-cat/sticker-packs/3/assets/hat.png https://fx.sna.pr/projects/cool-cat/sticker-packs/3/assets/thumbs/hat.png

https://fx.sna.pr/projects/hipster/filter-packs/7/cover.png https://fx.sna.pr/projects/hipster/filter-packs/7/filters/rainbow/filter.json https://fx.sna.pr/projects/hipster/filter-packs/7/filters/rainbow/thumb.png https://fx.sna.pr/projects/hipster/filter-packs/7/filters/rainbow/vignette.png

Pack URLs

A specific pack JSON can be requested from this URL: https://fx.sna.pr/projects/ project-slug / filter or sticker-packs/ pack-id / filter or sticker-pack.json

https://fx.sna.pr/projects/cool-cat/sticker-packs/3/sticker-pack.json https://fx.sna.pr/projects/hipster/filter-packs/7/filter-pack.json

Example Process

  1. User downloads cool-cat app with filter pack included. (filter-pack.json contains "etag": "65g4")
  2. User opens app
  3. App requests https://fx.sna.pr/projects/cool-cat/filter-packs/latest/filter-pack.json with HTTP Header If-None-Match: "65g4"
  4. Server returns HTTP 304
  5. After 1 day, user opens app again
  6. App requests https://fx.sna.pr/projects/cool-cat/filter-packs/latest/filter-pack.json with HTTP Header If-None-Match: "65g4"
  7. Server returns HTTP 200 and new JSON
  8. App tells user 'A new filter pack is available (5mb), would you like to downlaod it now?'
  9. App uses JSON contents to find and download all assets in the pack.
  10. Once downloads have succeeded the old pack is replaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment