wistia-uploader 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'json'
4
+ gem 'multipart-post', '>= 1.1.5'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.4"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.8)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ git (1.2.5)
8
+ i18n (0.6.1)
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.5)
15
+ multi_json (1.3.6)
16
+ multipart-post (1.1.5)
17
+ rake (0.9.2.2)
18
+ rdoc (3.12)
19
+ json (~> 1.4)
20
+ shoulda (3.1.1)
21
+ shoulda-context (~> 1.0)
22
+ shoulda-matchers (~> 1.2)
23
+ shoulda-context (1.0.0)
24
+ shoulda-matchers (1.3.0)
25
+ activesupport (>= 3.0.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.1.4)
32
+ jeweler (~> 1.8.4)
33
+ json
34
+ multipart-post (>= 1.1.5)
35
+ rdoc (~> 3.12)
36
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jason Lawrence of Wistia, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ wistia-uploader
2
+ ===============
3
+
4
+ A simple command line media upload client for Wistia users.
5
+
6
+ Run 'bin/wistia-uploader -h' for additional information.
7
+
8
+ Configuration
9
+ -------------
10
+
11
+ While not required for use, defaults for various required parameters may be
12
+ supplied via the '~/.wistia.conf' configuration file in the form of simple
13
+ key/value pairs. Example:
14
+
15
+ # Credentials for foo.wistia.com
16
+ api_password = <API_PASSWORD>
17
+ project_id = <PROJECT_HASHED_ID>
18
+
19
+ A Wistia 'contact_id' may also be specified, otherwise the account owner will
20
+ be inferred from the project.
21
+
22
+ Copyright
23
+ ---------
24
+
25
+ Copyright (c) 2012 Jason Lawrence of Wistia, Inc.
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "wistia-uploader"
18
+ gem.homepage = "http://github.com/wistia/wistia-uploader"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A simple CLI uploader for Wistia users.}
21
+ gem.description = %Q{A simple CLI uploader for Wistia users.}
22
+ gem.email = "jason@wistia.com"
23
+ gem.authors = ["Jason Lawrence"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "wistia-uploader #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # A simple CLI media uploader for Wistia.
4
+
5
+ require 'set'
6
+ require 'json'
7
+ require 'optparse'
8
+
9
+ require_relative '../lib/wistia-uploader'
10
+
11
+ options = {}
12
+
13
+ # Required and config-loadable option sets.
14
+ required = Set.new [:api_password, :project_id, :media_file]
15
+ loadable = Set.new([:contact_id]) + required
16
+
17
+ OptionParser.new do |opts|
18
+ opts.banner = "Usage: wistia-uploader [options]"
19
+
20
+ opts.separator ""
21
+ opts.separator "Description:"
22
+ opts.separator " Upload media files to a Wistia project."
23
+ opts.separator ""
24
+ opts.separator "Configuration:"
25
+ opts.separator " Default values for required options may be specified as"
26
+ opts.separator " newline separated key=value pairs in '~/.wistia.conf'."
27
+ opts.separator ""
28
+ opts.separator " Options provided in this manner will be overridden if"
29
+ opts.separator " specified on the command line."
30
+ opts.separator ""
31
+
32
+ opts.separator "General options:"
33
+
34
+ opts.on("-v", "--[no-]verbose", "Verbose output") do |v|
35
+ options[:verbose] = v
36
+ end
37
+
38
+ opts.separator ""
39
+ opts.separator "Required options:"
40
+
41
+ opts.on("-k", "--api-password API_PASSWORD", "The Wistia API password.") do |api_password|
42
+ options[:api_password] = api_password
43
+ end
44
+
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
+ opts.on("-f", "--media-file MEDIA_FILE", "The local path of the media file to be", "uploaded.") do |media_file|
50
+ options[:media_file] = media_file
51
+ end
52
+
53
+ opts.separator ""
54
+ opts.separator "Optional:"
55
+
56
+ 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
+ options[:media_name] = media_name
58
+ end
59
+
60
+ 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|
61
+ options[:contact_id] = contact_id
62
+ end
63
+
64
+ opts.on_tail("-h", "--help", "Show this message") do
65
+ puts opts
66
+ exit
67
+ end
68
+
69
+ end.parse!
70
+
71
+ # Load defaults from ~/.wistia.conf, if present. Only valid loadable options
72
+ # not already specified on the CLI will be initialized in this manner.
73
+ if File.exists? File.expand_path("~/.wistia.conf")
74
+ puts "Found ~/.wistia.conf, loading defaults!" if options[:verbose]
75
+ File.open(File.expand_path("~/.wistia.conf")) do |conf|
76
+ conf.readlines.reject{|l|l.strip.start_with?('#')}.each do |line|
77
+ k, v = line.split("=").map { |i| i.strip }
78
+ next if (k.empty? || v.empty?)
79
+ if (loadable.include?(k.to_sym) && !options.include?(k.to_sym))
80
+ puts " #{k}='#{v}'" if options[:verbose]
81
+ options[k.to_sym] = v
82
+ end
83
+ end
84
+ end
85
+ puts "" if options[:verbose]
86
+ end
87
+
88
+ # Ensure that we have all required parameters.
89
+ unless options.keys.to_set.superset?(required)
90
+ puts "ERROR: You're missing some required options! Please specify:"
91
+ puts ""
92
+ missing = required - options.keys.to_set
93
+ missing.to_a.sort.each do |m|
94
+ puts " --#{m.to_s.gsub(/_/,"-")}"
95
+ end
96
+ puts ""
97
+ puts "Use '-h' to see the help documentation."
98
+ exit
99
+ end
100
+
101
+ # Ok, time to upload!
102
+ $stdout.write("Uploading '#{options[:media_file]}' to Wistia...") if options[:verbose]
103
+ $stdout.flush
104
+ begin
105
+ result = WistiaUploader.upload_media(
106
+ options[:api_password], options[:project_id],
107
+ options[:media_file], options[:media_name], options[:contact_id])
108
+ puts " Done!" if options[:verbose]
109
+
110
+ # Pretty-print the resultant media details.
111
+ if options[:verbose]
112
+ data = JSON.parse(result)
113
+ puts "Media (id:#{data['id']}) successfully created."
114
+ puts " md5: #{data['md5']}"
115
+ end
116
+ rescue
117
+ puts "ERROR! Upload failed. Msg: #{$!}"
118
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require 'net/http/post/multipart'
3
+
4
+ UPLOAD_URL = "https://upload.wistia.com/"
5
+
6
+ class WistiaUploader
7
+
8
+ def self.upload_media(api_pass, project, file, name=nil, contact=nil)
9
+ params = { :api_password => api_pass, :project_id => project }
10
+ params[:contact_id] = contact if contact
11
+ params[:name] = name if name
12
+
13
+ code, body = self.post_file_to_wistia('', params, file)
14
+ return body
15
+ end
16
+
17
+ def self.post_file_to_wistia(path, data, file, timeout=nil)
18
+ uri = URI(UPLOAD_URL + path)
19
+
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ http.use_ssl = true if (uri.scheme == 'https')
22
+
23
+ # Set the connection timeouts, if specified
24
+ if timeout
25
+ http.ssl_timeout = 10
26
+ http.open_timeout = 10
27
+ http.read_timeout = 10
28
+ end
29
+
30
+ media = File.open(file)
31
+ req = Net::HTTP::Post::Multipart.new uri.request_uri, data.merge({
32
+ 'file' => UploadIO.new(media, 'application/octet-stream', File.basename(file))
33
+ })
34
+ res = http.request(req)
35
+ media.close
36
+
37
+ return [res.code, res.body]
38
+ end
39
+
40
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWistiaUploader < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "wistia-uploader"
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Lawrence"]
12
+ s.date = "2012-09-26"
13
+ s.description = "A simple CLI uploader for Wistia users."
14
+ s.email = "jason@wistia.com"
15
+ s.executables = ["wistia-uploader"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/wistia-uploader",
29
+ "lib/wistia-uploader.rb",
30
+ "test/helper.rb",
31
+ "test/test_wistia-uploader.rb",
32
+ "wistia-uploader.gemspec"
33
+ ]
34
+ s.homepage = "http://github.com/wistia/wistia-uploader"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "A simple CLI uploader for Wistia users."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<json>, [">= 0"])
45
+ s.add_runtime_dependency(%q<multipart-post>, [">= 1.1.5"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ else
51
+ s.add_dependency(%q<json>, [">= 0"])
52
+ s.add_dependency(%q<multipart-post>, [">= 1.1.5"])
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<json>, [">= 0"])
60
+ s.add_dependency(%q<multipart-post>, [">= 1.1.5"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
65
+ end
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wistia-uploader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Lawrence
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: multipart-post
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: shoulda
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ 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
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.4
110
+ description: A simple CLI uploader for Wistia users.
111
+ email: jason@wistia.com
112
+ executables:
113
+ - wistia-uploader
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - .document
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - bin/wistia-uploader
127
+ - lib/wistia-uploader.rb
128
+ - test/helper.rb
129
+ - test/test_wistia-uploader.rb
130
+ - wistia-uploader.gemspec
131
+ homepage: http://github.com/wistia/wistia-uploader
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ segments:
145
+ - 0
146
+ hash: -2139810491125213326
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.24
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: A simple CLI uploader for Wistia users.
159
+ test_files: []