panda 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/panda/config.rb +44 -2
- data/lib/panda/errors.rb +4 -1
- data/lib/panda/panda.rb +13 -11
- data/lib/panda/version.rb +1 -1
- data/panda.gemspec +1 -0
- data/spec/panda_spec.rb +50 -2
- metadata +25 -13
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ If you don't use a config file and want to simply be setup, do the following (wo
|
|
45
45
|
|
46
46
|
In most cases you will have used the [panda\_uploader](http://github.com/newbamboo/panda_uploader) jQuery plugin to upload the video (more details about this are in the [Integrating Panda with Ruby on Rails](http://pandastream.com/docs/integrate_with_rails) tutorial). Then you will want to get the video and screenshots urls of your encoding to display to your users.
|
47
47
|
|
48
|
-
The name of the profile can be found in your [Panda account](http://pandastream.com/
|
48
|
+
The name of the profile can be found in your [Panda account](http://pandastream.com/profiles) when editing an encoding cloud's profiles.
|
49
49
|
|
50
50
|
encodings = Panda::Video.find("1234").encodings
|
51
51
|
=> [...]
|
data/lib/panda/config.rb
CHANGED
@@ -2,7 +2,27 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module Panda
|
4
4
|
class Config
|
5
|
-
|
5
|
+
|
6
|
+
def self.from_panda_url(panda_url)
|
7
|
+
panda_uri = URI.parse(panda_url)
|
8
|
+
|
9
|
+
config = new
|
10
|
+
config.access_key = panda_uri.user
|
11
|
+
config.secret_key = panda_uri.password
|
12
|
+
config.cloud_id = panda_uri.path[1..-1]
|
13
|
+
config.api_host = panda_uri.host
|
14
|
+
config.api_port = API_PORT
|
15
|
+
config
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_hash(auth_params)
|
19
|
+
config = new
|
20
|
+
auth_params.each_key do |key|
|
21
|
+
config.send("#{key}=", auth_params[key])
|
22
|
+
end
|
23
|
+
config
|
24
|
+
end
|
25
|
+
|
6
26
|
def config
|
7
27
|
@config ||= {}
|
8
28
|
end
|
@@ -32,6 +52,7 @@ module Panda
|
|
32
52
|
end
|
33
53
|
|
34
54
|
# Setup connection for Heroku
|
55
|
+
# @deprecated: use Config.from_panda_url(panda_url)
|
35
56
|
def parse_panda_url(panda_url)
|
36
57
|
panda_uri = URI.parse(panda_url)
|
37
58
|
|
@@ -53,6 +74,27 @@ module Panda
|
|
53
74
|
raise "Region Unknown"
|
54
75
|
end
|
55
76
|
end
|
56
|
-
|
77
|
+
|
78
|
+
def validate!
|
79
|
+
errs = validation_errors
|
80
|
+
raise Panda::ConfigurationError, errs.join(', ') if errs.any?
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def valid?
|
85
|
+
validation_errors.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def validation_errors
|
89
|
+
err = []
|
90
|
+
if config["access_key"].to_s.empty?
|
91
|
+
err << "access_key is missing"
|
92
|
+
end
|
93
|
+
if config["secret_key"].to_s.empty?
|
94
|
+
err << "secret_key is missing"
|
95
|
+
end
|
96
|
+
err
|
97
|
+
end
|
98
|
+
|
57
99
|
end
|
58
100
|
end
|
data/lib/panda/errors.rb
CHANGED
data/lib/panda/panda.rb
CHANGED
@@ -9,26 +9,27 @@ module Panda
|
|
9
9
|
def_delegators :connection, :get, :post, :put, :delete, :api_url, :setup_bucket, :signed_params
|
10
10
|
|
11
11
|
def configure(auth_params=nil, &block)
|
12
|
+
raise ArgumentError, "missing auth params or block" unless auth_params || block_given?
|
12
13
|
|
13
14
|
if !auth_params
|
14
|
-
|
15
|
+
config = Config.new
|
15
16
|
if (block.arity > 0)
|
16
|
-
block.call(
|
17
|
+
block.call(config)
|
17
18
|
else
|
18
|
-
|
19
|
+
config.instance_eval(&block)
|
19
20
|
end
|
20
|
-
|
21
|
-
auth_params = configure.to_hash
|
22
21
|
elsif auth_params.is_a?(String)
|
23
|
-
|
22
|
+
config = Config.from_panda_url(auth_params)
|
23
|
+
else
|
24
|
+
config = Config.from_hash(auth_params)
|
24
25
|
end
|
25
26
|
|
26
|
-
configure_with_auth_params(
|
27
|
+
configure_with_auth_params(config)
|
27
28
|
true
|
28
29
|
end
|
29
30
|
|
30
31
|
def configure_heroku
|
31
|
-
configure_with_auth_params Config.
|
32
|
+
configure_with_auth_params Config.from_panda_url(ENV['PANDASTREAM_URL'])
|
32
33
|
true
|
33
34
|
end
|
34
35
|
|
@@ -37,7 +38,7 @@ module Panda
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def connection
|
40
|
-
raise "Panda is not configured!" unless @connection
|
41
|
+
raise Panda::ConfigurationError, "Panda is not configured!" unless @connection
|
41
42
|
@connection
|
42
43
|
end
|
43
44
|
|
@@ -55,8 +56,9 @@ module Panda
|
|
55
56
|
Panda::Adapter::RestClient
|
56
57
|
end
|
57
58
|
|
58
|
-
def configure_with_auth_params(
|
59
|
-
|
59
|
+
def configure_with_auth_params(config)
|
60
|
+
config.validate!
|
61
|
+
connect!(config.to_hash)
|
60
62
|
@clouds = {}
|
61
63
|
@cloud = Cloud::new(:id => @connection.cloud_id)
|
62
64
|
end
|
data/lib/panda/version.rb
CHANGED
data/panda.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency "rest-client"
|
17
17
|
s.add_dependency "json"
|
18
18
|
|
19
|
+
s.add_development_dependency "rake"
|
19
20
|
s.add_development_dependency "timecop"
|
20
21
|
s.add_development_dependency "rspec", "2.4.0"
|
21
22
|
s.add_development_dependency "webmock"
|
data/spec/panda_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'timecop'
|
|
3
3
|
|
4
4
|
describe Panda do
|
5
5
|
before(:each) do
|
6
|
-
new_time = Time.
|
6
|
+
new_time = Time.utc(20010, 1, 12, 1, 0, 0)
|
7
7
|
Timecop.freeze(new_time)
|
8
8
|
end
|
9
9
|
|
@@ -13,12 +13,60 @@ describe Panda do
|
|
13
13
|
it "should raise error for #{method}" do
|
14
14
|
lambda {
|
15
15
|
Panda.send(method, nil, nil)
|
16
|
-
}.should raise_error("Panda is not configured!")
|
16
|
+
}.should raise_error(Panda::ConfigurationError, "Panda is not configured!")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "root configuration with hash" do
|
23
|
+
it "should not fail is access_key and secret_key are given" do
|
24
|
+
proc do
|
25
|
+
Panda.configure({:access_key => "bar", :secret_key => "baz"})
|
26
|
+
end.should_not raise_error(Panda::ConfigurationError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fail if access_key or secret_key are missing" do
|
30
|
+
proc do
|
31
|
+
Panda.configure({:secret_key => "baz"})
|
32
|
+
end.should raise_error(Panda::ConfigurationError)
|
33
|
+
proc do
|
34
|
+
Panda.configure({:access_key => "bar"})
|
35
|
+
end.should raise_error(Panda::ConfigurationError)
|
36
|
+
proc do
|
37
|
+
Panda.configure({})
|
38
|
+
end.should raise_error(Panda::ConfigurationError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "root configuration with block" do
|
43
|
+
it "should not fail is access_key and secret_key are given" do
|
44
|
+
proc do
|
45
|
+
Panda.configure do
|
46
|
+
access_key "bar"
|
47
|
+
secret_key "baz"
|
48
|
+
end
|
49
|
+
end.should_not raise_error(Panda::ConfigurationError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should fail if access_key or secret_key are missing" do
|
53
|
+
proc do
|
54
|
+
Panda.configure do
|
55
|
+
secret_key "baz"
|
56
|
+
end
|
57
|
+
end.should raise_error(Panda::ConfigurationError)
|
58
|
+
proc do
|
59
|
+
Panda.configure do
|
60
|
+
access_key "bar"
|
61
|
+
end
|
62
|
+
end.should raise_error(Panda::ConfigurationError)
|
63
|
+
proc do
|
64
|
+
Panda.configure do
|
65
|
+
end
|
66
|
+
end.should raise_error(Panda::ConfigurationError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
22
70
|
shared_examples_for "Connected" do
|
23
71
|
|
24
72
|
it "should make get request with signed request to panda server" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 3
|
10
|
+
version: 1.4.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- New Bamboo
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-08-18 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: ruby-hmac
|
@@ -63,7 +62,7 @@ dependencies:
|
|
63
62
|
type: :runtime
|
64
63
|
version_requirements: *id003
|
65
64
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
65
|
+
name: rake
|
67
66
|
prerelease: false
|
68
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
68
|
none: false
|
@@ -77,9 +76,23 @@ dependencies:
|
|
77
76
|
type: :development
|
78
77
|
version_requirements: *id004
|
79
78
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
79
|
+
name: timecop
|
81
80
|
prerelease: false
|
82
81
|
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rspec
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
83
96
|
none: false
|
84
97
|
requirements:
|
85
98
|
- - "="
|
@@ -91,11 +104,11 @@ dependencies:
|
|
91
104
|
- 0
|
92
105
|
version: 2.4.0
|
93
106
|
type: :development
|
94
|
-
version_requirements: *
|
107
|
+
version_requirements: *id006
|
95
108
|
- !ruby/object:Gem::Dependency
|
96
109
|
name: webmock
|
97
110
|
prerelease: false
|
98
|
-
requirement: &
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
99
112
|
none: false
|
100
113
|
requirements:
|
101
114
|
- - ">="
|
@@ -105,7 +118,7 @@ dependencies:
|
|
105
118
|
- 0
|
106
119
|
version: "0"
|
107
120
|
type: :development
|
108
|
-
version_requirements: *
|
121
|
+
version_requirements: *id007
|
109
122
|
description: Panda Client
|
110
123
|
email:
|
111
124
|
- info@pandastream.com
|
@@ -161,7 +174,6 @@ files:
|
|
161
174
|
- spec/profile_spec.rb
|
162
175
|
- spec/spec_helper.rb
|
163
176
|
- spec/video_spec.rb
|
164
|
-
has_rdoc: true
|
165
177
|
homepage: http://github.com/newbamboo/panda_gem
|
166
178
|
licenses: []
|
167
179
|
|
@@ -191,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
203
|
requirements: []
|
192
204
|
|
193
205
|
rubyforge_project: panda
|
194
|
-
rubygems_version: 1.
|
206
|
+
rubygems_version: 1.8.5
|
195
207
|
signing_key:
|
196
208
|
specification_version: 3
|
197
209
|
summary: Panda Client
|