Skip to content

Instantly share code, notes, and snippets.

@naaman

naaman/chunker.rb

Last active Aug 29, 2015
Embed
What would you like to do?
#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