panda 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -7
- data/VERSION +1 -1
- data/lib/panda/modules/builders.rb +14 -11
- data/lib/panda/modules/finders.rb +1 -1
- data/lib/panda/panda.rb +28 -23
- data/lib/panda/proxies/scope.rb +3 -3
- data/lib/panda/resources/cloud.rb +13 -0
- data/lib/panda/resources/encoding.rb +16 -13
- data/panda.gemspec +4 -4
- data/spec/cloud_spec.rb +32 -2
- data/spec/encoding_spec.rb +6 -6
- metadata +45 -17
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Panda gem provides an interface to access the [Panda](http://pandastream.com) API from Ruby.
|
4
4
|
|
5
|
+
* [Visit panda\_gem on Github](http://github.com/newbamboo/panda_gem)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
gem install panda
|
@@ -19,7 +21,7 @@ Panda gem provides an interface to access the [Panda](http://pandastream.com) AP
|
|
19
21
|
config.cloud_id = "panda_cloud_id"
|
20
22
|
end
|
21
23
|
|
22
|
-
or Panda.configure
|
24
|
+
or Panda.configure({:access_key => ....})
|
23
25
|
|
24
26
|
### Creating an instance of the client for EU
|
25
27
|
|
@@ -27,14 +29,22 @@ Panda gem provides an interface to access the [Panda](http://pandastream.com) AP
|
|
27
29
|
config.access_key = "panda_access_key"
|
28
30
|
config.secret_key = "panda_secret_key"
|
29
31
|
config.cloud_id = "panda_cloud_id"
|
30
|
-
config.
|
32
|
+
config.api_host = "api.eu.pandastream.com"
|
31
33
|
end
|
32
34
|
|
33
35
|
### Creating an instance using Heroku
|
34
36
|
|
35
|
-
Panda.configure
|
36
|
-
|
37
|
-
|
37
|
+
Panda.configure(ENV['PANDASTREAM_URL'])
|
38
|
+
|
39
|
+
### Inside a Rails app with a main account or using Heroku
|
40
|
+
|
41
|
+
Config is stored in `config/panda.yml` or you must set an the PANDASTREAM_URL environment variable in your `/.bashrc` file (see the [Heroku config variable docs](http://docs.heroku.com/config-vars)).
|
42
|
+
|
43
|
+
Use the following in your `config/initializers/panda.rb`:
|
44
|
+
|
45
|
+
Panda.configure((ENV['PANDASTREAM_URL'] || YAML::load_file(File.join(File.dirname(__FILE__),"..", "panda.yml"))[RAILS_ENV]))
|
46
|
+
|
47
|
+
See the [Rails How-to](http://www.pandastream.com/docs/integrate_with_rails) for more details.
|
38
48
|
|
39
49
|
### Typical usage
|
40
50
|
|
@@ -482,7 +492,5 @@ Since Panda 0.6, PandaGem returns a Hash by default. If you want PandaGem to ret
|
|
482
492
|
bundler install
|
483
493
|
rake spec
|
484
494
|
|
485
|
-
Copyright
|
486
|
-
---------
|
487
495
|
|
488
496
|
Copyright (c) 2009-2010 New Bamboo. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
@@ -8,19 +8,22 @@ module Panda
|
|
8
8
|
|
9
9
|
module CreateBuilder
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
response = connection.post(full_object_url(many_path), attributes)
|
17
|
-
Panda::const_get("#{end_class_name}").new(response)
|
18
|
-
end
|
11
|
+
def create(attributes)
|
12
|
+
resource = build_resource(attributes)
|
13
|
+
resource.create
|
14
|
+
resource
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def create!(attributes)
|
18
|
+
resource = build_resource(attributes)
|
19
|
+
resource.create!
|
20
|
+
resource
|
21
|
+
end
|
23
22
|
|
23
|
+
private
|
24
|
+
def build_resource(attributes)
|
25
|
+
Panda::const_get("#{end_class_name}").new(attributes.merge(:cloud_id => cloud.id))
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
module DeleteBuilder
|
data/lib/panda/panda.rb
CHANGED
@@ -3,36 +3,41 @@ require 'forwardable'
|
|
3
3
|
require 'json' unless defined?(ActiveSupport::JSON)
|
4
4
|
|
5
5
|
module Panda
|
6
|
-
|
7
|
-
|
6
|
+
extend self
|
7
|
+
extend Forwardable
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
attr_reader :cloud, :clouds
|
10
|
+
attr_reader :connection
|
11
11
|
|
12
|
-
|
12
|
+
def_delegators :connection, :get, :post, :put, :delete, :api_url, :setup_bucket, :signed_params
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def configure(auth_params=nil)
|
15
|
+
@clouds = {}
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
@connection.raise_error=true
|
24
|
-
@connection.format = :hash
|
25
|
-
@cloud = Cloud::new(:id => @connection.cloud_id)
|
17
|
+
if auth_params
|
18
|
+
connect!(auth_params)
|
19
|
+
else
|
20
|
+
yield @connection = Connection.new
|
26
21
|
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
@connection.raise_error=true
|
24
|
+
@connection.format = :hash
|
25
|
+
@cloud = Cloud::new(:id => @connection.cloud_id)
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
def connect!(auth_params, options={})
|
29
|
+
@connection = Connection.new(auth_params, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def connection
|
33
|
+
raise "Not connected. Please connect! first." unless @connection
|
34
|
+
@connection
|
35
|
+
end
|
36
36
|
|
37
|
+
def version
|
38
|
+
open(File.join(File.dirname(__FILE__), '../../VERSION')) { |f|
|
39
|
+
f.read.strip
|
40
|
+
}
|
37
41
|
end
|
42
|
+
|
38
43
|
end
|
data/lib/panda/proxies/scope.rb
CHANGED
@@ -25,9 +25,9 @@ module Panda
|
|
25
25
|
object = find_object_by_path(url, map)
|
26
26
|
|
27
27
|
if object.is_a?(Array)
|
28
|
-
object.map{|o| klass.new(o.merge(
|
29
|
-
elsif object[
|
30
|
-
klass.new(object.merge(
|
28
|
+
object.map{|o| klass.new(o.merge('cloud_id' => cloud.id))}
|
29
|
+
elsif object['id']
|
30
|
+
klass.new(object.merge('cloud_id' => cloud.id))
|
31
31
|
else
|
32
32
|
Error.new(object).raise!
|
33
33
|
end
|
@@ -22,6 +22,19 @@ module Panda
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def eu?
|
26
|
+
region == "eu"
|
27
|
+
end
|
28
|
+
|
29
|
+
def us?
|
30
|
+
region == "us"
|
31
|
+
end
|
32
|
+
|
33
|
+
def region
|
34
|
+
return "eu" if connection.api_host == Panda::Connection::EU_API_HOST
|
35
|
+
return "us" if connection.api_host == Panda::Connection::US_API_HOST
|
36
|
+
end
|
37
|
+
|
25
38
|
def videos
|
26
39
|
VideoScope.new(self)
|
27
40
|
end
|
@@ -5,25 +5,28 @@ module Panda
|
|
5
5
|
belongs_to :video
|
6
6
|
has_one :profile
|
7
7
|
|
8
|
+
class << self
|
9
|
+
def first
|
10
|
+
EncodingScope.new(self).per_page(1).first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
def url
|
9
|
-
"
|
15
|
+
get_url("#{extname}")
|
10
16
|
end
|
11
17
|
|
18
|
+
def error_log
|
19
|
+
get_url(".log") if fail?
|
20
|
+
end
|
21
|
+
|
12
22
|
def screenshots
|
13
|
-
|
14
|
-
if status == 'success'
|
15
|
-
(1..7).map do |i|
|
16
|
-
"http://s3.amazonaws.com/#{cloud.s3_videos_bucket}/#{id}_#{i}.jpg"
|
17
|
-
end
|
18
|
-
else
|
19
|
-
[]
|
20
|
-
end
|
23
|
+
((1..7).map{|i| get_url("_#{i}.jpg")} if success?) || []
|
21
24
|
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_url(end_path)
|
29
|
+
"#{cloud.url}#{path}#{end_path}"
|
27
30
|
end
|
28
31
|
|
29
32
|
end
|
data/panda.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{panda}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.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{2010-
|
12
|
+
s.date = %q{2010-10-19}
|
13
13
|
s.description = %q{Panda Client}
|
14
14
|
s.email = %q{info@pandastream.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
|
|
59
59
|
s.homepage = %q{http://github.com/newbamboo/panda_gem}
|
60
60
|
s.rdoc_options = ["--charset=UTF-8"]
|
61
61
|
s.require_paths = ["lib"]
|
62
|
-
s.rubygems_version = %q{1.3.
|
62
|
+
s.rubygems_version = %q{1.3.7}
|
63
63
|
s.summary = %q{Panda Client}
|
64
64
|
s.test_files = [
|
65
65
|
"spec/cloud_spec.rb",
|
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
|
|
75
75
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
76
76
|
s.specification_version = 3
|
77
77
|
|
78
|
-
if Gem::Version.new(Gem::
|
78
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
79
79
|
s.add_runtime_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
80
80
|
s.add_runtime_dependency(%q<rest-client>, [">= 1.4"])
|
81
81
|
s.add_runtime_dependency(%q<json>, [">= 1.2"])
|
data/spec/cloud_spec.rb
CHANGED
@@ -1,6 +1,36 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe Panda::
|
3
|
+
describe Panda::Cloud do
|
4
|
+
|
5
|
+
describe "region" do
|
6
|
+
it "should tell the region" do
|
7
|
+
Panda.configure do |c|
|
8
|
+
c.access_key = "my_access_key"
|
9
|
+
c.secret_key = "my_secret_key"
|
10
|
+
c.api_host = "api.pandastream.com"
|
11
|
+
c.cloud_id = 'my_cloud_id'
|
12
|
+
c.api_port = 85
|
13
|
+
end
|
14
|
+
|
15
|
+
Panda.cloud.region.should == "us"
|
16
|
+
Panda.cloud.us?.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should tell the region" do
|
20
|
+
Panda.configure do |c|
|
21
|
+
c.access_key = "my_access_key"
|
22
|
+
c.secret_key = "my_secret_key"
|
23
|
+
c.api_host = "api.eu.pandastream.com"
|
24
|
+
c.cloud_id = 'my_cloud_id'
|
25
|
+
c.api_port = 85
|
26
|
+
end
|
27
|
+
|
28
|
+
Panda.cloud.region.should == "eu"
|
29
|
+
Panda.cloud.eu?.should == true
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
4
34
|
describe "Using configure bloc" do
|
5
35
|
before(:each) do
|
6
36
|
Panda.configure do |c|
|
@@ -48,7 +78,7 @@ describe Panda::Video do
|
|
48
78
|
video.id.should == "123"
|
49
79
|
end
|
50
80
|
|
51
|
-
it "should
|
81
|
+
it "should create a video using cloud" do
|
52
82
|
videos_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
53
83
|
stub_http_request(:post, /api.example.com:85\/v2\/videos.json/).
|
54
84
|
with{|r| r.body =~ /cloud_id=cloud1/}.
|
data/spec/encoding_spec.rb
CHANGED
@@ -63,21 +63,21 @@ describe Panda::Encoding do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should return the video_url" do
|
66
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
|
66
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my_bucket.s3.amazonaws.com/\"}"
|
67
67
|
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
68
68
|
to_return(:body => cloud_json)
|
69
69
|
|
70
|
-
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext"})
|
71
|
-
encoding.url.should == "http://s3.amazonaws.com/
|
70
|
+
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda"})
|
71
|
+
encoding.url.should == "http://my_bucket.s3.amazonaws.com/abc/panda.ext"
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should generate a screenhost array" do
|
75
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
|
75
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my_bucket.s3.amazonaws.com/\"}"
|
76
76
|
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
77
77
|
to_return(:body => cloud_json)
|
78
78
|
|
79
|
-
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :status => "success"})
|
80
|
-
encoding.screenshots[0].should == "http://s3.amazonaws.com/
|
79
|
+
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
80
|
+
encoding.screenshots[0].should == "http://my_bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should generate a screenhost array" do
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- New Bamboo
|
@@ -9,39 +15,55 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-10-19 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: ruby-hmac
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
- 2
|
23
34
|
version: 0.3.2
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: rest-client
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
33
49
|
version: "1.4"
|
34
|
-
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
35
52
|
- !ruby/object:Gem::Dependency
|
36
53
|
name: json
|
37
|
-
|
38
|
-
|
39
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
40
57
|
requirements:
|
41
58
|
- - ">="
|
42
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 11
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 2
|
43
64
|
version: "1.2"
|
44
|
-
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
45
67
|
description: Panda Client
|
46
68
|
email: info@pandastream.com
|
47
69
|
executables: []
|
@@ -100,21 +122,27 @@ rdoc_options:
|
|
100
122
|
require_paths:
|
101
123
|
- lib
|
102
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
103
126
|
requirements:
|
104
127
|
- - ">="
|
105
128
|
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
106
132
|
version: "0"
|
107
|
-
version:
|
108
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
109
135
|
requirements:
|
110
136
|
- - ">="
|
111
137
|
- !ruby/object:Gem::Version
|
138
|
+
hash: 3
|
139
|
+
segments:
|
140
|
+
- 0
|
112
141
|
version: "0"
|
113
|
-
version:
|
114
142
|
requirements: []
|
115
143
|
|
116
144
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.3.
|
145
|
+
rubygems_version: 1.3.7
|
118
146
|
signing_key:
|
119
147
|
specification_version: 3
|
120
148
|
summary: Panda Client
|