Skip to content

Commit

Permalink
Private records!
Browse files Browse the repository at this point in the history
 - delegate url generation to server
 - push last --private switch
 - indented docs
  • Loading branch information
Antono Vasiljev committed Apr 14, 2012
1 parent 7d12318 commit 42778f5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
41 changes: 22 additions & 19 deletions bin/shelr
Expand Up @@ -10,34 +10,37 @@ HELP = <<-HELP
Usage: #{BASENAME} command [arg]
Recording:
COMMANDS:
record - record new shellcast
Recording:
Publishing:
record - record new shellcast
push last - publish last record
push RECORD_ID - publish
Publishing:
Getting record as json:
push last - publish last record
push last --private - publish private record
push RECORD_ID - publish record with given id
dump last - dump last record as json to current dir
dump RECORD_ID - dump any record as json to current dir
Getting record as json:
Replaying:
dump last - dump last record as json to current dir
dump RECORD_ID - dump any record as json to current dir
list - print list of records
play last - play last local record
play RECORD_ID - play local record
play RECORD_URL - play remote record
play dump.json - play local file dumped with `shelr dump`
Replaying:
Setup:
list - print list of records
play last - play last local record
play RECORD_ID - play local record
play RECORD_URL - play remote record
play dump.json - play local file dumped with `shelr dump`
setup API_KEY - set your API key
backend [ttyrec|script] - setup recorder backend
Setup:
Visit: http://shelr.tv/ for more info.
setup API_KEY - set your API key
backend [ttyrec|script] - setup recorder backend
Visit: http://shelr.tv/ for more info.
HELP

Expand Down Expand Up @@ -75,7 +78,7 @@ when 'dump'
end
when 'push'
if ARGV[1]
Shelr::Publisher.new.publish(ARGV[1])
Shelr::Publisher.new.publish(ARGV[1], ARGV[2] == '--private')
else
puts "What do you want to publish?"
Shelr::Player.list
Expand Down
3 changes: 3 additions & 0 deletions lib/shelr/player.rb
Expand Up @@ -64,6 +64,9 @@ def play
STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
end

def scriptreplay(typescript, timing)
end

private

def record_file(name)
Expand Down
20 changes: 12 additions & 8 deletions lib/shelr/publisher.rb
Expand Up @@ -4,7 +4,8 @@
module Shelr
class Publisher

def publish(id)
def publish(id, priv = false)
@private = priv
ensure_unlocked(id)
with_exception_handler do
uri = URI.parse(Shelr::API_URL + '/records')
Expand All @@ -30,7 +31,7 @@ def ensure_unlocked(id)
if File.exist?(lock_path)
puts "=> Cannot publish the record (make sure it finished with exit or Ctrl+D)"
puts "=> Record locked on #{File.read(lock_path)}"
puts "=> Esure no other shelr process running"
puts "=> Make sure no other shelr process running (ps axu | grep shelr)"
puts "=> Or remove lock file manually: #{lock_path}"
exit 0
end
Expand All @@ -45,12 +46,14 @@ def with_exception_handler(&block)
end

def handle_response(res)
res = JSON.parse(res.body)
if res['ok']
STDOUT.puts res['message']
STDOUT.puts Shelr::API_URL + '/records/' + res['id']
else
STDOUT.puts res['message']
with_exception_handler do
res = JSON.parse(res.body)
if res['ok']
STDOUT.puts "=> " + res['message'].to_s
STDOUT.puts "=> " + res['url'].to_s
else
STDOUT.puts res['message']
end
end
end

Expand Down Expand Up @@ -85,6 +88,7 @@ def prepare(id)
out['description'] = STDIN.gets.strip
STDOUT.print 'Tags (ex: howto, linux): '
out['tags'] = STDIN.gets.strip
out['private'] = @private
return out.to_json
end
end
Expand Down
12 changes: 10 additions & 2 deletions spec/shelr/recorder_spec.rb
Expand Up @@ -5,6 +5,7 @@
before do
STDIN.stub(:gets).and_return('my shellcast')
Shelr.backend = 'script'
# disable term size guard
STDOUT.stub(:puts)
STDOUT.stub(:print)
end
Expand All @@ -13,6 +14,7 @@
before do
subject.stub(:system).with(anything).and_return(true)
subject.stub(:record_id => "1")
subject.stub(:ensure_terminal_has_good_size)
subject.stub(:with_lock_file).and_yield
end

Expand Down Expand Up @@ -49,9 +51,9 @@
end

it "adds XDG_CURRENT_DESKTOP to @meta as xdg_current_desktop" do
subject.stub(:record_id => 'ololo')
ENV['XDG_CURRENT_DESKTOP'] = 'united-kde-gnome-shell'
subject.request_metadata
subject.meta["recorded_at"].should == 'ololo'
subject.meta["xdg_current_desktop"].should == 'united-kde-gnome-shell'
end

it "reads title from stdin" do
Expand All @@ -69,4 +71,10 @@
subject.user_columns.should == 10
end
end

describe "#scriptreplay(typescript, timing)" do
it "reads typescript" do
File.stub(:read)
end
end
end

0 comments on commit 42778f5

Please sign in to comment.