Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basementuniverse/jsonpad-realtime-js
jsonpad Realtime API connector
https://github.com/basementuniverse/jsonpad-realtime-js
Last synced: 23 days ago
JSON representation
jsonpad Realtime API connector
- Host: GitHub
- URL: https://github.com/basementuniverse/jsonpad-realtime-js
- Owner: basementuniverse
- License: mit
- Created: 2015-06-01T09:22:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-02T06:45:43.000Z (over 9 years ago)
- Last Synced: 2024-04-14T04:43:11.438Z (9 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonpad Realtime API connector
This is a Javascript connector for the [jsonpad](https://jsonpad.io) Realtime API, which allows you to get realtime updates when lists and items change.
See the [jsonpad Realtime API Documentation](https://jsonpad.io/docs-realtime) for more information on the jsonpad Realtime API.
## Installation
To install this script manually, just download the [latest release](https://github.com/basementuniverse/jsonpad-realtime-js/releases).
Then, include the `jsonpadrealtime.js` file in your page:
## Getting started
Here's an example of how to get started:
var jsonpad = jsonpadRealtime.create("username", "realtimetoken");
// Watch all events
jsonpad.watch(function(objectId, eventData, eventType) {
console.log(
"An event occurred! Object ID: %s\nEvent data: %O\nEvent type: %s",
objectId,
eventData,
eventType
);
});
// Watch a particular list for events (and filter events for "list-update" only)
jsonpad.watchList(
"listname",
function(objectId, eventData, eventType) {
// ...
},
["list-update"]
);
// Watch a particular item for events (and filter events for "list-delete" or
// "item-delete" only)
jsonpad.watchItem(
"itemid",
function(objectId, eventData, eventType) {
// ...
},
["list-delete", "item-delete"]
);## Documentation
The `jsonpadRealtime` object has 3 functions:
### .watch(_callback_ [, _events_])
`callback` A function that will be called when an event occurs. This function should take 3 arguments:- `objectId` The name/id of the list/item affected by the event.
- `eventData` An object containing information associated with the event.
- `eventType` A string containing the type of event that occurred.`events` An optional array of event types to watch for. See [jsonpad Realtime API Documentation](https://jsonpad.io/docs-realtime#Filtering-events) for a list of event types.
### .watchList(_listName_, _callback_ [, _events_])
`listName` The name of the list to watch.
`callback` A function that will be called when an event occurs on the list being watched.
`events` An optional array of event types to watch for.
### .watchItem(_itemId_, _callback_ [, _events_])
`itemId` The id of the item to watch.
`callback` A function that will be called when an event occurs on the item being watched.
`events` An optional array of event types to watch for.