Skip to content

Instantly share code, notes, and snippets.

@TrentBrown
Last active July 25, 2016 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrentBrown/5623671 to your computer and use it in GitHub Desktop.
Save TrentBrown/5623671 to your computer and use it in GitHub Desktop.
FileThis Notification API

FileThis Change Notification

FileThis provides a notification system which allows clients to receive notifications when the resources exposed in our API change state (eg. accounts, connections, etc).

Each subscription to the notification system specifies a resource pattern that closely matches the REST paths used by the FileThis Resource API.

When a subscriber responds successfully to a notification request, the set of resource change notifications in the request will all be removed from the FileThis notification queue. If the client does not respond, or responds with a failure code, FileThis will try again to deliver the notifications, with an exponential-backoff to increase the interval of time between attempts.

The schemas below are defined using JSON Schema.

Examples can be validated against schemas here.

Notification Schema:

{
    "title": "Notifications",
    "type": "array",
    "items": 
    {
        "title": "Notification",
        "type": "object",
        "properties":
        {
            "pattern":
            {
                "description": "The resource pattern subscribed to",
                "type": "string",
                "required": true
            },
            "matches":
            {
                "description": "Changed resources that match the pattern",
                "type": "array",
                "required": true,
                "items": 
                {
                    "title": "match",
                    "type": "object",
                    "properties":
                    {
                        "match":
                        {
                            "description": "A changed resource",
                            "type": "string",
                            "required": true
                        },
                        "resources":
                        {
                            "type": "array",
                            "required": true,
                            "items": 
                            {
                                "title": "resource",
                                "type": "object",
                                "properties":
                                {
                                    "name":
                                    {
                                        "type": "string",
                                        "required": true
                                    },
                                    "value":
                                    {
                                        "type": "string",
                                        "required": true
                                    }
                                }
                            }
                        },
                        "timestamp":
                        {
                            "description": "When resource changed",
                            "type": "date",
                            "required": true
                        }
                    }
                }
            }
        }
    }
}

Notification example

This example contains notifications for the resource change pattern /account//connections//state. This matches changes to the state property of connections. The state property of a connection is an enumeration that can have values such as waiting, connecting, question, and error. These changes may be of interest for providing feedback to users.

[
    {
        "pattern": "/account/*/connections/*/state",
        "matches":
        [
            {
                "match": "/accounts/123/connections/456/state",
                "resources":
                [
                    {
                        "name": "accounts",
                        "value": "123"
                    },
                    {
                        "name": "connections",
                        "value": "456"
                    },
                    {
                        "name": "state",
                        "value": "error"
                    }
                ],
                "timestamp": "2013-05-02T00:54:06.655Z"
            }
        ]
    }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment