-
-
Save flores/1283883 to your computer and use it in GitHub Desktop.
REST Tutorial
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
| 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!") | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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") | |
| } | |
| } | |
| }); |
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
| 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"]); | |
| } | |
| } | |
| }); |
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 surfer = new Surf() | |
| , resources | |
| , key = "1234567890"; | |
| ; |
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
| 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")); | |
| } | |
| } | |
| }); |
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
| 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")); | |
| } | |
| } | |
| }); |
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
| 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")); | |
| } | |
| } | |
| }); |
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
| 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")); | |
| } | |
| } | |
| }); |
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
| 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!") | |
| } | |
| } | |
| }); |
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
| 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!") | |
| } | |
| } | |
| }); |
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
| 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); | |
| } | |
| } | |
| }); |
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
| 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!") | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sub-Channel-Notifications.js channel: "foo.bar" @dyoder