mpokrywka-panda 0.0.2.1

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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-03-04
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
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.
data/Manifest.txt ADDED
@@ -0,0 +1,25 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/panda.rb
9
+ lib/panda/version.rb
10
+ lib/panda/video.rb
11
+ log/debug.log
12
+ script/destroy
13
+ script/generate
14
+ script/txt2html
15
+ setup.rb
16
+ tasks/deployment.rake
17
+ tasks/environment.rake
18
+ tasks/website.rake
19
+ test/test_helper.rb
20
+ test/test_panda.rb
21
+ website/index.html
22
+ website/index.txt
23
+ website/javascripts/rounded_corners_lite.inc.js
24
+ website/stylesheets/screen.css
25
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,2 @@
1
+ gem sources -a http://gems.github.com (you only have to do this once)
2
+ sudo gem install dctanner-panda_gem
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'panda/version'
2
+
3
+ AUTHOR = 'Damien Tanner' # can also be an array of Authors
4
+ EMAIL = "damien@new-bamboo.co.uk"
5
+ DESCRIPTION = "Ruby library for Panda (pandastream.com), a video uploading, encoding and streaming service."
6
+ GEM_NAME = 'panda' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'panda' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Panda::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'panda documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'panda'
@@ -0,0 +1,9 @@
1
+ module Panda #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,140 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'yaml'
4
+
5
+ module Panda
6
+ class << self
7
+ attr_accessor :account_key, :api_domain, :api_port, :default_encoding_profile, :verbose
8
+
9
+ def api_port
10
+ @api_port ||= 80
11
+ @api_port
12
+ end
13
+ end
14
+
15
+ class Video
16
+ attr_accessor :vals
17
+
18
+ # Deprecated. Use encoding_for_profile instead and check for status == 'success' manually.
19
+ def find_encoding(profile_title)
20
+ self.encodings.find { |e|
21
+ e.profile_title == profile_title and e.status == 'success'
22
+ }
23
+ end
24
+
25
+ def encoding_for_profile(profile_title)
26
+ self.encodings.find { |e|
27
+ e.profile_title == profile_title
28
+ }
29
+ end
30
+
31
+ def self.new_with_attrs(vals)
32
+ video = new
33
+ video.vals = {}
34
+ vals.each do |k,v|
35
+ video.vals[k] = v
36
+ class_eval "def video.#{k}; @vals[:#{k}]; end"
37
+ end
38
+
39
+ # If this is a parent video, turn the encodings into Panda::Video objects
40
+ if vals[:status] == "original"
41
+ vals[:encodings].map! do |e|
42
+ self.new_with_attrs(e[:video])
43
+ end
44
+ end
45
+
46
+ return video
47
+ end
48
+
49
+ def self.find(token)
50
+ response = request(:get, "/videos/#{token}")
51
+ p = self.new_with_attrs(response[:video])
52
+ return p
53
+ end
54
+
55
+ def self.create
56
+ response = request(:post, "/videos")
57
+ p = self.new_with_attrs(response[:video])
58
+ return p
59
+ end
60
+
61
+ def self.delete(token)
62
+ response = request(:post, "/videos/#{token}",{'_method' => 'delete'})
63
+ return response[:videos].map {|v| self.new_with_attrs(v[:video]) }
64
+ end
65
+
66
+ def self.videos
67
+ response = request(:get, "/videos")
68
+ return response[:videos].map {|v| self.new_with_attrs(v[:video]) }
69
+ end
70
+
71
+ # Makes request to remote service.
72
+ def self.request(method, path, params={})
73
+ raise Panda::AccountKeyNotSet if Panda.account_key.nil?
74
+ params[:account_key] = Panda.account_key
75
+ path += ".yaml"
76
+ http = Net::HTTP.new(Panda.api_domain, Panda.api_port)
77
+
78
+ case method
79
+ when :get
80
+ response = http.request_get("#{path}?account_key=#{Panda.account_key}")
81
+ when :post
82
+ req = Net::HTTP::Post.new(path)
83
+ req.form_data = params
84
+ response = http.request(req)
85
+ end
86
+
87
+ if Panda.verbose
88
+ puts "--> #{response.code} #{response.message} (#{response.body.length})"
89
+ puts response.body
90
+ end
91
+ handle_response(response)
92
+ end
93
+
94
+ # Handles response and error codes from remote service.
95
+
96
+ def self.handle_response(response)
97
+ case response.code.to_i
98
+ when 200...400
99
+ YAML.load(response.body)
100
+ when 401
101
+ raise(Panda::UnauthorizedAccess.new(response))
102
+ when 404
103
+ raise(Panda::VideoNotFound.new(response))
104
+ when 500...600
105
+ raise(Panda::ServerError.new(response))
106
+ else
107
+ raise(Panda::PandaError.new(response, "Unknown response code: #{response.code}"))
108
+ end
109
+ end
110
+ end
111
+
112
+ class PandaError < StandardError; end
113
+
114
+ class ConnectionError < PandaError # :nodoc:
115
+ attr_reader :response
116
+
117
+ def initialize(response, message = nil)
118
+ @response = response
119
+ @message = message
120
+ end
121
+
122
+ def to_s
123
+ "Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
124
+ end
125
+ end
126
+
127
+ class AccountKeyNotSet < PandaError; end
128
+
129
+ # 4xx Client Error
130
+ class ClientError < ConnectionError; end # :nodoc:
131
+
132
+ # 401 Unauthorized
133
+ class UnauthorizedAccess < ClientError; end # :nodoc
134
+
135
+ # 404 Not Found
136
+ class VideoNotFound < ClientError; end # :nodoc:
137
+
138
+ # 5xx Server Error
139
+ class ServerError < ConnectionError; end # :nodoc:
140
+ end
data/lib/panda.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__) + '/panda'
2
+
3
+ require 'video'
data/log/debug.log ADDED
File without changes