media_monster_client 2.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in media_monster_client.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,4 @@
1
+ require 'media_monster/model'
2
+ require 'media_monster/job'
3
+ require 'media_monster/task'
4
+ require 'media_monster/sequence'
@@ -0,0 +1,42 @@
1
+ module MediaMonster
2
+
3
+ class Job < Model
4
+
5
+ attr_accessor :job_type # which type of job is this? audio to start, video, document, etc.
6
+ attr_accessor :original # file location
7
+ attr_accessor :call_back # url for webhook
8
+ attr_accessor :tasks # array of tasks
9
+
10
+ def initialize(*args)
11
+ super
12
+ @tasks = []
13
+ end
14
+
15
+ def tasks=(as)
16
+ # puts "adding each task..."
17
+ if as[0].is_a?(String) || as[0].is_a?(Symbol) || as[0].is_a?(Hash)
18
+ self.add_task(*as)
19
+ else
20
+ as.each{|a| self.add_task(*a)}
21
+ end
22
+ end
23
+
24
+ def add_sequence(*args)
25
+ new_sequence = Sequence.new
26
+ @tasks << new_sequence
27
+ yield new_sequence
28
+ end
29
+
30
+ def add_task(*args)
31
+ @tasks ||= []
32
+ new_task = if (args.length == 1 && args[0].is_a?(MediaMonster::Task))
33
+ args[0]
34
+ else
35
+ MediaMonster::Task.new(*args)
36
+ end
37
+ @tasks << new_task
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,28 @@
1
+ module MediaMonster
2
+
3
+ class Model
4
+
5
+ def initialize(*args)
6
+ return unless args
7
+ if args[0].is_a?(Hash)
8
+ args[0].each{|k,v| self.send("#{k.to_s}=".to_sym, v)}
9
+ end
10
+ end
11
+
12
+ if defined?(as_json)
13
+ def as_json_with_class_name(options={})
14
+ {self.class.name.demodulize.underscore.to_sym => as_json_without_class_name(options)}
15
+ end
16
+
17
+ alias_method_chain :as_json, :class_name
18
+ else
19
+
20
+ def to_json(options = {})
21
+ ActiveSupport::JSON.encode({self.class.name.demodulize.underscore.to_sym => instance_values}, options)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ module MediaMonster
2
+
3
+ class Sequence < Model
4
+
5
+ # attr_accessor :options #hash
6
+ # attr_accessor :result #string
7
+ attr_accessor :call_back #string
8
+ attr_accessor :label #string
9
+ attr_accessor :tasks #array
10
+
11
+ def initialize(*args)
12
+ super
13
+ self.tasks = []
14
+ end
15
+
16
+ def add_task(*args)
17
+ new_task = if (args.length == 1 && args[0].is_a?(MediaMonster::Task))
18
+ args[0]
19
+ else
20
+ MediaMonster::Task.new(*args)
21
+ end
22
+
23
+ self.tasks << new_task
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,24 @@
1
+ module MediaMonster
2
+
3
+ class Task < Model
4
+
5
+ attr_accessor :task_type #string
6
+ attr_accessor :options #hash
7
+ attr_accessor :result #string
8
+ attr_accessor :call_back #string
9
+ attr_accessor :label #string
10
+
11
+ def initialize(*args)
12
+ super
13
+ if args[0].is_a?(String) || args[0].is_a?(Symbol)
14
+ self.task_type = args[0].to_s
15
+ self.options = args[1]
16
+ self.result = args[2].to_s
17
+ self.call_back = args[3].to_s
18
+ self.label = args[4].to_s
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'active_support'
5
+ require 'active_support/core_ext'
6
+ require 'active_support/json/encoding'
7
+ require 'active_support/all'
8
+ rescue LoadError=>err
9
+ # puts "LoadError:#{err.message}"
10
+ end
11
+
12
+
13
+ require 'oauth'
14
+ require 'json'
15
+ require 'cgi'
16
+
17
+ require 'media_monster'
18
+
19
+
20
+ module MediaMonsterClient
21
+ class << self
22
+
23
+ attr_accessor :key, :secret, :scheme, :host, :port, :version
24
+
25
+ def create_job(job=nil)
26
+ job ||= MediaMonster::Job.new
27
+ yield job
28
+ post(create_url("jobs"), job.to_json, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
29
+ end
30
+
31
+ def update_task(task_id, task_status)
32
+ json = {'task'=>{'status'=>task_status}}.to_json
33
+ put(create_url("tasks/#{task_id.to_i}"), json, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
34
+ end
35
+
36
+ protected
37
+
38
+ def create_url(path)
39
+ "/api/#{version}/#{path}"
40
+ end
41
+
42
+ [:delete, :get, :head, :post, :put, :request].each do |method|
43
+ define_method method do |*args|
44
+ access_token.send(method, *args)
45
+ end
46
+ end
47
+
48
+ def consumer
49
+ @consumer ||= OAuth::Consumer.new(key,
50
+ secret,
51
+ :site => "#{scheme || 'http'}://#{host}:#{port}",
52
+ :http_method => :get)
53
+ end
54
+
55
+ def access_token
56
+ @access_token ||= OAuth::AccessToken.new(consumer)
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,3 @@
1
+ module MediaMonsterClient
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "media_monster_client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "media_monster_client"
7
+ s.version = MediaMonsterClient::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Andrew Kuklewicz (kookster)"]
10
+ s.email = ["andrew@prx.org"]
11
+ s.homepage = ""
12
+ s.summary = %q{client gem for media monster app}
13
+ s.description = %q{client gem for media monster app}
14
+
15
+ s.rubyforge_project = "media_monster_client"
16
+
17
+ s.add_dependency("activesupport", "2.3.9")
18
+ # s.add_dependency("active_model")
19
+ s.add_dependency("oauth")
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'media_monster_client'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,70 @@
1
+ # require 'rubygems'
2
+ # gem 'activesupport', '=2.2.3'
3
+ # gem 'activesupport', '=2.3.9'
4
+ # gem 'activesupport', '=3.0.9'
5
+
6
+ require 'helper'
7
+
8
+ class TestMediaMonsterClient < Test::Unit::TestCase
9
+
10
+ def setup
11
+ MediaMonsterClient.key = '9NmQzsWBWs8TyfJswqMmkmjwAH3ItNBIC72KLjQK'
12
+ MediaMonsterClient.secret = '592BSoaCb4FfwqsZ6Ql8WShVZ6HVnecR4Dk9lRfQ'
13
+ MediaMonsterClient.host = "development.prx.org"
14
+ MediaMonsterClient.port = 3000
15
+ MediaMonsterClient.version = 'v1'
16
+ end
17
+
18
+ def test_create_job
19
+ response = MediaMonsterClient.create_job do |job|
20
+ job.job_type = 'audio'
21
+ job.original = 's3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2'
22
+ job.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
23
+
24
+ job.add_task( 'transcode',
25
+ {:format=>'mp3', :sample_rate=>'44100', :bit_rate=>'128'},
26
+ 's3://development.tcf.prx.org/public/audio_files/21/test.mp3',
27
+ nil,
28
+ 'download')
29
+
30
+ end
31
+
32
+ puts response.inspect
33
+
34
+ end
35
+
36
+ def test_create_job_with_sequence
37
+ response = MediaMonsterClient.create_job do |job|
38
+ job.job_type = 'audio'
39
+ job.original = 's3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2'
40
+ job.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
41
+
42
+ job.add_sequence do |s|
43
+ s.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
44
+ s.label = 'preview'
45
+
46
+ s.add_task( :task_type=>'cut',
47
+ :options=>{:length=>4, :fade=>1},
48
+ :label=>'cut it')
49
+
50
+ s.add_task( :task_type=>'transcode',
51
+ :options=>{:format=>'mp3', :sample_rate=>'44100', :bit_rate=>'64'},
52
+ :label=>'mp3',
53
+ :result=>'s3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test_preview.mp3')
54
+ end
55
+
56
+ end
57
+ puts response.inspect
58
+ end
59
+
60
+ # MediaMonsterClient.create_job do |job|
61
+ # job.job_type = 'audio'
62
+ # job.original = 's3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2'
63
+ # job.add_task( 'copy',
64
+ # {},
65
+ # 's3://development.tcf.prx.org/public/audio_files/21/test.mp2',
66
+ # 'http://localhost:3001/audio_files/21/processed',
67
+ # 'original')
68
+ # end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: media_monster_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Kuklewicz (kookster)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-11 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 9
34
+ version: 2.3.9
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: oauth
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: client gem for media monster app
52
+ email:
53
+ - andrew@prx.org
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - Rakefile
64
+ - lib/media_monster.rb
65
+ - lib/media_monster/job.rb
66
+ - lib/media_monster/model.rb
67
+ - lib/media_monster/sequence.rb
68
+ - lib/media_monster/task.rb
69
+ - lib/media_monster_client.rb
70
+ - lib/media_monster_client/version.rb
71
+ - media_monster_client.gemspec
72
+ - test/helper.rb
73
+ - test/test_media_monster_client.rb
74
+ has_rdoc: true
75
+ homepage: ""
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project: media_monster_client
104
+ rubygems_version: 1.4.2
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: client gem for media monster app
108
+ test_files:
109
+ - test/helper.rb
110
+ - test/test_media_monster_client.rb