wistia-uploader 0.1.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -0
- data/Gemfile +8 -5
- data/Gemfile.lock +10 -1
- data/README.md +7 -9
- data/Rakefile +11 -14
- data/VERSION +1 -1
- data/bin/wistia-uploader +75 -72
- data/lib/wistia-uploader.rb +87 -35
- data/spec/spec_helper.rb +5 -0
- data/spec/wistia-uploader_spec.rb +141 -0
- data/wistia-uploader.gemspec +8 -10
- metadata +10 -23
- data/test/helper.rb +0 -18
- data/test/test_wistia-uploader.rb +0 -7
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p392@wistia-uploader --create
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
gem 'json'
|
4
4
|
gem 'multipart-post', '>= 1.1.5'
|
@@ -6,8 +6,11 @@ gem 'multipart-post', '>= 1.1.5'
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
|
9
|
+
gem 'shoulda', '>= 0'
|
10
|
+
gem 'rdoc', '~> 3.12'
|
11
|
+
gem 'jeweler', '~> 1.8.4'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rspec'
|
13
16
|
end
|
data/Gemfile.lock
CHANGED
@@ -4,6 +4,7 @@ GEM
|
|
4
4
|
activesupport (3.2.8)
|
5
5
|
i18n (~> 0.6)
|
6
6
|
multi_json (~> 1.0)
|
7
|
+
diff-lcs (1.2.4)
|
7
8
|
git (1.2.5)
|
8
9
|
i18n (0.6.1)
|
9
10
|
jeweler (1.8.4)
|
@@ -17,6 +18,14 @@ GEM
|
|
17
18
|
rake (0.9.2.2)
|
18
19
|
rdoc (3.12)
|
19
20
|
json (~> 1.4)
|
21
|
+
rspec (2.13.0)
|
22
|
+
rspec-core (~> 2.13.0)
|
23
|
+
rspec-expectations (~> 2.13.0)
|
24
|
+
rspec-mocks (~> 2.13.0)
|
25
|
+
rspec-core (2.13.1)
|
26
|
+
rspec-expectations (2.13.0)
|
27
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
28
|
+
rspec-mocks (2.13.1)
|
20
29
|
shoulda (3.1.1)
|
21
30
|
shoulda-context (~> 1.0)
|
22
31
|
shoulda-matchers (~> 1.2)
|
@@ -28,9 +37,9 @@ PLATFORMS
|
|
28
37
|
ruby
|
29
38
|
|
30
39
|
DEPENDENCIES
|
31
|
-
bundler (~> 1.1.4)
|
32
40
|
jeweler (~> 1.8.4)
|
33
41
|
json
|
34
42
|
multipart-post (>= 1.1.5)
|
35
43
|
rdoc (~> 3.12)
|
44
|
+
rspec
|
36
45
|
shoulda
|
data/README.md
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
wistia-uploader
|
2
|
-
===============
|
1
|
+
# wistia-uploader
|
3
2
|
|
4
|
-
A
|
3
|
+
A command line media upload client for Wistia users.
|
5
4
|
|
6
5
|
Run 'bin/wistia-uploader -h' for additional information.
|
7
6
|
|
8
|
-
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
wistia-uploader works with Ruby 1.8.7 and 1.9.3. Earlier versions of 1.8 and 1.9 may work but have not been tested.
|
10
|
+
|
11
|
+
## Configuration
|
9
12
|
-------------
|
10
13
|
|
11
14
|
While not required for use, defaults for various required parameters may be
|
@@ -18,8 +21,3 @@ key/value pairs. Example:
|
|
18
21
|
|
19
22
|
A Wistia 'contact_id' may also be specified, otherwise the account owner will
|
20
23
|
be inferred from the project.
|
21
|
-
|
22
|
-
Copyright
|
23
|
-
---------
|
24
|
-
|
25
|
-
Copyright (c) 2012 Jason Lawrence of Wistia, Inc.
|
data/Rakefile
CHANGED
@@ -14,25 +14,22 @@ require 'rake'
|
|
14
14
|
require 'jeweler'
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name =
|
18
|
-
gem.homepage =
|
19
|
-
gem.license =
|
20
|
-
gem.summary =
|
21
|
-
gem.description =
|
22
|
-
gem.email =
|
23
|
-
gem.authors = [
|
17
|
+
gem.name = 'wistia-uploader'
|
18
|
+
gem.homepage = 'http://github.com/wistia/wistia-uploader'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = 'A simple CLI uploader for Wistia users.'
|
21
|
+
gem.description = 'A simple CLI uploader for Wistia users.'
|
22
|
+
gem.email = 'dev@wistia.com'
|
23
|
+
gem.authors = ['Robby Grossman', 'Jason Lawrence', 'Brendan Schwartz']
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
27
27
|
|
28
|
-
require '
|
29
|
-
|
30
|
-
|
31
|
-
test.pattern = 'test/**/test_*.rb'
|
32
|
-
test.verbose = true
|
33
|
-
end
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
desc 'Run specs'
|
30
|
+
RSpec::Core::RakeTask.new
|
34
31
|
|
35
|
-
task :
|
32
|
+
task default: :spec
|
36
33
|
|
37
34
|
require 'rdoc/task'
|
38
35
|
Rake::RDocTask.new do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/bin/wistia-uploader
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
# A simple CLI media uploader for Wistia.
|
4
4
|
|
5
5
|
require 'set'
|
6
|
-
require 'json'
|
7
6
|
require 'optparse'
|
8
7
|
|
9
|
-
|
8
|
+
require File.expand_path('../../lib/wistia-uploader', __FILE__)
|
10
9
|
|
11
10
|
options = {}
|
12
11
|
|
@@ -15,57 +14,57 @@ required = Set.new [:api_password, :media_file]
|
|
15
14
|
loadable = Set.new([:contact_id, :project_id]) + required
|
16
15
|
|
17
16
|
OptionParser.new do |opts|
|
18
|
-
opts.banner =
|
19
|
-
|
20
|
-
opts.separator
|
21
|
-
opts.separator
|
22
|
-
opts.separator
|
23
|
-
opts.separator
|
24
|
-
opts.separator
|
25
|
-
opts.separator
|
26
|
-
opts.separator
|
27
|
-
opts.separator
|
28
|
-
opts.separator
|
29
|
-
opts.separator
|
30
|
-
opts.separator
|
31
|
-
|
32
|
-
opts.separator
|
33
|
-
|
34
|
-
opts.on(
|
17
|
+
opts.banner = 'Usage: wistia-uploader [options]'
|
18
|
+
|
19
|
+
opts.separator ''
|
20
|
+
opts.separator 'Description:'
|
21
|
+
opts.separator ' Upload media files to a Wistia project.'
|
22
|
+
opts.separator ''
|
23
|
+
opts.separator 'Configuration:'
|
24
|
+
opts.separator ' Default values for required options may be specified as'
|
25
|
+
opts.separator ' newline separated key=value pairs in \'~/.wistia.conf\'.'
|
26
|
+
opts.separator ''
|
27
|
+
opts.separator ' Options provided in this manner will be overridden if'
|
28
|
+
opts.separator ' specified on the command line.'
|
29
|
+
opts.separator ''
|
30
|
+
|
31
|
+
opts.separator 'General options:'
|
32
|
+
|
33
|
+
opts.on('-q', '--quiet', 'Silence output') do |q|
|
35
34
|
options[:quiet] = q
|
36
35
|
end
|
37
36
|
|
38
|
-
opts.on(
|
37
|
+
opts.on('-j', '--json', 'Output JSON') do |j|
|
39
38
|
options[:json] = j
|
40
39
|
end
|
41
40
|
|
42
|
-
opts.separator
|
43
|
-
opts.separator
|
41
|
+
opts.separator ''
|
42
|
+
opts.separator 'Required options:'
|
44
43
|
|
45
|
-
opts.on(
|
44
|
+
opts.on('-k', '--api-password API_PASSWORD', 'The Wistia API password.') do |api_password|
|
46
45
|
options[:api_password] = api_password
|
47
46
|
end
|
48
47
|
|
49
|
-
opts.on(
|
48
|
+
opts.on('-f', '--media-file MEDIA_FILE', 'The local/remote path of the media file', 'to be uploaded/imported.') do |media_file|
|
50
49
|
options[:media_file] = media_file
|
51
50
|
end
|
52
51
|
|
53
|
-
opts.separator
|
54
|
-
opts.separator
|
52
|
+
opts.separator ''
|
53
|
+
opts.separator 'Optional:'
|
55
54
|
|
56
|
-
opts.on(
|
55
|
+
opts.on('-p', '--project-id PROJECT_ID', 'The hashed id of the Wistia project to', 'upload to.') do |project_id|
|
57
56
|
options[:project_id] = project_id
|
58
57
|
end
|
59
58
|
|
60
|
-
opts.on(
|
59
|
+
opts.on('-n', '--media-name MEDIA_NAME', 'Set the display name of the media in the', 'Wistia project. If unspecified, this will', 'default to the filename.') do |media_name|
|
61
60
|
options[:media_name] = media_name
|
62
61
|
end
|
63
62
|
|
64
|
-
opts.on(
|
63
|
+
opts.on('-c', '--contact-id CONTACT_ID', 'The numeric id of the Wistia contact.', 'If this is unspecified, the account will', 'be inferred from the project_id.') do |contact_id|
|
65
64
|
options[:contact_id] = contact_id
|
66
65
|
end
|
67
66
|
|
68
|
-
opts.on_tail(
|
67
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
69
68
|
puts opts
|
70
69
|
exit
|
71
70
|
end
|
@@ -80,9 +79,9 @@ end
|
|
80
79
|
|
81
80
|
# Load defaults from ~/.wistia.conf, if present. Only valid loadable options
|
82
81
|
# not already specified on the CLI will be initialized in this manner.
|
83
|
-
if File.exists? File.expand_path(
|
84
|
-
puts
|
85
|
-
File.open(File.expand_path(
|
82
|
+
if File.exists? File.expand_path('~/.wistia.conf')
|
83
|
+
puts 'Found ~/.wistia.conf, loading defaults!' if !options[:quiet]
|
84
|
+
File.open(File.expand_path('~/.wistia.conf')) do |conf|
|
86
85
|
conf.readlines.reject{|l|l.strip.start_with?('#')}.each do |line|
|
87
86
|
k, v = line.split("=").map { |i| i.strip }
|
88
87
|
next if (k.empty? || v.empty?)
|
@@ -95,14 +94,14 @@ end
|
|
95
94
|
|
96
95
|
# Ensure that we have all required parameters.
|
97
96
|
unless options.keys.to_set.superset?(required)
|
98
|
-
puts
|
99
|
-
puts
|
97
|
+
puts 'ERROR: You\'re missing some required options! Please specify:'
|
98
|
+
puts ''
|
100
99
|
missing = required - options.keys.to_set
|
101
100
|
missing.to_a.sort.each do |m|
|
102
101
|
puts " --#{m.to_s.gsub(/_/,"-")}"
|
103
102
|
end
|
104
|
-
puts
|
105
|
-
puts
|
103
|
+
puts ''
|
104
|
+
puts 'Use \'-h\' to see the help documentation.'
|
106
105
|
exit
|
107
106
|
end
|
108
107
|
|
@@ -119,48 +118,52 @@ begin
|
|
119
118
|
paths = [options[:media_file]]
|
120
119
|
end
|
121
120
|
|
122
|
-
paths.each do |
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
exit
|
121
|
+
paths.each do |original_media_path|
|
122
|
+
if File.exists?(original_media_path)
|
123
|
+
puts "Uploading local file: '#{original_media_path}'..." if !options[:quiet]
|
124
|
+
original_media_is_local = true
|
125
|
+
else
|
126
|
+
if original_media_path =~ /^(#{(WistiaUploader::SUPPORTED_SCHEMES.join('|'))}):\/\//
|
127
|
+
puts "Importing remote file: '#{original_media_path}'..." if !options[:quiet]
|
128
|
+
original_media_is_local = false
|
129
|
+
else
|
130
|
+
puts "Local file #{original_media_path} does not exist."
|
131
|
+
exit
|
132
|
+
end
|
135
133
|
end
|
136
134
|
|
137
135
|
thread = WistiaUploader.upload_media(
|
138
136
|
options[:api_password], options[:project_id],
|
139
|
-
|
137
|
+
original_media_path, options[:media_name], options[:contact_id])
|
140
138
|
|
141
139
|
$stdout.sync
|
142
140
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
141
|
+
if original_media_is_local
|
142
|
+
phases = ["-", "\\", "|", "/"]
|
143
|
+
phase = 0
|
144
|
+
while (thread[:upload_status].nil?)
|
145
|
+
if thread[:progress] == nil
|
146
|
+
comp = 0
|
147
|
+
else
|
148
|
+
comp = (thread[:progress] * 50).round
|
149
|
+
end
|
150
|
+
if thread[:samples] && (thread[:samples].length > 0)
|
151
|
+
bps = (thread[:samples].inject{|sum,x| sum + x[0] }) / thread[:samples].length
|
152
|
+
else
|
153
|
+
bps = 0.0
|
154
|
+
end
|
155
|
+
unless options[:quiet]
|
156
|
+
$stdout.write("\r")
|
157
|
+
$stdout.write(" #{'%3d' % (2*comp)}% [#{'=' * comp}>#{' ' * (50 - comp)}] #{phases[phase]} #{thread[:last_pos]} bytes")
|
158
|
+
$stdout.flush if RUBY_VERSION =~ /^1.8/
|
159
|
+
end
|
160
|
+
phase = (phase + 1) % 4
|
161
|
+
sleep 0.2
|
155
162
|
end
|
156
|
-
unless options[:quiet]
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
phase = (phase + 1) % 4
|
161
|
-
sleep 0.2
|
163
|
+
$stdout.write("\n") unless options[:quiet]
|
164
|
+
else
|
165
|
+
thread.join
|
162
166
|
end
|
163
|
-
$stdout.write("\n") unless options[:quiet]
|
164
167
|
|
165
168
|
if thread[:upload_status] == :success
|
166
169
|
data = JSON.parse(thread[:body])
|
@@ -170,11 +173,11 @@ begin
|
|
170
173
|
puts data if options[:json]
|
171
174
|
else
|
172
175
|
# Error state.
|
173
|
-
puts
|
176
|
+
puts 'An error occurred during upload!' unless options[:quiet]
|
174
177
|
exit 1
|
175
178
|
end
|
176
179
|
end
|
177
180
|
rescue
|
178
181
|
puts "ERROR! Upload failed. Msg: #{$!}"
|
179
|
-
puts "\t
|
182
|
+
puts "\t#{$!.backtrace.join("\n\t")}"
|
180
183
|
end
|
data/lib/wistia-uploader.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
# Setup environment via bundler
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'json'
|
1
6
|
require 'net/http'
|
7
|
+
require 'net/https' if RUBY_VERSION =~ /^1.8/
|
2
8
|
require 'net/http/post/multipart'
|
3
9
|
|
4
|
-
UPLOAD_URL = "https://upload.wistia.com/"
|
5
|
-
|
6
10
|
# Hacktacular mostly-accurate patch for upload monitoring.
|
7
11
|
class WFile < File
|
8
12
|
def set_thread(thread)
|
@@ -10,8 +14,13 @@ class WFile < File
|
|
10
14
|
end
|
11
15
|
def read(*args)
|
12
16
|
if @thread
|
13
|
-
|
14
|
-
|
17
|
+
rounded_file_size = if RUBY_VERSION =~ /^1.8/
|
18
|
+
(File.size(self.path) * 100).round / 100.0
|
19
|
+
else
|
20
|
+
self.size.round(2)
|
21
|
+
end
|
22
|
+
@thread[:progress] = 1.0 * self.pos / rounded_file_size
|
23
|
+
@thread[:last_pos] = self.pos
|
15
24
|
end
|
16
25
|
super(*args)
|
17
26
|
end
|
@@ -19,54 +28,97 @@ end
|
|
19
28
|
|
20
29
|
|
21
30
|
class WistiaUploader
|
31
|
+
UPLOAD_URL = 'https://upload.wistia.com/'
|
32
|
+
SUPPORTED_SCHEMES = %w(ftp http https)
|
22
33
|
|
23
34
|
def self.upload_media(api_pass, project, file, name=nil, contact=nil)
|
24
35
|
params = { :api_password => api_pass, :project_id => project }
|
25
36
|
params[:contact_id] = contact if contact
|
26
37
|
params[:name] = name if name
|
27
38
|
|
28
|
-
|
39
|
+
self.post_file_to_wistia('', params, file)
|
29
40
|
end
|
30
|
-
|
31
|
-
def self.post_file_to_wistia(path, data, file, timeout=nil)
|
32
|
-
Thread.new do
|
33
|
-
thread = Thread.current
|
34
|
-
thread[:progress] = 0.0
|
35
|
-
thread[:last_pos] = 0
|
36
41
|
|
42
|
+
|
43
|
+
def self.post_file_to_wistia(path, data, file, timeout=nil)
|
44
|
+
data.reject! { |k,v| v.nil? || v.to_s.empty? } # Sanitize the params hash.
|
45
|
+
thread = Thread.new do
|
46
|
+
Thread.current[:progress] = 0.0
|
47
|
+
Thread.current[:last_pos] = 0
|
37
48
|
uri = URI(UPLOAD_URL + path)
|
49
|
+
http_client = self.get_http_client(uri, timeout)
|
50
|
+
response = self.perform_http_post(file, data, uri, http_client)
|
51
|
+
self.set_thread_status_from_response(response)
|
52
|
+
end
|
53
|
+
thread
|
54
|
+
end
|
38
55
|
|
39
|
-
# Sanitize the params hash.
|
40
|
-
data.reject! { |k,v| (v == nil) || v.empty? }
|
41
56
|
|
42
|
-
|
43
|
-
http.use_ssl = true if (uri.scheme == 'https')
|
57
|
+
private
|
44
58
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
59
|
+
def self.perform_http_post(file, data, uri, http_client)
|
60
|
+
if self.file_is_local?(file)
|
61
|
+
self.upload_local_file(file, data, uri, http_client)
|
62
|
+
else
|
63
|
+
self.import_remote_file(file, data, uri, http_client)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def self.get_http_client(uri, timeout)
|
69
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
70
|
+
if uri.scheme == 'https'
|
71
|
+
if RUBY_VERSION =~ /^1.8/
|
72
|
+
http.cert_store = OpenSSL::X509::Store.new.set_default_paths
|
50
73
|
end
|
74
|
+
http.use_ssl = true
|
75
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
76
|
+
end
|
77
|
+
|
78
|
+
# Set the connection timeouts, if specified
|
79
|
+
if timeout
|
80
|
+
http.ssl_timeout = 10
|
81
|
+
http.open_timeout = 10
|
82
|
+
http.read_timeout = 10
|
83
|
+
end
|
51
84
|
|
52
|
-
|
53
|
-
|
85
|
+
http
|
86
|
+
end
|
54
87
|
|
55
|
-
req = Net::HTTP::Post::Multipart.new uri.request_uri, data.merge({
|
56
|
-
'file' => UploadIO.new(media, 'application/octet-stream', File.basename(file))
|
57
|
-
})
|
58
|
-
res = http.request(req)
|
59
|
-
media.close
|
60
88
|
|
61
|
-
|
62
|
-
|
89
|
+
def self.upload_local_file(file, data, uri, http)
|
90
|
+
media = WFile.open(file)
|
91
|
+
media.set_thread(Thread.current)
|
92
|
+
req = Net::HTTP::Post::Multipart.new uri.request_uri, data.merge({
|
93
|
+
'file' => UploadIO.new(media, 'application/octet-stream', File.basename(file))
|
94
|
+
})
|
95
|
+
response = http.request(req)
|
96
|
+
media.close
|
97
|
+
response
|
98
|
+
end
|
63
99
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
100
|
+
|
101
|
+
def self.import_remote_file(file, data, uri, http)
|
102
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
103
|
+
req.set_form_data(data.merge(:url => file))
|
104
|
+
http.request(req)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def self.file_is_local?(file_path)
|
109
|
+
!self.file_is_remote?(file_path)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def self.file_is_remote?(file_path)
|
114
|
+
file_path =~ /^(#{(SUPPORTED_SCHEMES.join('|'))}):\/\//
|
70
115
|
end
|
71
116
|
|
117
|
+
|
118
|
+
def self.set_thread_status_from_response(response)
|
119
|
+
Thread.current[:code] = response.code
|
120
|
+
Thread.current[:body] = response.body
|
121
|
+
|
122
|
+
Thread.current[:upload_status] = (response.code == '200') ? :success : :failed
|
123
|
+
end
|
72
124
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WistiaUploader do
|
4
|
+
describe 'public class methods' do
|
5
|
+
describe '#upload_media' do
|
6
|
+
it 'posts the specified file to Wistia when given optional params' do
|
7
|
+
password = mock('password')
|
8
|
+
project = mock('project')
|
9
|
+
file = mock('file')
|
10
|
+
name = mock('name')
|
11
|
+
contact = mock('contact')
|
12
|
+
|
13
|
+
WistiaUploader.should_receive(:post_file_to_wistia).with('',
|
14
|
+
hash_including({
|
15
|
+
api_password: password,
|
16
|
+
project_id: project,
|
17
|
+
contact_id: contact,
|
18
|
+
name: name,
|
19
|
+
}), file
|
20
|
+
)
|
21
|
+
WistiaUploader.upload_media(password, project, file, name, contact)
|
22
|
+
end
|
23
|
+
it 'posts the specified file to Wistia when given only required params' do
|
24
|
+
password = mock('password')
|
25
|
+
project = mock('project')
|
26
|
+
file = mock('file')
|
27
|
+
|
28
|
+
WistiaUploader.should_receive(:post_file_to_wistia).with('',
|
29
|
+
hash_including({
|
30
|
+
api_password: password,
|
31
|
+
project_id: project,
|
32
|
+
}), file
|
33
|
+
)
|
34
|
+
WistiaUploader.upload_media(password, project, file)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe '#post_file_to_wistia' do
|
38
|
+
describe 'given a local file' do
|
39
|
+
it 'uploads the file' do
|
40
|
+
file = mock('file')
|
41
|
+
file.stub :set_thread
|
42
|
+
WFile.should_receive(:open).with('/var/tmp/dummy.mov').and_return(file)
|
43
|
+
|
44
|
+
upload_io = mock('upload io')
|
45
|
+
UploadIO.should_receive(:new).and_return(upload_io)
|
46
|
+
|
47
|
+
request = mock('request')
|
48
|
+
Net::HTTP::Post::Multipart.should_receive(:new).and_return(request)
|
49
|
+
|
50
|
+
http = mock('net_http')
|
51
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
52
|
+
|
53
|
+
http.stub :use_ssl=
|
54
|
+
http.stub :verify_mode=
|
55
|
+
|
56
|
+
response = mock('response')
|
57
|
+
http.should_receive(:request).and_return(response)
|
58
|
+
file.stub :close
|
59
|
+
|
60
|
+
response.should_receive(:code).exactly(2).and_return('200')
|
61
|
+
response.should_receive(:body).and_return('OK')
|
62
|
+
|
63
|
+
thread = WistiaUploader.post_file_to_wistia('', {api_password: 'pass', project_id: 5}, '/var/tmp/dummy.mov')
|
64
|
+
thread.join
|
65
|
+
end
|
66
|
+
end
|
67
|
+
describe 'for remote files' do
|
68
|
+
before do
|
69
|
+
request = mock('request')
|
70
|
+
Net::HTTP::Post.should_receive(:new).and_return(request)
|
71
|
+
request.stub :set_form_data
|
72
|
+
|
73
|
+
http = mock('net_http')
|
74
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
75
|
+
|
76
|
+
http.stub :use_ssl=
|
77
|
+
http.stub :verify_mode=
|
78
|
+
|
79
|
+
response = mock('response')
|
80
|
+
http.should_receive(:request).and_return(response)
|
81
|
+
|
82
|
+
response.should_receive(:code).exactly(2).and_return('200')
|
83
|
+
response.should_receive(:body).and_return('OK')
|
84
|
+
end
|
85
|
+
it 'web file: imports the file' do
|
86
|
+
thread = WistiaUploader.post_file_to_wistia('', {api_password: 'pass', project_id: 5}, 'http://fakedomain.cc/dummy.mov')
|
87
|
+
thread.join
|
88
|
+
end
|
89
|
+
it 'ssl web file: imports the file' do
|
90
|
+
thread = WistiaUploader.post_file_to_wistia('', {api_password: 'pass', project_id: 5}, 'https://fakedomain.cc/dummy.mov')
|
91
|
+
thread.join
|
92
|
+
end
|
93
|
+
it 'ftp file: imports the file' do
|
94
|
+
thread = WistiaUploader.post_file_to_wistia('', {api_password: 'pass', project_id: 5}, 'ftp://fakedomain.cc/dummy.mov')
|
95
|
+
thread.join
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'private class methods' do
|
102
|
+
describe '#perform_http_post' do
|
103
|
+
describe 'with local file' do
|
104
|
+
it 'performs upload' do
|
105
|
+
WistiaUploader.stub(:file_is_local?).and_return(true)
|
106
|
+
WistiaUploader.should_receive(:upload_local_file).exactly(1)
|
107
|
+
WistiaUploader.send :perform_http_post, nil, nil, nil, nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
describe 'with remote file' do
|
111
|
+
it 'performs import' do
|
112
|
+
WistiaUploader.stub(:file_is_local?).and_return(false)
|
113
|
+
WistiaUploader.should_receive(:import_remote_file).exactly(1)
|
114
|
+
WistiaUploader.send :perform_http_post, nil, nil, nil, nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
describe '#file_is_local? and #file_is_remote?' do
|
119
|
+
it 'works for http (non-ssl) files' do
|
120
|
+
file_path = 'http://example.com/movie.mov'
|
121
|
+
WistiaUploader.send(:file_is_local?, file_path).should be_false
|
122
|
+
WistiaUploader.send(:file_is_remote?, file_path).should be_true
|
123
|
+
end
|
124
|
+
it 'works for http (ssl) files' do
|
125
|
+
file_path = 'https://example.com/movie.mov'
|
126
|
+
WistiaUploader.send(:file_is_local?, file_path).should be_false
|
127
|
+
WistiaUploader.send(:file_is_remote?, file_path).should be_true
|
128
|
+
end
|
129
|
+
it 'works for ftp files' do
|
130
|
+
file_path = 'ftp://example.com/movie.mov'
|
131
|
+
WistiaUploader.send(:file_is_local?, file_path).should be_false
|
132
|
+
WistiaUploader.send(:file_is_remote?, file_path).should be_true
|
133
|
+
end
|
134
|
+
it 'works for local files' do
|
135
|
+
file_path = '/var/www/movie.mov'
|
136
|
+
WistiaUploader.send(:file_is_local?, file_path).should be_true
|
137
|
+
WistiaUploader.send(:file_is_remote?, file_path).should be_false
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/wistia-uploader.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wistia-uploader"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jason Lawrence"]
|
12
|
-
s.date = "
|
11
|
+
s.authors = ["Robby Grossman", "Jason Lawrence", "Brendan Schwartz"]
|
12
|
+
s.date = "2013-08-19"
|
13
13
|
s.description = "A simple CLI uploader for Wistia users."
|
14
|
-
s.email = "
|
14
|
+
s.email = "dev@wistia.com"
|
15
15
|
s.executables = ["wistia-uploader"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
|
+
".rvmrc",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -27,14 +28,14 @@ Gem::Specification.new do |s|
|
|
27
28
|
"VERSION",
|
28
29
|
"bin/wistia-uploader",
|
29
30
|
"lib/wistia-uploader.rb",
|
30
|
-
"
|
31
|
-
"
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"spec/wistia-uploader_spec.rb",
|
32
33
|
"wistia-uploader.gemspec"
|
33
34
|
]
|
34
35
|
s.homepage = "http://github.com/wistia/wistia-uploader"
|
35
36
|
s.licenses = ["MIT"]
|
36
37
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.25"
|
38
39
|
s.summary = "A simple CLI uploader for Wistia users."
|
39
40
|
|
40
41
|
if s.respond_to? :specification_version then
|
@@ -45,14 +46,12 @@ Gem::Specification.new do |s|
|
|
45
46
|
s.add_runtime_dependency(%q<multipart-post>, [">= 1.1.5"])
|
46
47
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
48
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
|
49
49
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
50
|
else
|
51
51
|
s.add_dependency(%q<json>, [">= 0"])
|
52
52
|
s.add_dependency(%q<multipart-post>, [">= 1.1.5"])
|
53
53
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
54
54
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
-
s.add_dependency(%q<bundler>, ["~> 1.1.4"])
|
56
55
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
56
|
end
|
58
57
|
else
|
@@ -60,7 +59,6 @@ Gem::Specification.new do |s|
|
|
60
59
|
s.add_dependency(%q<multipart-post>, [">= 1.1.5"])
|
61
60
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
62
61
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
-
s.add_dependency(%q<bundler>, ["~> 1.1.4"])
|
64
62
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
65
63
|
end
|
66
64
|
end
|
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wistia-uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
+
- Robby Grossman
|
8
9
|
- Jason Lawrence
|
10
|
+
- Brendan Schwartz
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: json
|
@@ -75,22 +77,6 @@ dependencies:
|
|
75
77
|
- - ~>
|
76
78
|
- !ruby/object:Gem::Version
|
77
79
|
version: '3.12'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: bundler
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 1.1.4
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 1.1.4
|
94
80
|
- !ruby/object:Gem::Dependency
|
95
81
|
name: jeweler
|
96
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +94,7 @@ dependencies:
|
|
108
94
|
- !ruby/object:Gem::Version
|
109
95
|
version: 1.8.4
|
110
96
|
description: A simple CLI uploader for Wistia users.
|
111
|
-
email:
|
97
|
+
email: dev@wistia.com
|
112
98
|
executables:
|
113
99
|
- wistia-uploader
|
114
100
|
extensions: []
|
@@ -117,6 +103,7 @@ extra_rdoc_files:
|
|
117
103
|
- README.md
|
118
104
|
files:
|
119
105
|
- .document
|
106
|
+
- .rvmrc
|
120
107
|
- Gemfile
|
121
108
|
- Gemfile.lock
|
122
109
|
- LICENSE.txt
|
@@ -125,8 +112,8 @@ files:
|
|
125
112
|
- VERSION
|
126
113
|
- bin/wistia-uploader
|
127
114
|
- lib/wistia-uploader.rb
|
128
|
-
-
|
129
|
-
-
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/wistia-uploader_spec.rb
|
130
117
|
- wistia-uploader.gemspec
|
131
118
|
homepage: http://github.com/wistia/wistia-uploader
|
132
119
|
licenses:
|
@@ -143,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
130
|
version: '0'
|
144
131
|
segments:
|
145
132
|
- 0
|
146
|
-
hash:
|
133
|
+
hash: 4405734978225036635
|
147
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
135
|
none: false
|
149
136
|
requirements:
|
@@ -152,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
139
|
version: '0'
|
153
140
|
requirements: []
|
154
141
|
rubyforge_project:
|
155
|
-
rubygems_version: 1.8.
|
142
|
+
rubygems_version: 1.8.25
|
156
143
|
signing_key:
|
157
144
|
specification_version: 3
|
158
145
|
summary: A simple CLI uploader for Wistia users.
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'wistia-uploader'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|