Last active
August 29, 2015 14:04
-
-
Save naaman/681922d2abd88945288e to your computer and use it in GitHub Desktop.
This file contains 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
#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 | |
) |
This file contains 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
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 |
This file contains 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
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