Skip to content

Instantly share code, notes, and snippets.

@flores
Forked from dyoder/Create-A-Channel.js
Created October 13, 2011 09:56
Show Gist options
  • Save flores/1283883 to your computer and use it in GitHub Desktop.
Save flores/1283883 to your computer and use it in GitHub Desktop.
REST Tutorial
surfer.get({
url: resources.notifications.url,
parameters: {
channel: "foo"
},
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].MessageList,
},
on: {
200: function(response) {
assert.equals(response.content.data[0].message,
"Hello, Foo!")
}
}
});
surfer.get({
url: resources.notifications.channels.url,
parameters: {
events: "create,delete"
},
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].ChannelEvent,
},
on: {
200: function(response) {
assert.ok(response.content.data.name);
}
}
});
surfer.get({
url: resources.notifications.channels.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].ChannelEvent,
},
on: {
200: function(response) {
assert.ok(response.content.data.name);
}
}
});
surfer.post({
url: resources.notifications.channels.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].Channel,
content_type: resources.schema["1.0"].Channel
},
content: {
name: "Foo"
},
on: {
201: function(response) {
resources.channels = {};
resources.channels["foo"] = response.content.data;
assert.ok(resources.channels["foo"].publish.url);
}
}
});
surfer.post({
url: resources.sessions.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].Session,
content_type: resources.schema["1.0"].Key
},
content: {
key: key
},
on: {
201: function(response) {
resources.session = response.getHeader("Location");
resources.notifications = response.content.data.notifications;
assert.ok(resources.notifications);
}
}
});
surfer.get({
url: "http://waves.io/",
headers: {
accept: "application/json",
origin: "http://yourdomain.com"
},
on: {
response: function(response) {
resources = response.content.data;
assert.ok(resources.sessions.url);
}
}
});
surfer.get({
url: resources.notifications.subscribe.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].MessageList,
},
content: {
filter: {
to: "Bob"
}
},
on: {
200: function(response) {
assert.equals(response.content.data[0].message.to,
"Bob")
}
}
});
surfer.get({
url: resources.notifications.channels.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].ChannelList,
},
on: {
200: function(response) {
resources.channels = response.content.data;
assert.ok(resource.channels["foo"]);
}
}
});
var surfer = new Surf()
, resources
, key = "1234567890";
;
surfer.post({
url: resources.notifications.url,
parameters: {
channel: "foo.bar"
},
headers: {
origin: "http://yourdomain.com",
content_type: resources.schema["1.0"].Message
accept: resources.schema["1.0"].Message,
},
content: {
message: "Hello, Foo.Bar!"
},
on: {
201: function(response) {
assert.equals(response.content.data.message.url,
response.getHeader("Location"));
}
}
});
surfer.post({
url: resources.notifications.publish.url,
headers: {
origin: "http://yourdomain.com",
content_type: resources.schema["1.0"].Message
accept: resources.schema["1.0"].Message,
},
content: {
message: "Hello, World!",
timeout: { hours: 1 }
},
on: {
201: function(response) {
assert.equals(response.content.data.message.url,
response.getHeader("Location"));
}
}
});
surfer.post({
url: resources.notifications.publish.url,
headers: {
origin: "http://yourdomain.com",
content_type: resources.schema["1.0"].Message
accept: resources.schema["1.0"].Message,
},
content: {
message: {
from: "Alice",
to: "Bob",
text: "Hello, Bob!"
}
},
on: {
201: function(response) {
assert.equals(response.content.data.message.url,
response.getHeader("Location"));
}
}
});
surfer.post({
url: resources.channels["foo"].publish.url,
headers: {
origin: "http://yourdomain.com",
content_type: resources.schema["1.0"].Message
accept: resources.schema["1.0"].Message,
},
content: {
message: "Hello, Foo!"
},
on: {
201: function(response) {
assert.equals(response.content.data.message.url,
response.getHeader("Location"));
}
}
});
surfer.get({
url: resources.channels["foo"].subscribe.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].MessageList,
},
on: {
200: function(response) {
assert.equals(response.content.data[0].message,
"Hello, Foo!")
}
}
});
surfer.get({
url: resources.notifications.subscribe.url,
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].MessageList,
},
on: {
200: function(response) {
assert.equals(response.content.data[0].message,
"Hello, World!")
}
}
});
surfer.get({
url: resources.notifications.url,
parameters: {
channel: "foo.bar"
events: "create,delete"
},
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].ChannelEvent,
},
on: {
200: function(response) {
assert.ok(response.content.data.name);
}
}
});
surfer.get({
url: resources.notifications.url,
parameters: {
channel: "foo.bar"
},
headers: {
origin: "http://yourdomain.com",
accept: resources.schema["1.0"].MessageList,
},
on: {
200: function(response) {
assert.equals(response.content.data[0].message,
"Hello, Foo.Bar!")
}
}
});
@flores
Copy link
Author

flores commented Oct 13, 2011

Sub-Channel-Notifications.js channel: "foo.bar" @dyoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment