Class: Lapse::Cli
- Inherits:
-
Thor
- Object
- Thor
- Lapse::Cli
- Defined in:
- lib/lapse/cli.rb
Instance Method Summary collapse
- #add_frame(clip_id) ⇒ Object
- #create_clip(title, *image_paths) ⇒ Object
- #photobooth(title, frame_count = 10) ⇒ Object
- #signin(host, token) ⇒ Object
- #signout ⇒ Object
Instance Method Details
#add_frame(clip_id) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lapse/cli.rb', line 49 def add_frame(clip_id) file = get_frame([:url]) frame = upload_frame clip_id, file.path clip = authenticated_client.submit_frames(clip_id, [frame.id]) url = "#{api_host}/#{clip.slug}" if [:open] system "open #{url}" else system "echo #{url} | pbcopy" end end |
#create_clip(title, *image_paths) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lapse/cli.rb', line 30 def create_clip(title, *image_paths) clip = authenticated_client.create_clip puts "Created clip id #{clip.id}" frames = image_paths.map do |image_path| upload_frame(clip.id, image_path) end authenticated_client.submit_frames(clip.id, frames.map(&:id)) puts 'Publishing clip' authenticated_client.publish_clip(clip.id, title: title) puts "#{api_host}/#{clip.slug}" end |
#photobooth(title, frame_count = 10) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/lapse/cli.rb', line 65 def photobooth(title, frame_count = 10) clip = authenticated_client.create_clip if ![:url] && !system('which imagesnap') puts "Install imagesnap via \`brew install imagesnap\` to use your local camera." return end frames = frame_count.to_i.times.map do |i| if [:url] file = get_frame([:url]) else file = Tempfile.new(['photobooth', '.jpg'], encoding: 'BINARY') system "imagesnap #{file.path}" end upload_frame clip.id, file.path end authenticated_client.submit_frames(clip.id, frames.map(&:id)) authenticated_client.publish_clip(clip.id, title: title) url = "#{api_host}/#{clip.slug}" if [:open] system "open #{url}" else system "echo #{url} | pbcopy" end puts "\n#{url}" end |
#signin(host, token) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lapse/cli.rb', line 10 def signin(host, token) result = unauthenticated_client(host).authenticate(token) self.auth_data = { :access_token => result['access_token'], :api_host => host } result = ["Signed in as #{result.user.username}"] result << " on #{host}" if host puts result.join('') end |
#signout ⇒ Object
24 25 26 27 |
# File 'lib/lapse/cli.rb', line 24 def signout File.delete config_file puts 'Signed out' end |