Skip to content

Instantly share code, notes, and snippets.

@naaman
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naaman/681922d2abd88945288e to your computer and use it in GitHub Desktop.
Save naaman/681922d2abd88945288e to your computer and use it in GitHub Desktop.
#require 'net/http'
require 'excon'
Excon.defaults[:chunk_size] = 1024*10
streamer = lambda do
sleep((100..500).to_a.sample.to_f / 1000)
"#{%w(hello from streaming how do you do).to_a.sample * 30}\n"
end
res = Excon.post(
"http://busl.herokuapp.com/streams/#{ARGV[0]}",
request_block: streamer
)
require 'excon'
streamer = lambda do |chunk, remaining_bytes, total_bytes|
puts chunk
end
res = Excon.get(
"http://busl.herokuapp.com/streams/#{ARGV[0]}",
response_block: streamer
)
puts res.inspect
require "heroku/command"
require "excon"
class Heroku::Command::Stream < Heroku::Command::BaseWithApp
# publish
#
# publish some random data
#
# -s, --stream STREAM # stream id
def publish
puts options.inspect
Excon.defaults[:chunk_size] = 1024*10
streamer = lambda do
sleep((100..500).to_a.sample.to_f / 1000)
"#{%w(hello from streaming how do you do).to_a.sample * 30}\n"
end
Excon.post(
"http://busl.herokuapp.com/streams/#{options[:stream]}",
request_block: streamer
)
end
# subscribe
#
# subscribe to a stream
#
# -s, --stream STREAM # stream id
def subscribe
puts options.inspect
streamer = lambda do |chunk, remaining_bytes, total_bytes|
puts chunk
end
res = Excon.get(
"http://busl.herokuapp.com/streams/#{options[:stream]}",
response_block: streamer
)
puts res.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment