zencoder 2.2.2 → 2.3.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.
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class Account < Zencoder
1
+ module Zencoder
2
+ class Account < Base
3
3
 
4
4
  def self.create(params={}, options={})
5
5
  HTTP.post("#{options[:base_url] || base_url}/account", encode(params, options[:format]), options)
@@ -0,0 +1,82 @@
1
+ module Zencoder
2
+ class Base
3
+
4
+ def self.api_key
5
+ Zencoder.api_key
6
+ end
7
+
8
+ def self.base_url
9
+ Zencoder.base_url
10
+ end
11
+
12
+ def self.encode(content, format=nil)
13
+ if content.is_a?(String)
14
+ content
15
+ elsif format.to_s == 'xml'
16
+ if content.is_a?(Hash) && content.keys.size == 1
17
+ content[content.keys.first].to_xml(:root => content.keys.first)
18
+ else
19
+ content.to_xml
20
+ end
21
+ else
22
+ content.to_json
23
+ end
24
+ end
25
+
26
+ def encode(content, format=nil)
27
+ self.class.encode(content, format)
28
+ end
29
+
30
+ def self.decode(content, format=nil)
31
+ if content.is_a?(String)
32
+ if format.to_s == 'xml'
33
+ Hash.from_xml(content)
34
+ else
35
+ ActiveSupport::JSON.decode(content)
36
+ end
37
+ else
38
+ content
39
+ end
40
+ end
41
+
42
+ def decode(content, format=nil)
43
+ self.class.decode(content, format)
44
+ end
45
+
46
+
47
+ protected
48
+
49
+ def self.apply_api_key(params, format=nil)
50
+ if api_key
51
+ decoded_params = decode(params, format).with_indifferent_access
52
+
53
+ if decoded_params[:api_request]
54
+ decoded_params[:api_request] = decoded_params[:api_request].with_indifferent_access
55
+ end
56
+
57
+ if format.to_s == 'xml'
58
+ if !(decoded_params[:api_request] && decoded_params[:api_request][:api_key])
59
+ decoded_params[:api_request] ||= {}.with_indifferent_access
60
+ decoded_params[:api_request][:api_key] = api_key
61
+ end
62
+ else
63
+ decoded_params['api_key'] = api_key unless decoded_params['api_key']
64
+ end
65
+
66
+ decoded_params
67
+ else
68
+ params
69
+ end
70
+ end
71
+
72
+ def self.merge_params(options, params)
73
+ if options[:params]
74
+ options[:params] = options[:params].merge(params)
75
+ options
76
+ else
77
+ options.merge(:params => params)
78
+ end
79
+ end
80
+
81
+ end
82
+ end
@@ -1,5 +1,6 @@
1
- class Zencoder
1
+ module Zencoder
2
2
  class Error < StandardError
3
+
3
4
  def initialize(error_or_message)
4
5
  if error_or_message.is_a?(Exception)
5
6
  @error = error_or_message
@@ -38,4 +39,5 @@ class Zencoder
38
39
  end
39
40
 
40
41
  class HTTPError < Error; end
42
+
41
43
  end
@@ -1,8 +1,8 @@
1
1
  # Ruby's Net/HTTP Sucks
2
2
  # Borrowed root cert checking from http://redcorundum.blogspot.com/2008/03/ssl-certificates-and-nethttps.html
3
3
 
4
- class Zencoder
5
- class HTTP < Zencoder
4
+ module Zencoder
5
+ class HTTP < Base
6
6
  class NetHTTP
7
7
 
8
8
  attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :skip_ssl_verify, :options
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class HTTP < Zencoder
1
+ module Zencoder
2
+ class HTTP < Base
3
3
  class Typhoeus
4
4
 
5
5
  def self.post(url, options={})
data/lib/zencoder/http.rb CHANGED
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class HTTP < Zencoder
1
+ module Zencoder
2
+ class HTTP < Base
3
3
 
4
4
  attr_accessor :body, :url, :options, :method, :format
5
5
 
data/lib/zencoder/job.rb CHANGED
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class Job < Zencoder
1
+ module Zencoder
2
+ class Job < Base
3
3
 
4
4
  def self.create(params={}, options={})
5
5
  params = apply_api_key(params, options[:format])
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class Notification < Zencoder
1
+ module Zencoder
2
+ class Notification < Base
3
3
 
4
4
  def self.list(options={})
