Created
March 21, 2012 18:36
-
-
Save nlacasse/2150934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.post({ | |
url: description.resources.session.resources.channels.url, | |
headers: { | |
accept: description.schema["1.0"].channel.mediaType, | |
content_type: description.schema["1.0"].channel.mediaType, | |
authorization: "Capability " + | |
description.resources.session.resources.channels.capabilities.create | |
}, | |
content: { | |
name: "foo" | |
}, | |
on: { | |
201: function(response) { | |
description.resources.channels = {}; | |
description.resources.channels.foo = response.content.data; | |
assert.ok(description.resources.channels.foo.url); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.post({ | |
url: description.resources.sessions.url, | |
headers: { | |
accept: description.schema["1.0"].session.mediaType, | |
content_type: description.schema["1.0"].account.mediaType | |
}, | |
content: { | |
secret: secret | |
}, | |
on: { | |
201: function(response) { | |
description.resources.session = response.content.data; | |
assert.ok(description.resources.session); | |
assert.ok(description.resources.session.url); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.post({ | |
url: description.resources.session.resources.subscriptions.url, | |
headers: { | |
accept: description.schema["1.0"].subscription.mediaType, | |
content_type: description.schema["1.0"].subscription.mediaType, | |
authorization: "Capability " + | |
description.resources.session.resources.subscriptions.capabilities.create | |
}, | |
content: { | |
channels: [ description.resources.channels.foo.url ] | |
}, | |
on: { | |
201: function(response) { | |
description.resources.subscription = response.content.data; | |
assert.ok(description.resources.subscription.url); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.get({ | |
url: "http://api.spire.io/", | |
headers: { | |
accept: "application/json" | |
}, | |
on: { | |
200: function(response) { | |
description = response.content.data; | |
assert.ok(description.resources.sessions.url); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.get({ | |
url: description.resources.subscription.url, | |
headers: { | |
accept: description.schema["1.0"].events.mediaType, | |
authorization: "Capability " + | |
description.resources.subscription.capabilities.messages | |
}, | |
parameters: { | |
"last-message": description.lastMessageTimestamp | |
}, | |
on: { | |
200: function(response) { | |
var events = response.content.data; | |
assert.equal(events.messages.length, 0); | |
} | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.get({ | |
url: description.resources.subscription.url, | |
headers: { | |
accept: description.schema["1.0"].events.mediaType, | |
authorization: "Capability " + | |
description.resources.subscription.capabilities.messages | |
}, | |
on: { | |
200: function(response) { | |
var events = response.content.data; | |
description.lastMessageTimestamp = events.messages[0].timestamp; | |
assert.equal(events.messages[0].content, "Hello, World!"); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.get({ | |
url: description.resources.subscription.url, | |
headers: { | |
accept: description.schema["1.0"].events.mediaType, | |
authorization: "Capability " + | |
description.resources.subscription.capabilities.messages | |
}, | |
parameters: { | |
"last-message": description.lastMessageTimestamp, | |
timeout: 30 // seconds | |
}, | |
on: { | |
200: function(response) { | |
var events = response.content.data; | |
assert.equal(events.messages[0].content, "Hello, World!"); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shred.post({ | |
url: description.resources.channels.foo.url, | |
headers: { | |
content_type: description.schema["1.0"].message.mediaType, | |
accept: description.schema["1.0"].message.mediaType, | |
authorization: "Capability " + | |
description.resources.channels.foo.capabilities.publish | |
}, | |
content: { content: "Hello, World!" }, | |
on: { | |
201: function(response) { | |
// we get back the message we publish | |
assert.equal(response.content.data.content,"Hello, World!"); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Shred = require("../lib/shred") | |
, assert = require('assert') | |
, shred = new Shred() | |
, description | |
, secret = "12345678" | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment