37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
|
# 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::Adapter::NetHttp
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.['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.['X-Api-Key'] = Slideshift::Tool.config['service']['key']
req.['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
|