Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created September 26, 2014 19:20
Show Gist options
  • Save ToeJamson/3da24bcef47212cf6bdf to your computer and use it in GitHub Desktop.
Save ToeJamson/3da24bcef47212cf6bdf to your computer and use it in GitHub Desktop.
Data Streams over WebSockets and HTTP Long Polling Protocols
{
"time": "2:07:04pm",
"price": "510.83",
"delta": "69.02",
"perc": "13.51",
"vol": 2930
}
{
"time": "2:07:06pm",
"price": "512.29",
"delta": "70.48",
"perc": "13.76",
"vol": 5120
}
$ gem install pubnub
require 'pubnub'
my_logger = Logger.new(STDOUT)
pubnub = Pubnub.new(
subscribe_key: "demo",
error_callback: lambda { |msg|
puts "Error callback says: #{msg.inspect}"
},
logger: my_logger
)
options = {
channel: "hello_world",
http_sync: true
}
pubnub.subscribe(options) { |data| puts data.msg }
$ pip install pubnub==3.5.2
import pubnub
pubnub = Pubnub(subscribe_key="demo", ssl_on=False)
def pn_received(message):
print(message)
return True
pubnub.subscribe_sync(channel='hello_world', callback=pn_received)
<script src="//cdn.pubnub.com/pubnub.min.js"></script>
<script>
(function(){
var pubnub = PUBNUB.init({
publish_key : 'demo',
error: function(e) {
console.log(e);
}
});
// The message you want to sent can be anything
// Examples include strings, numbers, arrays, or JavaScript Objects, etc.
// JavaScript Objects are automatically converted to JSON strings by the SDK
pubnub.publish({
channel : "hello_world",
message : "Hi, from JavaScript"
});
})();
</script>
$ gem install pubnub
require 'pubnub'
my_logger = Logger.new(STDOUT)
pubnub = Pubnub.new(
publish_key: "demo",
error_callback: lambda { |msg|
puts "Error callback says: #{msg.inspect}"
},
logger: my_logger
)
options = {
message: "Hi, from Ruby",
channel: "hello_world",
http_sync: true
}
pubnub.publish(options) do |envelope|
puts envelope.inspect
end
$ pip install pubnub==3.5.2
import pubnub
pubnub = Pubnub(publish_key="demo", ssl_on=False)
def pn_error(message):
print ("ERROR: " + str(message))
print pubnub.publish(channel='hello_world', message='Hi, from Python', error=pn_error)
<script src="//cdn.pubnub.com/pubnub.min.js"></script>
<script>
(function(){
var pubnub = PUBNUB.init({
subscribe_key : 'demo',
error: function(e) {
console.log(e);
}
});
// Messages received on the specified channel will be sent to the message callback function
// JSON strings are automatically converted to JavaScript Objects by the SDK
pubnub.subscribe({
channel : "hello_world",
message : function(msg) {
console.log(msg);
}
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment