Modifications

Sauter à la navigation Sauter à la recherche
2 548 octets ajoutés ,  11 janvier 2015 à 15:55
Page créée avec « {{Spark.IO-Could-API-NAV}} {{traduction}} == Enregistrer un CallBack == {{bloc-etroit|text=In the build section of the Spark website, you will be able to register a URL on... »
{{Spark.IO-Could-API-NAV}}

{{traduction}}

== Enregistrer un CallBack ==

{{bloc-etroit|text=In the build section of the Spark website, you will be able to register a URL on your own server to which we will POST each time one of your Spark Cores publishes a certain event.

{{ambox|text=This feature is still in progress, and will be released later in March.}}
}}

== Souscrire un événement ==
{{bloc-etroit|text=You can make an API call that will open a stream of [http://www.w3.org/TR/eventsource/ Server-Sent Events] (SSEs). You will make one API call that opens a connection to the Spark Cloud. That connection will stay open, unlike normal HTTP calls which end quickly. Very little data will come to you across the connection unless your Spark Core publishes an event, at which point you will be immediately notified.}}

To subscribe to an event stream, make a GET request to one of the following endpoints. This will open a Server-Sent Events (SSE) stream, i.e., a TCP socket that stays open. In each case, the event name filter in the URI is optional. When specifying an event name filter, published events will be limited to those events with names that begin with the specified string. For example, specifying an event name filter of 'temp' will return events with names 'temp' and 'temperature'.

SSE resources:
* http://dev.w3.org/html5/eventsource/
* https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events
* http://www.html5rocks.com/en/tutorials/eventsource/basics/

Subscribe to the firehose of public events, plus private events published by devices one owns:

<nowiki>GET /v1/events[/:event_name]

# EXAMPLE
curl -H "Authorization: Bearer 38bb7b318cc6898c80317decb34525844bc9db55"
https://api.spark.io/v1/events/temperature</nowiki>

Subscribe to all events, public and private, published by devices one owns:

GET /v1/devices/events[/:event_name]

<nowiki># EXAMPLE
curl -H "Authorization: Bearer 38bb7b318cc6898c80317decb34525844bc9db55"
https://api.spark.io/v1/devices/events/temperature</nowiki>

Subscribe to events from one specific device. If the API user owns the device, then she will receive all events, public and private, published by that device. If the API user does not own the device she will only receive public events.

<nowiki>GET /v1/devices/:device_id/events[/:event_name]

# EXAMPLE
curl -H "Authorization: Bearer 38bb7b318cc6898c80317decb34525844bc9db55"
https://api.spark.io/v1/devices/55ff70064939494339432586/events/temperature</nowiki>

{{Spark.IO-Could-API-TRAILER}}
32 920

modifications

Menu de navigation