wistia-uploader 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/bin/wistia-uploader +35 -15
- data/lib/wistia-uploader.rb +3 -0
- data/wistia-uploader.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/wistia-uploader
CHANGED
@@ -11,8 +11,8 @@ require_relative '../lib/wistia-uploader'
|
|
11
11
|
options = {}
|
12
12
|
|
13
13
|
# Required and config-loadable option sets.
|
14
|
-
required = Set.new [:api_password, :
|
15
|
-
loadable = Set.new([:contact_id]) + required
|
14
|
+
required = Set.new [:api_password, :media_file]
|
15
|
+
loadable = Set.new([:contact_id, :project_id]) + required
|
16
16
|
|
17
17
|
OptionParser.new do |opts|
|
18
18
|
opts.banner = "Usage: wistia-uploader [options]"
|
@@ -31,8 +31,12 @@ OptionParser.new do |opts|
|
|
31
31
|
|
32
32
|
opts.separator "General options:"
|
33
33
|
|
34
|
-
opts.on("-
|
35
|
-
options[:
|
34
|
+
opts.on("-q", "--quiet", "Silence output") do |q|
|
35
|
+
options[:quiet] = q
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-j", "--json", "Output JSON") do |j|
|
39
|
+
options[:json] = j
|
36
40
|
end
|
37
41
|
|
38
42
|
opts.separator ""
|
@@ -42,10 +46,6 @@ OptionParser.new do |opts|
|
|
42
46
|
options[:api_password] = api_password
|
43
47
|
end
|
44
48
|
|
45
|
-
opts.on("-p", "--project-id PROJECT_ID", "The hashed id of the Wistia project to", "upload to.") do |project_id|
|
46
|
-
options[:project_id] = project_id
|
47
|
-
end
|
48
|
-
|
49
49
|
opts.on("-f", "--media-file MEDIA_FILE", "The local path of the media file to be", "uploaded.") do |media_file|
|
50
50
|
options[:media_file] = media_file
|
51
51
|
end
|
@@ -53,6 +53,10 @@ OptionParser.new do |opts|
|
|
53
53
|
opts.separator ""
|
54
54
|
opts.separator "Optional:"
|
55
55
|
|
56
|
+
opts.on("-p", "--project-id PROJECT_ID", "The hashed id of the Wistia project to", "upload to.") do |project_id|
|
57
|
+
options[:project_id] = project_id
|
58
|
+
end
|
59
|
+
|
56
60
|
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|
|
57
61
|
options[:media_name] = media_name
|
58
62
|
end
|
@@ -68,21 +72,25 @@ OptionParser.new do |opts|
|
|
68
72
|
|
69
73
|
end.parse!
|
70
74
|
|
75
|
+
# If there's anything left in ARGV after options parsing, assume it's a path
|
76
|
+
# to a media file.
|
77
|
+
if ARGV[0]
|
78
|
+
options[:media_file] = ARGV[0]
|
79
|
+
end
|
80
|
+
|
71
81
|
# Load defaults from ~/.wistia.conf, if present. Only valid loadable options
|
72
82
|
# not already specified on the CLI will be initialized in this manner.
|
73
83
|
if File.exists? File.expand_path("~/.wistia.conf")
|
74
|
-
puts "Found ~/.wistia.conf, loading defaults!" if options[:
|
84
|
+
puts "Found ~/.wistia.conf, loading defaults!" if !options[:quiet]
|
75
85
|
File.open(File.expand_path("~/.wistia.conf")) do |conf|
|
76
86
|
conf.readlines.reject{|l|l.strip.start_with?('#')}.each do |line|
|
77
87
|
k, v = line.split("=").map { |i| i.strip }
|
78
88
|
next if (k.empty? || v.empty?)
|
79
89
|
if (loadable.include?(k.to_sym) && !options.include?(k.to_sym))
|
80
|
-
puts " #{k}='#{v}'" if options[:verbose]
|
81
90
|
options[k.to_sym] = v
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
85
|
-
puts "" if options[:verbose]
|
86
94
|
end
|
87
95
|
|
88
96
|
# Ensure that we have all required parameters.
|
@@ -99,20 +107,32 @@ unless options.keys.to_set.superset?(required)
|
|
99
107
|
end
|
100
108
|
|
101
109
|
# Ok, time to upload!
|
102
|
-
$stdout.write("Uploading '#{options[:media_file]}'
|
110
|
+
$stdout.write("Uploading '#{options[:media_file]}' ...") if !options[:quiet]
|
103
111
|
$stdout.flush
|
104
112
|
begin
|
113
|
+
unless File.exists? options[:media_file]
|
114
|
+
puts "ERROR: The file '#{options[:media_file]}' doesn't seem to exist."
|
115
|
+
end
|
116
|
+
|
105
117
|
result = WistiaUploader.upload_media(
|
106
118
|
options[:api_password], options[:project_id],
|
107
119
|
options[:media_file], options[:media_name], options[:contact_id])
|
108
|
-
puts " Done!" if options[:
|
120
|
+
puts " Done!" if !options[:quiet]
|
121
|
+
|
122
|
+
data = JSON.parse(result)
|
109
123
|
|
110
124
|
# Pretty-print the resultant media details.
|
111
|
-
if options[:
|
112
|
-
data = JSON.parse(result)
|
125
|
+
if !options[:quiet]
|
113
126
|
puts "Media (id:#{data['id']}) successfully created."
|
127
|
+
puts " bytes: #{data['filesize']}"
|
114
128
|
puts " md5: #{data['md5']}"
|
115
129
|
end
|
130
|
+
|
131
|
+
# Spit out the JSON data returned from wistia.
|
132
|
+
if options[:json]
|
133
|
+
puts data
|
134
|
+
end
|
116
135
|
rescue
|
117
136
|
puts "ERROR! Upload failed. Msg: #{$!}"
|
137
|
+
puts "\t" + $!.backtrace.join("\n\t")
|
118
138
|
end
|
data/lib/wistia-uploader.rb
CHANGED
@@ -17,6 +17,9 @@ class WistiaUploader
|
|
17
17
|
def self.post_file_to_wistia(path, data, file, timeout=nil)
|
18
18
|
uri = URI(UPLOAD_URL + path)
|
19
19
|
|
20
|
+
# Sanitize the params hash.
|
21
|
+
data.reject! { |k,v| (v == nil) || v.empty? }
|
22
|
+
|
20
23
|
http = Net::HTTP.new(uri.host, uri.port)
|
21
24
|
http.use_ssl = true if (uri.scheme == 'https')
|
22
25
|
|
data/wistia-uploader.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wistia-uploader"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Lawrence"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-10"
|
13
13
|
s.description = "A simple CLI uploader for Wistia users."
|
14
14
|
s.email = "jason@wistia.com"
|
15
15
|
s.executables = ["wistia-uploader"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wistia-uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash: -
|
146
|
+
hash: -704925937519016139
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|