class Slideshift::Tool::Cli::Main

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/slideshift/tool/cli/main.rb, line 16
def initialize(*args)
  super(*args)

  Slideshift::Tool.config.read(File.expand_path('../default.conf', __FILE__))

  Slideshift::Tool.config.read(File.expand_path('~/.slideshift.conf')) if File.exists?(File.expand_path('~/.slideshift.conf'))
  Slideshift::Tool.config.read(File.expand_path('./slideshift.conf'))  if File.exists?(File.expand_path('./slideshift.conf'))

  Slideshift::Tool.config
end

Public Instance Methods

server() click to toggle source
# File lib/slideshift/tool/cli/main.rb, line 29
def server
  presentation = Slideshift::Tool::Presentation.new
  presentation.load
  server = Slideshift::Tool::Server::Server.new(presentation)
  server.start
end
upload() click to toggle source
# File lib/slideshift/tool/cli/main.rb, line 37
def upload

  say 'Uploading new presentation to SlideShift ...'

  `tar czf presentation.tar.gz .`

  http = Faraday.new(:url => Slideshift::Tool.config['service']['url']) do |builder|
    #builder.use Faraday::Response::Logger     # log the request to STDOUT
    builder.use Faraday::Adapter::NetHttp     # make http requests with Net::HTTP

    builder.request :multipart
    builder.request :url_encoded
  end

  if Slideshift::Tool.config['service']['id']
    say 'Presentation ID found, updating ...'
    type = :update
  else
    say 'Creating new presentation ...'
    type = :create
  end

  if type == :create
    name = ask 'Name of your presentation:'
    response = http.put do |req|
      req.url '/api/presentation'
      req.headers['X-Api-Key'] = Slideshift::Tool.config['service']['key']
      req.body = Yajl::Encoder.encode({ :name => name })
    end
    id = response.body
  else
    id = Slideshift::Tool.config['service']['id']
  end

  http.put do |req|
    req.url File.join('/api/presentation', id)
    req.headers['X-Api-Key'] = Slideshift::Tool.config['service']['key']
    req.headers['Content-Type'] = 'application/x-gzip'
    req.body = File.read('presentation.tar.gz')
  end

  FileUtils.rm('presentation.tar.gz')

  if type == :create
    Slideshift::Tool.config.service.id = id
    conf = File.exists?('./slideshift.conf') ? File.read('./slideshift.conf') : ''
    unless conf.index(id)
      conf << "\nservice.id = '#{id}'\n"
      File.open('./slideshift.conf', 'w') do |file|
        file.write(conf)
      end
    end
  end

  say "You presentation id: #{id}"
  say "Presentation can be accessed directly: #{Slideshift::Tool.config['service']['url']}/presentation/#{id}"
end