Class Session
Extends
Resource.
Session Resource
Defined in: session.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Session(spire, data)
Represents a session in the spire api.
|
| Field Attributes | Field Name and Description |
|---|---|
|
Actual data from the spire.io api.
|
|
|
Reference to spire object.
|
| Method Attributes | Method Name and Description |
|---|---|
|
account(cb)
Gets the account resource.
|
|
|
account$(cb)
Gets the account resource.
|
|
|
applicationByName(applicationName, cb)
Gets an application by name.
|
|
|
applications(cb)
Gets the applications collection.
|
|
|
applications$(cb)
Gets the applications collection.
|
|
|
channelByName(channelName, cb)
Gets a channel by name.
|
|
|
channels(cb)
Gets the channels collection.
|
|
|
channels$(cb)
Gets the channels collection.
|
|
|
createApplication(name, cb)
Creates an application.
|
|
|
createChannel(name, limit, cb)
Creates a channel.
|
|
|
createSubscription(options, cb)
Creates a subscription to any number of channels.
|
|
|
findOrCreateChannel(name, limit, cb)
Find or creates a channel
|
|
|
findOrCreateSubscription(Subscription, channelOrChannels, cb)
Gets a subscription to the given channels.
|
|
|
get(cb)
Gets the Session resource. |
|
|
publish(channelName, message, cb)
Publish to a channel.
|
|
|
resetAccount(cb)
Resets the account resource.
|
|
|
subscribe(channelOrChannels, options, listener, cb)
Creates an new subscription to a channel or channels, and adds a listener.
|
|
|
subscriptionByName(subscriptionName, cb)
Gets a subscription by name.
|
|
|
subscriptions(cb)
Gets the subscriptions collection.
|
|
|
subscriptions$(cb)
Gets the subscriptions collection.
|
- Methods borrowed from class Resource:
- authorization, capabilities, capability, getIfCapable, mediaType, request, schema, update, url
Sessions contain other resources, like channels and subscriptions. These
can be accessed in the session.resources object.
One important resource inside session is the account resource
session.account, which is only given to sessions authenticated
with an email and password. The account resource is documented in its own
class.
Session objects maintain lists of channels and subscriptions. If you call
the session.channels or session.subscriptions
methods, you will get back cached data if it exists. Use the $
cache-bypass methods: session.channels$ and
session.subscriptions$ to get fresh data from the api.
- Parameters:
- {object} spire
- Spire object
- {object} data
- Session data from the spire api
session.account(function (err, account) {
if (!err) {
// `account` is account resource.
}
});
- Parameters:
- {function (err|account)} cb
- Callback
session.account$(function (err, account) {
if (!err) {
// `account` is account resource.
}
});
- Parameters:
- {function (err|account)} cb
- Callback
session.applicationByName('name_of_application', function (err, application) {
if (!err) {
// `application` now contains an application object
}
});
- Parameters:
- {String} applicationName
- Name of application
- {function (err|application)} cb
- Callback
session.applications(function (err, applications) {
if (!err) {
// `applications` is a hash of all the account's applications
}
});
- Parameters:
- {function (err|applications)} cb
- Callback
session.applications$(function (err, applications) {
if (!err) {
// `applications` is a hash of all the account's applications
}
});
- Parameters:
- {function (err|applications)} cb
- Callback
session.channelByName('name_of_channel', function (err, channel) {
if (!err) {
// `channel` now contains a channel object
}
});
- Parameters:
- {String} channelName
- Name of channel
- {function (err|channel)} cb
- Callback
session.channels(function (err, channels) {
if (!err) {
// `channels` is a hash of all the account's channels
}
});
- Parameters:
- {function (err|channels)} cb
- Callback
session.channels$(function (err, channels) {
if (!err) {
// `channels` is a hash of all the account's channels
}
});
- Parameters:
- {function (err|channels)} cb
- Callback
session.createApplication('name_of_application', function (err, application) {
if (!err) {
// `application` now contains a application object
}
});
- Parameters:
- {string} name
- Application name
- {function (err|application)} cb
- Callback
session.createChannel('foo', function (err, channel) {
if (!err) {
// `channel` is the channel named "foo".
}
});
- Parameters:
- {string} name
- Channel name
- {number} limit Optional
- Number of messages to keep in channel
- {function (err|channel)} cb
- Callback
session.findOrCreateSubscription({
name: 'my-sub',
channelNames: ['foo', 'bar']
},
function (err, subscription) {
if (!err) {
// `subscription` is the new subscription
}
});
- Parameters:
- {object} options
- Options
- {string} options.name
- Subscription name
- {array} options.channelNames
- Channel names to subscribe to
- {array} options.channelUrls
- Channel urls to subscribe to
- {number} options.expiration
- Subscription expiration (ms)
- {function (err|subscription)} cb
- Callback
session.findOrCreateChannel('foo', function (err, channel) {
if (!err) {
// `channel` is the channel named "foo".
}
});
- Parameters:
- {string} name
- Channel name to get or create
- {number} limit Optional
- Number of messages to keep in channel
- {function(err|channel)} cb
- Callback
session.findOrCreateSubscription('mySubscription', ['foo', 'bar'], function (err, subscription) {
if (!err) {
// `subscription` is a subscription named 'mySubscription', listening on channels named 'foo' and 'bar'.
}
});
- Parameters:
- {string} Subscription
- name
- {array or string} channelOrChannels
- Either a single channel name, or an array of channel names to subscribe to
- {function (err|subscription)} cb
- Callback
Gets the Session resource.
- Parameters:
- {function (err|session)} cb
- Callback
session.publish('my_channel', 'my message', function (err, message) {
if (!err) {
// Message sent successfully
}
});
- Parameters:
- {string} channelName
- Channel name
- {object|string} message
- Message
- {function (err|message)} cb
- Callback
session.resetAccount(function (err, session) {
if (!err) {
// `session` is session with new account resource.
}
});
- Parameters:
- {function (err|session)} cb
- Callback
session.subscribe('myChannel', options, function (messages) {
// `messages` is array of messages sent to the channel
}, function (err) {
// `err` will be non-null if there was a problem creating the subscription.
});
By default this will get all events from the beginning of time.
If you only want messages created from this point forward, pass { last: 'now' } in the options:
session.subscribe('myChannel', options, function (messages) {
// `messages` is array of messages sent to the channel
}, function (err) {
// `err` will be non-null if there was a problem creating the subscription.
});
- Parameters:
- {array or string} channelOrChannels
- Either a single channel name, or an array of channel names to subscribe to
- {object} options Optional
- Options to pass to the listener
- {function (messages)} listener
- Listener that will get called with each batch of messages
- {function (err|subscription)} cb Optional
- Callback
session.subscriptionByName('name_of_subscription', function (err, subscription) {
if (!err) {
// `subscription` now contains a subscription object
}
});
- Parameters:
- {String} subscriptionName
- Name of subscription
- {function (err|subscription)} cb
- Callback
session.subscriptions(function (err, subscriptions) {
if (!err) {
// `subscriptions` is a hash of all the account's subscriptions
}
});
- Parameters:
- {function (err|channels)} cb
- Callback
session.subscriptions$(function (err, subscriptions) {
if (!err) {
// `subscriptions` is a hash of all the account's subscriptions
}
});
- Parameters:
- {function (err|subscriptions)} cb
- Callback