Skip to content

Instantly share code, notes, and snippets.

@domadev812
Forked from ToeJamson/1.json
Last active November 15, 2017 21:06
Show Gist options
  • Save domadev812/6f3c7e5386fca3890e273b57f0f0cd80 to your computer and use it in GitHub Desktop.
Save domadev812/6f3c7e5386fca3890e273b57f0f0cd80 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",
publish_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>=4.0.13'
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconfig = PNConfiguration()
pnconfig.subscribe_key = "my_subkey"
pnconfig.publish_key = "my_pubkey"
pnconfig.ssl = False
pubnub = PubNub(pnconfig)
def pn_received(message):
print(message)
return True
pubnub.subscribe_sync(channel='hello_world', callback=pn_received)
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.16.1.js"></script>
<script>
(function(){
pubnub = new PubNub({
publishKey : 'demo',
subscribeKey : 'demo'
})
});
// 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(
{
message: {
such: "Hi, from JavaScript"
},
channel: "hello_world",
sendByPost: false, // true to send via post
storeInHistory: false, //override default storage options
meta: {
"cool": "meta"
} // publish extra meta with the request
},
function (status, response) {
// handle status, response
}
);
})();
</script>
$ gem install pubnub
require 'pubnub'
my_logger = Logger.new(STDOUT)
pubnub = Pubnub.new(
publish_key: "demo",
subscribe_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.status
end
$ pip install 'pubnub>=4.0.13'
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconfig = PNConfiguration()
pnconfig.subscribe_key = "my_subkey"
pnconfig.publish_key = "my_pubkey"
pnconfig.ssl = False
pubnub = PubNub(pnconfig)
def publish_callback(result, status):
pass
# Handle PNPublishResult and PNStatus
print pubnub.publish().channel('hello_world').message(['Hi, from Python']).async(publish_callback)
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.16.1.js"></script>
<script>
(function(){
var pubnub = new PubNub({
subscribeKey: "mySubscribeKey",
publishKey: "demo",
ssl: true
})
// 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({
channels: ['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