5
5
  params = {:api_key => options.delete(:api_key) || api_key,
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class Output < Zencoder
1
+ module Zencoder
2
+ class Output < Base
3
3
 
4
4
  def self.progress(output_id, options={})
5
5
  params = {:api_key => options.delete(:api_key) || api_key}
@@ -7,4 +7,4 @@ class Zencoder
7
7
  end
8
8
 
9
9
  end
10
- end
10
+ end
@@ -1,5 +1,5 @@
1
- class Zencoder
2
- class Response < Zencoder
1
+ module Zencoder
2
+ class Response < Base
3
3
 
4
4
  attr_accessor :code, :body, :raw_body, :raw_response
5
5
 
@@ -1,3 +1,3 @@
1
- class Zencoder
2
- GEM_VERSION = '2.2.2'
1
+ module Zencoder
2
+ GEM_VERSION = '2.3.0'
3
3
  end
@@ -1,85 +1,17 @@
1
- class Zencoder
1
+ module Zencoder
2
2
 
3
- cattr_writer :base_url
4
- cattr_writer :api_key
3
+ mattr_writer :api_key
4
+ mattr_writer :base_url
5
+
6
+ self.api_key = nil
7
+ self.base_url = 'https://app.zencoder.com/api'
5
8
 
6
9
  def self.api_key
7
10
  @@api_key || ENV['ZENCODER_API_KEY']
8
11
  end
9
12
 
10
- self.base_url = 'https://app.zencoder.com/api'
11
-
12
13
  def self.base_url(env=nil)
13
14
  @@base_url
14
15
  end
15
16
 
16
- def self.encode(content, format=nil)
17
- if content.is_a?(String)
18
- content
19
- elsif format.to_s == 'xml'
20
- if content.is_a?(Hash) && content.keys.size == 1
21
- content[content.keys.first].to_xml(:root => content.keys.first)
22
- else
23
- content.to_xml
24
- end
25
- else
26
- content.to_json
27
- end
28
- end
29
-
30
- def encode(content, format=nil)
31
- self.class.encode(content, format)
32
- end
33
-
34
- def self.decode(content, format=nil)
35
- if content.is_a?(String)
36
- if format.to_s == 'xml'
37
- Hash.from_xml(content)
38
- else
39
- ActiveSupport::JSON.decode(content)
40
- end
41
- else
42
- content
43
- end
44
- end
45
-
46
- def decode(content, format=nil)
47
- self.class.decode(content, format)
48
- end
49
-
50
-
51
- protected
52
-
53
- def self.apply_api_key(params, format=nil)
54
- if api_key
55
- decoded_params = decode(params, format).with_indifferent_access
56
-
57
- if decoded_params[:api_request]
58
- decoded_params[:api_request] = decoded_params[:api_request].with_indifferent_access
59
- end
60
-
61
- if format.to_s == 'xml'
62
- if !(decoded_params[:api_request] && decoded_params[:api_request][:api_key])
63
- decoded_params[:api_request] ||= {}.with_indifferent_access
64
- decoded_params[:api_request][:api_key] = api_key
65
- end
66
- else
67
- decoded_params['api_key'] = api_key unless decoded_params['api_key']
68
- end
69
-
70
- decoded_params
71
- else
72
- params
73
- end
74
- end
75
-
76
- def self.merge_params(options, params)
77
- if options[:params]
78
- options[:params] = options[:params].merge(params)
79
- options
80
- else
81
- options.merge(:params => params)
82
- end
83
- end
84
-
85
17
  end
data/lib/zencoder.rb CHANGED
@@ -13,6 +13,7 @@ end
13
13
  # Zencoder
14
14
  require 'zencoder/extensions'
15
15
  require 'zencoder/zencoder'
16
+ require 'zencoder/base'
16
17
  require 'zencoder/http/net_http'
17
18
  require 'zencoder/http/typhoeus'
18
19
  require 'zencoder/http'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zencoder
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 2
8
- - 2
9
- version: 2.2.2
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Nathan Sutton
@@ -22,9 +23,11 @@ dependencies:
22
23
  name: activesupport
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 3
28
31
  segments:
29
32
  - 0
30
33
  version: "0"
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: i18n
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 3
40
45
  segments:
41
46
  - 0
42
47
  version: "0"
@@ -46,9 +51,11 @@ dependencies:
46
51
  name: shoulda
47
52
  prerelease: false
48
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
49
55
  requirements:
50
56
  - - ">="
51
57
  - !ruby/object:Gem::Version
58
+ hash: 3
52
59
  segments:
53
60
  - 0
54
61
  version: "0"
@@ -58,9 +65,11 @@ dependencies:
58
65
  name: mocha
59
66
  prerelease: false
60
67
  requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
61
69
  requirements:
62
70
  - - ">="
63
71
  - !ruby/object:Gem::Version
72
+ hash: 3
64
73
  segments:
65
74
  - 0
66
75
  version: "0"
@@ -70,37 +79,27 @@ dependencies:
70
79
  name: webmock
71
80
  prerelease: false
72
81
  requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
84
  - - ">="
75
85
  - !ruby/object:Gem::Version
86
+ hash: 3
76
87
  segments:
77
88
  - 0
78
89
  version: "0"
79
90
  type: :development
80
91
  version_requirements: *id005
81
- description: Zencoder <http://zencoder.com> integration library and CLI client.
92
+ description: Zencoder <http://zencoder.com> integration library.
82
93
  email: info@zencoder.com
83
- executables:
84
- - zencoder
94
+ executables: []
95
+
85
96
  extensions: []
86
97
 
87
98
  extra_rdoc_files: []
88
99
 
89
100
  files:
90
- - bin/zencoder
91
101
  - lib/zencoder/account.rb
92
- - lib/zencoder/cli/auth.rb
93
- - lib/zencoder/cli/command.rb
94
- - lib/zencoder/cli/commands/account.rb
95
- - lib/zencoder/cli/commands/base.rb
96
- - lib/zencoder/cli/commands/jobs.rb
97
- - lib/zencoder/cli/commands/outputs.rb
98
- - lib/zencoder/cli/commands/plugins.rb
99
- - lib/zencoder/cli/commands/setup.rb
100
- - lib/zencoder/cli/helpers.rb
101
- - lib/zencoder/cli/plugin.rb
102
- - lib/zencoder/cli/response.rb
103
- - lib/zencoder/cli.rb
102
+ - lib/zencoder/base.rb
104
103
  - lib/zencoder/errors.rb
105
104
  - lib/zencoder/extensions.rb
106
105
  - lib/zencoder/http/net_http.rb
@@ -126,25 +125,29 @@ rdoc_options: []
126
125
  require_paths:
127
126
  - lib
128
127
  required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
+ hash: 3
132
133
  segments:
133
134
  - 0
134
135
  version: "0"
135
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
136
138
  requirements:
137
139
  - - ">="
138
140
  - !ruby/object:Gem::Version
141
+ hash: 3
139
142
  segments:
140
143
  - 0
141
144
  version: "0"
142
145
  requirements: []
143
146
 
144
147
  rubyforge_project: zencoder
145
- rubygems_version: 1.3.6
148
+ rubygems_version: 1.3.7
146
149
  signing_key:
147
150
  specification_version: 3
148
- summary: Zencoder <http://zencoder.com> integration library and CLI client.
151
+ summary: Zencoder <http://zencoder.com> integration library.
149
152
  test_files: []
150
153
 
data/bin/zencoder DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("#{File.dirname(__FILE__)}/../lib")
3
- require 'zencoder/cli'
@@ -1,28 +0,0 @@
1
- require 'yaml'
2
-
3
- module ZencoderCLI
4
- module Auth
5
- extend ZencoderCLI::Helpers
6
- class << self
7
-
8
- def require_authentication(env)
9
- Zencoder.api_key ||= retrieve_api_key(env)
10
- end
11
-
12
- def retrieve_api_key(env)
13
- env = "production" if !env || env.blank?
14
- if File.exist?("#{home_directory}/.zencoder/api-key")
15
- keys = YAML.load_file("#{home_directory}/.zencoder/api-key")
16
- if keys[env].present?
17
- keys[env]
18
- else
19
- error "No API found for the #{env} environment. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
20
- end
21
- else
22
- error "No API keys found. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,41 +0,0 @@
1
- module ZencoderCLI
2
- module Command
3
- extend ZencoderCLI::Helpers
4
-
5
- class UnknownCommandName < RuntimeError; end
6
-
7
- mattr_accessor :commands
8
- self.commands = {}
9
-
10
- class << self
11
-
12
- def run(command, args, global_options={}, command_options={})
13
- ZencoderCLI::Auth.require_authentication(global_options[:environment]) unless command[/^setup/]
14
- pieces = command.split(":")
15
- if pieces.size == 1
16
- method_name = :run
17
- klass_name = pieces.first.camelize
18
- else
19
- method_name = pieces.pop
20
- klass_name = pieces.map(&:camelize).join("::")
21
- end
22
- klass = "ZencoderCLI::Command::#{klass_name}".constantize
23
- if klass.respond_to?(method_name)
24
- klass.send(method_name, args, global_options, command_options)
25
- else
26
- raise UnknownCommandName
27
- end
28
- rescue UnknownCommandName, NameError => e
29
- if e.class == UnknownCommandName || e.message[/uninitialized constant ZencoderCLI::Command::/]
30
- error "There is no command named #{command}. Use --help for more information."
31
- else
32
- raise e
33
- end
34
- end
35
-
36
- end
37
- end
38
- end
39
-
40
- require 'zencoder/cli/commands/base'
41
- Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |c| require c }
@@ -1,42 +0,0 @@
1
- module ZencoderCLI::Command
2
- class Account < Base
3
-
4
- provides "account", { "account:show" => "Show account information",
5
- "account:integration" => "Put your account in integration mode",
6
- "account:live" => "Take your account out of integration mode" }
7
-
8
- class << self
9
-
10
- def show(args, global_options, command_options)
11
- account = Zencoder::Account.details(:base_url => Zencoder.base_url(global_options[:environment])).body
12
- rows = []
13
- rows << ["Minutes Used", account["minutes_used"]]
14
- rows << ["Minutes Included", account["minutes_included"]]
15
- rows << ["Account State", account["account_state"].titleize]
16
- rows << ["Billing State", account["billing_state"].titleize]
17
- rows << ["Plan", account["plan"]]
18
- rows << ["Integration Mode", account["integration_mode"] ? "YES" : "NO"]
19
- puts table([{ :value => "Account", :colspan => 2 }], *rows)
20
- end
21
-
22
- def integration(args, global_options, command_options)
23
- response = Zencoder::Account.integration(:base_url => Zencoder.base_url(global_options[:environment]))
24
- if response.success?
25
- puts "Your account is now in integration mode."
26
- else
27
- puts "There was an unexpected problem."
28
- end
29
- end
30
-
31
- def live(args, global_options, command_options)
32
- response = Zencoder::Account.live(:base_url => Zencoder.base_url(global_options[:environment]))
33
- if response.success?
34
- puts "Your account is now able to process live jobs."
35
- else
36
- puts "You cannot turn off integration mode for this account."
37
- end
38
- end
39
-
40
- end
41
- end
42
- end
@@ -1,13 +0,0 @@
1
- module ZencoderCLI::Command
2
- class Base
3
- extend ZencoderCLI::Helpers
4
-
5
- class << self
6
-
7
- def provides(name, commands={})
8
- ZencoderCLI::Command.commands.merge!({ name => commands })
9
- end
10
-
11
- end
12
- end
13
- end
@@ -1,133 +0,0 @@
1
- module ZencoderCLI::Command
2
- class Jobs < Base
3
-
4
- provides "jobs", { "jobs:list" => { :description => "Lists the most recent jobs",
5
- :options => proc{|t|
6
- t.opt :number, "Number of jobs returned per page. Default 10.", :type => Integer
7
- t.opt :page, "Jobs page number. Default 1.", :type => Integer
8
- t.opt :long, "Will not truncate filenames.", :default => false
9
- }},
10
- "jobs:show" => "Show job details by ID",
11
- "jobs:resubmit" => "Resubmit a job by ID",
12
- "jobs:cancel" => "Cancels a job by ID",
13
- "jobs:delete" => "Deletes a job by ID" }
14
-
15
- class << self
16
-
17
- def list(args, global_options, command_options)
18
- jobs = Zencoder::Job.list(:base_url => Zencoder.base_url(global_options[:environment]), :per_page => command_options[:number] || 10, :page => command_options[:page] || 1).process_for_cli.body
19
- if jobs.any?
20
- jobs_table = table do |t|
21
- t.headings = ["ID", "Created", "Filename", "Duration", "Size", "Test", "State"]
22
- jobs.each do |job|
23
- duration = job["job"]["input_media_file"]["duration_in_ms"] ? (job["job"]["input_media_file"]["duration_in_ms"]/1000).to_s+"s" : "---"
24
- filesize = job["job"]["input_media_file"]["file_size_bytes"] ? ("%0.2f" % (job["job"]["input_media_file"]["file_size_bytes"].to_f/1.megabyte))+" MB" : "---"
25
- t << [
26
- job["job"]["id"],
27
- format_date(job["job"]["created_at"]),
28
- truncate(File.basename(job["job"]["input_media_file"]["url"]), :length => command_options[:long] ? 256 : 25),
29
- { :value => duration, :alignment => :right },
30
- { :value => filesize, :alignment => :right },
31
- job["job"]["test"] ? "YES" : "NO",
32
- job["job"]["state"].titleize
33
- ]
34
- end
35
- end
36
- puts jobs_table
37
- else
38
- puts "No jobs found."
39
- end
40
- end
41
-
42
- def show(args, global_options, command_options)
43
- job = Zencoder::Job.details(args.shift, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli.body["job"]
44
- rows = []
45
- rows << ["ID", job["id"]]
46
- rows << ["Created", format_date(job["created_at"])]
47
- rows << ["Finished", format_date(job["finished_at"])] if job["finished_at"]
48
- rows << ["Pass Through", job["pass_through"]] if job["pass_through"]
49
- rows << ["Test", job["test"] ? "YES" : "NO"]
50
- rows << ["State", job["state"].titleize]
51
- puts table([{ :value => "Job", :colspan => 2 }], *rows)
52
- puts
53
-
54
- input = job["input_media_file"]
55
- rows = []
56
- rows << ["ID", input["id"]]
57
- rows << ["URL", input["url"]]
58
- rows << ["State", input["state"].titleize]
59
- rows << ["Duration", (input["duration_in_ms"]/1000).to_s+" seconds"] if input["duration_in_ms"]
60
- rows << ["Size", ("%0.2f" % (input["file_size_bytes"].to_f/1.megabyte))+" MB"] if input["file_size_bytes"]
61
- rows << ["Format", input["format"]] if input["format"]
62
- if input["state"] == "finished"
63
- rows << :separator
64
- rows << ["Video Codec", input["video_codec"]] if input["video_codec"]
65
- rows << ["Resolution", input["width"].to_s+"x"+input["height"].to_s] if input["width"] && input["height"]
66
- rows << ["Video Bitrate", input["video_bitrate_in_kbps"].to_s+" Kbps"] if input["video_bitrate_in_kbps"]
67
- rows << ["Frame Rate", input["frame_rate"]] if input["frame_rate"]
68
- rows << :separator
69
- rows << ["Audio Codec", input["audio_codec"]] if input["audio_codec"]
70
- rows << ["Audio Bitrate", input["audio_bitrate_in_kbps"].to_s+" Kbps"] if input["audio_codec"]
71
- rows << ["Sample Rate", input["audio_sample_rate"]] if input["audio_sample_rate"]
72
- rows << ["Channels", input["channels"]] if input["channels"]
73
- end
74
- if input["error_class"] || input["error_message"]
75
- rows << :separator
76
- rows << ["Error Class", input["error_class"]] if input["error_class"]
77
- rows << ["Error Message", input["error_message"]] if input["error_message"]
78
- end
79
- puts table([{ :value => "Input", :colspan => 2 }], *rows)
80
- puts
81
-
82
- job["output_media_files"].each_with_index do |output, i|
83
- rows = []
84
- rows << ["ID", output["id"]]
85
- rows << ["Label", output["label"]] if output["label"]
86
- rows << ["URL", output["url"]]
87
- rows << ["State", output["state"].titleize]
88
- rows << ["Duration", (output["duration_in_ms"]/1000).to_s+" seconds"] if output["duration_in_ms"]
89
- rows << ["Size", ("%0.2f" % (output["file_size_bytes"].to_f/1.megabyte))+" MB"] if output["file_size_bytes"]
90
- rows << ["Format", output["format"]] if output["format"]
91
- if output["state"] == "finished"
92
- rows << :separator
93
- rows << ["Video Codec", output["video_codec"]] if output["video_codec"]
94
- rows << ["Resolution", output["width"].to_s+"x"+output["height"].to_s] if output["width"] && output["height"]
95
- rows << ["Video Bitrate", output["video_bitrate_in_kbps"].to_s+" Kbps"] if output["video_bitrate_in_kbps"]
96
- rows << ["Frame Rate", output["frame_rate"]] if output["frame_rate"]
97
- rows << :separator
98
- rows << ["Audio Codec", output["audio_codec"]] if output["audio_codec"]
99
- rows << ["Audio Bitrate", output["audio_bitrate_in_kbps"].to_s+" Kbps"] if output["audio_codec"]
100
- rows << ["Sample Rate", output["audio_sample_rate"]] if output["audio_sample_rate"]
101
- rows << ["Channels", output["channels"]] if output["channels"]
102
- end
103
- if output["error_class"] || output["error_message"]
104
- rows << :separator
105
- rows << ["Error Class", output["error_class"]] if output["error_class"]
106
- rows << ["Error Message", output["error_message"]] if output["error_message"]
107
- end
108
- puts table([{ :value => "Output ##{i+1}", :colspan => 2 }], *rows)
109
- puts
110
- end
111
- end
112
-
113
- def resubmit(args, global_options, command_options)
114
- job_id = args.shift
115
- response = Zencoder::Job.resubmit(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
116
- puts "Job ##{job_id} resubmitted."
117
- end
118
-
119
- def cancel(args, global_options, command_options)
120
- job_id = args.shift
121
- response = Zencoder::Job.cancel(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
122
- puts "Job ##{job_id} cancelled."
123
- end
124
-
125
- def delete(args, global_options, command_options)
126
- job_id = args.shift
127
- response = Zencoder::Job.delete(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
128
- puts "Job ##{job_id} deleted."
129
- end
130
-
131
- end
132
- end
133
- end
@@ -1,23 +0,0 @@
1
- module ZencoderCLI::Command
2
- class Outputs < Base
3
-
4
- provides "outputs", { "outputs:progress" => "Show output progress" }
5
-
6
- class << self
7
-
8
- def progress(args, global_options, command_options)
9
- output = Zencoder::Output.progress(args.shift, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli.body
10
- rows = []
11
- rows << ["State", output["state"].titleize]
12
- if output["state"] == "processing"
13
- rows << ["Event", output["current_event"].titleize]
14
- rows << ["Progress", output["progress"]]
15
- elsif output["state"] == "finished"
16
- rows << ["Progress", "100%"]
17
- end
18
- puts table([{ :value => "Output", :colspan => 2 }], *rows)
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- module ZencoderCLI::Command
2
- class Plugins < Base
3
-
4
- provides "plugins", { "plugins:list" => "Lists installed plugins",
5
- "plugins:install" => "Install a plugin via URL",
6
- "plugins:uninstall" => "Uninstall a plugin" }
7
-
8
- class << self
9
-
10
- def list(args, global_options, command_options)
11
- if ZencoderCLI::Plugin.list.any?
12
- puts "The following plugins are installed:"
13
- ZencoderCLI::Plugin.list.each do |plugin|
14
- display "* #{plugin}"
15
- end
16
- else
17
- display "There are no plugins installed."
18
- end
19
- end
20
-
21
- def install(args, global_options, command_options)
22
- plugin = ZencoderCLI::Plugin.new(args.shift)
23
- if plugin.install
24
- begin
25
- ZencoderCLI::Plugin.load_plugin(plugin.name)
26
- rescue Exception => e
27
- installation_failed(plugin, e.message)
28
- end
29
- display "#{plugin} installed."
30
- else
31
- error "Could not install #{plugin}. Please check the URL and try again."
32
- end
33
- end
34
-
35
- def uninstall(args, global_options, command_options)
36
- plugin = ZencoderCLI::Plugin.new(args.shift)
37
- plugin.uninstall
38
- display "#{plugin} uninstalled."
39
- end
40
-
41
- end
42
- end
43
- end
@@ -1,72 +0,0 @@
1
- require 'fileutils'
2
- require 'yaml'
3
-
4
- module ZencoderCLI::Command
5
- class Setup < Base
6
-
7
- provides "setup", { "setup" => "Caches authentication credentials",
8
- "setup:show" => "Shows your API keys",
9
- "setup:delete" => "Removes cached credentials and plugins" }
10
-
11
- class << self
12
-
13
- def run(args, global_options, command_options)
14
- display("Enter Your Zencoder API Key: ", false)
15
- save_api_key(global_options[:environment], ask)
16
- display "Your API key has been saved to #{home_directory}/.zencoder/api-key."
17
- end
18
-
19
- def show(args, global_options, command_options)
20
- if File.exist?("#{home_directory}/.zencoder/api-key")
21
- keys = YAML.load_file("#{home_directory}/.zencoder/api-key")
22
- if keys.length == 1
23
- display("Your API Key: ", false)
24
- puts keys.values.first
25
- else
26
- display("Your API Keys: ")
27
- puts table(nil, *keys.to_a)
28
- end
29
- else
30
- display("You have no API keys stored. Run `zencoder setup` to get started.")
31
- end
32
- end
33
-
34
- def delete(args, global_options, command_options)
35
- if confirm
36
- delete_setup
37
- display "#{home_directory}/.zencoder has been removed."
38
- else
39
- display "Ok, nothing changed."
40
- end
41
- end
42
-
43
-
44
- protected
45
-
46
- def save_api_key(environment, api_key)
47
- environment = "production" if !environment || environment.blank?
48
- begin
49
- FileUtils.mkdir_p("#{home_directory}/.zencoder")
50
- if File.exist?("#{home_directory}/.zencoder/api-key")
51
- key_envs = YAML.load_file("#{home_directory}/.zencoder/api-key")
52
- else
53
- key_envs = {}
54
- end
55
- key_envs[environment] = api_key
56
- File.open("#{home_directory}/.zencoder/api-key", 'w') do |out|
57
- YAML.dump(key_envs, out)
58
- end
59
- FileUtils.chmod 0700, "#{home_directory}/.zencoder"
60
- FileUtils.chmod 0600, "#{home_directory}/.zencoder/api-key"
61
- rescue Exception => e
62
- raise e
63
- end
64
- end
65
-
66
- def delete_setup
67
- FileUtils.rm_rf("#{home_directory}/.zencoder") if File.exist?("#{home_directory}/.zencoder")
68
- end
69
-
70
- end
71
- end
72
- end
@@ -1,61 +0,0 @@
1
- # Thank you Heroku gem.
2
-
3
- module ZencoderCLI
4
- module Helpers
5
-
6
- def home_directory
7
- running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
8
- end
9
-
10
- def running_on_windows?
11
- RUBY_PLATFORM =~ /mswin32|mingw32/
12
- end
13
-
14
- def running_on_a_mac?
15
- RUBY_PLATFORM =~ /-darwin\d/
16
- end
17
-
18
- def format_date(date)
19
- date = Time.parse(date) if date.is_a?(String)
20
- date.strftime("%Y-%m-%d %H:%M %Z")
21
- end
22
-
23
- def display(msg, newline=true)
24
- if newline
25
- puts(msg)
26
- else
27
- print(msg)
28
- STDOUT.flush
29
- end
30
- end
31
-
32
- def error(msg)
33
- STDERR.puts(msg)
34
- exit 1
35
- end
36
-
37
- def confirm(message="Are you sure you wish to continue? (y/N)?")
38
- display("#{message} ", false)
39
- ask.downcase == 'y'
40
- end
41
-
42
- def ask
43
- gets.strip
44
- rescue Interrupt
45
- puts
46
- exit
47
- end
48
-
49
- def truncate(text, *args)
50
- options = args.extract_options!
51
- options.reverse_merge!(:length => 30, :omission => "...")
52
-
53
- if text
54
- l = options[:length] - options[:omission].mb_chars.length
55
- chars = text.mb_chars
56
- (chars.length > options[:length] ? chars[0...l] + options[:omission] : text).to_s
57
- end
58
- end
59
-
60
- end
61
- end
@@ -1,76 +0,0 @@
1
- # based on the Rails Plugin
2
-
3
- module ZencoderCLI
4
- class Plugin
5
- class << self
6
- include ZencoderCLI::Helpers
7
- end
8
-
9
- attr_reader :name, :uri
10
-
11
- def self.directory
12
- File.expand_path("#{home_directory}/.zencoder/plugins")
13
- end
14
-
15
- def self.list
16
- Dir["#{directory}/*"].sort.map do |folder|
17
- File.basename(folder)
18
- end
19
- end
20
-
21
- def self.load!
22
- list.each do |plugin|
23
- begin
24
- load_plugin(plugin)
25
- rescue Exception => e
26
- display "Unable to load plugin: #{plugin}: #{e.message}"
27
- end
28
- end
29
- end
30
-
31
- def self.load_plugin(plugin)
32
- folder = "#{self.directory}/#{plugin}"
33
- $: << "#{folder}/lib" if File.directory? "#{folder}/lib"
34
- load "#{folder}/init.rb" if File.exists? "#{folder}/init.rb"
35
- end
36
-
37
- def initialize(uri)
38
- @uri = uri
39
- guess_name(uri)
40
- end
41
-
42
- def to_s
43
- name
44
- end
45
-
46
- def path
47
- "#{self.class.directory}/#{name}"
48
- end
49
-
50
- def install
51
- FileUtils.mkdir_p(path)
52
- Dir.chdir(path) do
53
- system("git init -q")
54
- if !system("git pull #{uri} -q")
55
- FileUtils.rm_rf path
56
- return false
57
- end
58
- end
59
- true
60
- end
61
-
62
- def uninstall
63
- FileUtils.rm_r path if File.directory?(path)
64
- end
65
-
66
-
67
- private
68
-
69
- def guess_name(url)
70
- @name = File.basename(url)
71
- @name = File.basename(File.dirname(url)) if @name.empty?
72
- @name.gsub!(/\.git$/, '') if @name =~ /\.git$/
73
- end
74
-
75
- end
76
- end
@@ -1,18 +0,0 @@
1
- class Zencoder
2
- class Response < Zencoder
3
-
4
- def process_for_cli
5
- if success?
6
- self
7
- else
8
- if errors.any?
9
- puts "Errors:\n#{errors.map{|error| "* "+error }.join("\n")}"
10
- else
11
- puts "ERROR\n-----\n\n#{body}\n\nHTTP Response Code\n------------------\n#{code}"
12
- end
13
- exit(1)
14
- end
15
- end
16
-
17
- end
18
- end
data/lib/zencoder/cli.rb DELETED
@@ -1,71 +0,0 @@
1
- require 'rubygems'
2
- begin
3
- gem 'trollop', '~> 1.16.2'
4
- gem 'terminal-table', '~> 1.4.2'
5
- require 'trollop'
6
- require 'terminal-table/import'
7
- rescue LoadError
8
- puts "You must install the trollop gem (~> 1.16.2) and the terminal-table gem (~> 1.4.2) to use the Zencoder CLI."
9
- exit 1
10
- end
11
-
12
- require 'zencoder'
13
- require 'zencoder/cli/helpers'
14
- require 'zencoder/cli/auth'
15
- require 'zencoder/cli/plugin'
16
- require 'zencoder/cli/command'
17
- require 'zencoder/cli/response'
18
- ZencoderCLI::Plugin.load!
19
-
20
- global_options = Trollop::options do
21
- version "Zencoder #{Zencoder::GEM_VERSION}"
22
- banner <<-EOS
23
- #{"-" * (14 + Zencoder::GEM_VERSION.length)}
24
- Zencoder CLI v#{Zencoder::GEM_VERSION}
25
- #{"-" * (14 + Zencoder::GEM_VERSION.length)}
26
-
27
- == Usage
28
-
29
- zencoder [global-options] command [command-options]
30
-
31
- == Available Commands
32
-
33
- #{
34
- ZencoderCLI::Command.commands.sort.map{|group, commands|
35
- commands.map{|command, description|
36
- command.ljust(22)+" # "+(description.is_a?(String) ? description : description[:description])
37
- }.join("\n")
38
- }.join("\n\n")
39
- }
40
-
41
- == Global Options
42
- EOS
43
- opt :environment, "Sets the environment to use (optional: defaults to production)", :type => String
44
- stop_on ZencoderCLI::Command.commands.map{|k, v| v.keys }.flatten
45
- end
46
-
47
- if ARGV.empty?
48
- puts "You must specify a command. Use --help for more information."
49
- exit(1)
50
- end
51
-
52
- command = ARGV.shift.strip
53
- args = ARGV
54
-
55
-
56
- flat_commands = ZencoderCLI::Command.commands.values.inject({}){|memo,group| memo.merge!(group) }
57
- command_options = Trollop::options do
58
- banner <<-EOS
59
- == Usage
60
-
61
- zencoder [global-options] #{command} [options]
62
-
63
- == Command Options
64
- EOS
65
- if flat_commands[command] && flat_commands[command][:options]
66
- flat_commands[command][:options].call(self)
67
- end
68
- end
69
-
70
-
71
- ZencoderCLI::Command.run(command, args, global_options, command_options)