panda 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +94 -0
- data/Rakefile +3 -11
- data/VERSION +1 -1
- data/lib/panda.rb +3 -4
- data/lib/panda/api_authentication.rb +1 -1
- data/lib/panda/panda.rb +59 -0
- data/panda.gemspec +14 -8
- data/spec/panda_spec.rb +19 -3
- data/spec/spec_helper.rb +3 -0
- metadata +26 -6
- data/README.rdoc +0 -13
- data/lib/panda/video.rb +0 -86
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Panda
|
2
|
+
|
3
|
+
Panda gem provides an interface to access the [Panda](http://api.pandastream.com) API from Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
sudo gem install panda -s http://gemcutter.org
|
8
|
+
|
9
|
+
## How to use it
|
10
|
+
|
11
|
+
|
12
|
+
require 'panda'
|
13
|
+
|
14
|
+
|
15
|
+
### Connecting to Panda
|
16
|
+
|
17
|
+
Panda.connect!({
|
18
|
+
:cloud_id => 'cloud_id',
|
19
|
+
:access_key => 'access_key',
|
20
|
+
:secret_key => 'secret_key',
|
21
|
+
:api_host => 'api.pandastream.com'
|
22
|
+
})
|
23
|
+
|
24
|
+
### Posting a video
|
25
|
+
|
26
|
+
Panda.post('/videos.json', {:source_url => 'http://www.example.com/original_video.mp4'})
|
27
|
+
=>{"duration"=>nil,
|
28
|
+
"created_at"=>"2010/01/15 14:48:42 +0000",
|
29
|
+
"original_filename"=>"panda.mp4",
|
30
|
+
"updated_at"=>"2010/01/15 14:48:42 +0000",
|
31
|
+
"source_url"=>"http://www.example.com/original_video.mp4",
|
32
|
+
"id"=>"12fce296-01e5-11df-ae37-12313902cc92",
|
33
|
+
"extname"=>".mp4",
|
34
|
+
"thumbnail_position"=>nil,
|
35
|
+
"audio_codec"=>nil,
|
36
|
+
"height"=>nil,
|
37
|
+
"upload_redirect_url"=>nil,
|
38
|
+
"fps"=>nil,
|
39
|
+
"video_codec"=>nil,
|
40
|
+
"status"=>"processing",
|
41
|
+
"width"=>nil}
|
42
|
+
|
43
|
+
### Getting all videos
|
44
|
+
|
45
|
+
Panda.get('/videos.json')
|
46
|
+
=> [{"duration"=>14010,
|
47
|
+
"created_at"=>"2010/01/13 16:45:29 +0000",
|
48
|
+
"original_filename"=>"panda.mp4",
|
49
|
+
"updated_at"=>"2010/01/13 16:45:35 +0000",
|
50
|
+
"source_url"=>"http://www.example.com/original_video.mp4",
|
51
|
+
"id"=>"0ee6b656-0063-11df-a433-1231390041c1",
|
52
|
+
"extname"=>".mp4",
|
53
|
+
"thumbnail_position"=>nil,
|
54
|
+
"audio_codec"=>"aac",
|
55
|
+
"height"=>240,
|
56
|
+
"upload_redirect_url"=>nil,
|
57
|
+
"fps"=>29,
|
58
|
+
"video_codec"=>"h264",
|
59
|
+
"status"=>"success",
|
60
|
+
"width"=>300}]
|
61
|
+
|
62
|
+
### Getting video encodings
|
63
|
+
|
64
|
+
Panda.get('/videos/0ee6b656-0063-11df-a433-1231390041c1/encodings.json')
|
65
|
+
=> [{"encoder_id"=>nil,
|
66
|
+
"created_at"=>"2010/01/13 16:45:30 +0000",
|
67
|
+
"video_id"=>"0ee6b656-0063-11df-a433-1231390041c1",
|
68
|
+
"video_url"=>
|
69
|
+
"http://s3.amazonaws.com/panda-videos/0f815986-0063-11df-a433-1231390041c1.flv",
|
70
|
+
"started_encoding_at"=>"2010/01/13 16:47:35 +0000",
|
71
|
+
"updated_at"=>"2010/01/13 16:47:40 +0000",
|
72
|
+
"lock_version"=>7,
|
73
|
+
"extname"=>".flv",
|
74
|
+
"encoding_progress"=>87,
|
75
|
+
"encoding_time"=>3,
|
76
|
+
"id"=>"0f815986-0063-11df-a433-1231390041c1",
|
77
|
+
"height"=>240,
|
78
|
+
"status"=>"success",
|
79
|
+
"profile_id"=>"00182830-0063-11df-8c8a-1231390041c1",
|
80
|
+
"width"=>300}]
|
81
|
+
|
82
|
+
### Deleting a video encoding
|
83
|
+
|
84
|
+
Panda.delete('/encodings/0f815986-0063-11df-a433-1231390041c1.json')
|
85
|
+
|
86
|
+
### Deleting a video
|
87
|
+
|
88
|
+
Panda.delete('/videos/0ee6b656-0063-11df-a433-1231390041c1.json')
|
89
|
+
|
90
|
+
|
91
|
+
Copyright
|
92
|
+
---------
|
93
|
+
|
94
|
+
Copyright (c) 2009-2010 New Bamboo. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -11,9 +11,11 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/newbamboo/panda_gem"
|
12
12
|
gem.authors = ["New Bamboo"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "fakeweb"
|
15
|
+
gem.add_development_dependency "fakeweb-matcher"
|
14
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
17
|
gem.add_dependency "ruby-hmac", ">= 0.3.2"
|
16
|
-
gem.add_dependency "rest-client", ">= 1.
|
18
|
+
gem.add_dependency "rest-client", ">= 1.2"
|
17
19
|
end
|
18
20
|
Jeweler::GemcutterTasks.new
|
19
21
|
rescue LoadError
|
@@ -35,13 +37,3 @@ end
|
|
35
37
|
task :spec => :check_dependencies
|
36
38
|
|
37
39
|
task :default => :spec
|
38
|
-
|
39
|
-
require 'rake/rdoctask'
|
40
|
-
Rake::RDocTask.new do |rdoc|
|
41
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
-
|
43
|
-
rdoc.rdoc_dir = 'rdoc'
|
44
|
-
rdoc.title = "panda #{version}"
|
45
|
-
rdoc.rdoc_files.include('README*')
|
46
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/panda.rb
CHANGED
data/lib/panda/panda.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Panda
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def connect!(auth_params={})
|
5
|
+
params = {:api_host => 'api.pandastream.com', :api_port => 80 }.merge(auth_params)
|
6
|
+
|
7
|
+
@api_version = 2
|
8
|
+
@cloud_id = params["cloud_id"] || params[:cloud_id]
|
9
|
+
@access_key = params["access_key"] || params[:access_key]
|
10
|
+
@secret_key = params["secret_key"] || params[:secret_key]
|
11
|
+
@api_host = params["api_host"] || params[:api_host]
|
12
|
+
@api_port = params["api_port"] || params[:api_port]
|
13
|
+
|
14
|
+
@prefix = params["prefix_url"] || "v#{@api_version}"
|
15
|
+
|
16
|
+
@connection = RestClient::Resource.new(api_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(request_uri, params={})
|
20
|
+
append_authentication_params!("GET", request_uri, params)
|
21
|
+
@connection[ApiAuthentication.add_params_to_request_uri(request_uri, params)].get
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(request_uri, params)
|
25
|
+
append_authentication_params!("POST", request_uri, params)
|
26
|
+
@connection[request_uri].post(params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def put(request_uri, params)
|
30
|
+
append_authentication_params!("PUT", request_uri, params)
|
31
|
+
@connection[request_uri].put(params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(request_uri, params={})
|
35
|
+
append_authentication_params!("DELETE", request_uri, params)
|
36
|
+
@connection[ApiAuthentication.add_params_to_request_uri(request_uri, params)].delete
|
37
|
+
end
|
38
|
+
|
39
|
+
def authentication_params(verb, request_uri, params)
|
40
|
+
auth_params = {}
|
41
|
+
auth_params['cloud_id'] = @cloud_id
|
42
|
+
auth_params['access_key'] = @access_key
|
43
|
+
auth_params['timestamp'] = Time.now.iso8601
|
44
|
+
auth_params['signature'] = ApiAuthentication.authenticate(verb, request_uri, @api_host, @secret_key, params.merge(auth_params))
|
45
|
+
return auth_params
|
46
|
+
end
|
47
|
+
|
48
|
+
def api_url
|
49
|
+
"http://#{@api_host}:#{@api_port}/#{@prefix}"
|
50
|
+
end
|
51
|
+
private
|
52
|
+
|
53
|
+
def append_authentication_params!(verb, request_uri, params)
|
54
|
+
auth_params = authentication_params(verb, request_uri, params)
|
55
|
+
params.merge!(auth_params)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/panda.gemspec
CHANGED
@@ -5,26 +5,26 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{panda}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["New Bamboo"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-15}
|
13
13
|
s.description = %q{Panda Client}
|
14
14
|
s.email = %q{bambinos@new-bamboo.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".gitignore",
|
21
21
|
"LICENSE",
|
22
|
-
"README.
|
22
|
+
"README.md",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
25
|
"lib/panda.rb",
|
26
26
|
"lib/panda/api_authentication.rb",
|
27
|
-
"lib/panda/
|
27
|
+
"lib/panda/panda.rb",
|
28
28
|
"log/debug.log",
|
29
29
|
"panda.gemspec",
|
30
30
|
"spec/panda_spec.rb",
|
@@ -47,17 +47,23 @@ Gem::Specification.new do |s|
|
|
47
47
|
|
48
48
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
49
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
50
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<fakeweb-matcher>, [">= 0"])
|
50
52
|
s.add_runtime_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
51
|
-
s.add_runtime_dependency(%q<rest-client>, [">= 1.
|
53
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.2"])
|
52
54
|
else
|
53
55
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
57
|
+
s.add_dependency(%q<fakeweb-matcher>, [">= 0"])
|
54
58
|
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
55
|
-
s.add_dependency(%q<rest-client>, [">= 1.
|
59
|
+
s.add_dependency(%q<rest-client>, [">= 1.2"])
|
56
60
|
end
|
57
61
|
else
|
58
62
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
63
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
64
|
+
s.add_dependency(%q<fakeweb-matcher>, [">= 0"])
|
59
65
|
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
60
|
-
s.add_dependency(%q<rest-client>, [">= 1.
|
66
|
+
s.add_dependency(%q<rest-client>, [">= 1.2"])
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
data/spec/panda_spec.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
3
|
+
describe Panda do
|
4
|
+
before(:each) do
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
Panda.connect!({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
|
7
|
+
Time.stub!(:now).and_return(mock("time", :iso8601 => "2009-11-04T17:54:11+00:00"))
|
6
8
|
end
|
9
|
+
|
10
|
+
|
11
|
+
it "should make get request with signed request to panda server" do
|
12
|
+
FakeWeb.register_uri(:get, "http://myapihost:85/v2/videos?timestamp=2009-11-04T17%3A54%3A11%2B00%3A00&signature=CxSYPM65SeeWH4CE%2FLcq7Ny2NtwxlpS8QOXG2BKe4p8%3D&access_key=my_access_key&cloud_id=my_cloud_id", :body => "abc")
|
13
|
+
Panda.get("/videos").should == "abc"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should make delete request with signed request to panda server" do
|
17
|
+
FakeWeb.register_uri(:delete, "http://myapihost:85/v2/videos/1?timestamp=2009-11-04T17%3A54%3A11%2B00%3A00&signature=t0IYclDXgjZFRYaMf0Gbg%2B5vOqp7q8QQRN8tlQ3bk8Q%3D&access_key=my_access_key&cloud_id=my_cloud_id", :query => {})
|
18
|
+
Panda.delete("/videos/1").should
|
19
|
+
FakeWeb.should have_requested(:delete, "http://myapihost:85/v2/videos/1?timestamp=2009-11-04T17%3A54%3A11%2B00%3A00&signature=t0IYclDXgjZFRYaMf0Gbg%2B5vOqp7q8QQRN8tlQ3bk8Q%3D&access_key=my_access_key&cloud_id=my_cloud_id")
|
20
|
+
end
|
21
|
+
|
22
|
+
|
7
23
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- New Bamboo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-15 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,26 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.2.9
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fakeweb
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: fakeweb-matcher
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
25
45
|
- !ruby/object:Gem::Dependency
|
26
46
|
name: ruby-hmac
|
27
47
|
type: :runtime
|
@@ -40,7 +60,7 @@ dependencies:
|
|
40
60
|
requirements:
|
41
61
|
- - ">="
|
42
62
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.
|
63
|
+
version: "1.2"
|
44
64
|
version:
|
45
65
|
description: Panda Client
|
46
66
|
email: bambinos@new-bamboo.co.uk
|
@@ -50,16 +70,16 @@ extensions: []
|
|
50
70
|
|
51
71
|
extra_rdoc_files:
|
52
72
|
- LICENSE
|
53
|
-
- README.
|
73
|
+
- README.md
|
54
74
|
files:
|
55
75
|
- .gitignore
|
56
76
|
- LICENSE
|
57
|
-
- README.
|
77
|
+
- README.md
|
58
78
|
- Rakefile
|
59
79
|
- VERSION
|
60
80
|
- lib/panda.rb
|
61
81
|
- lib/panda/api_authentication.rb
|
62
|
-
- lib/panda/
|
82
|
+
- lib/panda/panda.rb
|
63
83
|
- log/debug.log
|
64
84
|
- panda.gemspec
|
65
85
|
- spec/panda_spec.rb
|
data/README.rdoc
DELETED
data/lib/panda/video.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rest_client'
|
3
|
-
require 'api_authentication'
|
4
|
-
|
5
|
-
module Panda
|
6
|
-
class << self
|
7
|
-
attr_writer :rest_client_options
|
8
|
-
attr_reader :connection
|
9
|
-
|
10
|
-
def connect!(access_key, secret_key, api_host='api.pandastream.com', api_port=80)
|
11
|
-
@api_version = 2
|
12
|
-
@access_key = access_key
|
13
|
-
@secret_key = secret_key
|
14
|
-
@api_host = api_host
|
15
|
-
@api_port = api_port
|
16
|
-
@rest_client_options = {}
|
17
|
-
|
18
|
-
# raise Exception.new("You must supply a :secret_key") unless @secret_key
|
19
|
-
|
20
|
-
@connection = RestClient::Resource.new(api_url)
|
21
|
-
end
|
22
|
-
|
23
|
-
def api_url
|
24
|
-
"http://#{@api_host}:#{@api_port}/v#{@api_version}"
|
25
|
-
end
|
26
|
-
|
27
|
-
# NOTE: get params, MUST be given as the params hash, not as part of the url string
|
28
|
-
def get(request_uri, params={})
|
29
|
-
params = authenticate("GET", request_uri, params)
|
30
|
-
puts ApiAuthentication.add_params_to_request_uri(request_uri, params)
|
31
|
-
RestClient::Resource.new(concat_urls(api_url, ApiAuthentication.add_params_to_request_uri(request_uri, params))).get
|
32
|
-
end
|
33
|
-
|
34
|
-
def post(request_uri, params)
|
35
|
-
params = authenticate("POST", request_uri, params)
|
36
|
-
RestClient::Resource.new(concat_urls(api_url, request_uri)).post(params)
|
37
|
-
end
|
38
|
-
|
39
|
-
def put(request_uri, params)
|
40
|
-
params = authenticate("PUT", request_uri, params)
|
41
|
-
RestClient::Resource.new(concat_urls(api_url, request_uri)).put(params)
|
42
|
-
end
|
43
|
-
|
44
|
-
def delete(request_uri, params={})
|
45
|
-
params = authenticate("DELETE", request_uri, params)
|
46
|
-
puts ApiAuthentication.add_params_to_request_uri(request_uri, params)
|
47
|
-
RestClient::Resource.new(concat_urls(api_url, ApiAuthentication.add_params_to_request_uri(request_uri, params))).delete
|
48
|
-
end
|
49
|
-
|
50
|
-
# From rest-client/lib/restclient/resource.rb
|
51
|
-
|
52
|
-
def concat_urls(url, suburl) # :nodoc:
|
53
|
-
url = url.to_s
|
54
|
-
suburl = suburl.to_s
|
55
|
-
if url.slice(-1, 1) == '/' or suburl.slice(0, 1) == '/'
|
56
|
-
url + suburl
|
57
|
-
else
|
58
|
-
"#{url}/#{suburl}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Authentication
|
63
|
-
|
64
|
-
def authenticate(verb, request_uri, params)
|
65
|
-
params['access_key'] = @access_key
|
66
|
-
params['timestamp'] = Time.now.iso8601
|
67
|
-
params['signature'] = ApiAuthentication.authenticate(verb, request_uri, @api_host, @secret_key, params)
|
68
|
-
return params
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
# class AccountKeyNotSet < PandaError; end
|
74
|
-
#
|
75
|
-
# # 4xx Client Error
|
76
|
-
# class ClientError < ConnectionError; end # :nodoc:
|
77
|
-
#
|
78
|
-
# # 401 Unauthorized
|
79
|
-
# class UnauthorizedAccess < ClientError; end # :nodoc
|
80
|
-
#
|
81
|
-
# # 404 Not Found
|
82
|
-
# class VideoNotFound < ClientError; end # :nodoc:
|
83
|
-
#
|
84
|
-
# # 5xx Server Error
|
85
|
-
# class ServerError < ConnectionError; end # :nodoc:
|
86
|
-
end
|