panda 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/CHANGELOG.md +7 -0
- data/README.md +12 -4
- data/Rakefile +1 -1
- data/lib/panda.rb +3 -2
- data/lib/panda/base.rb +2 -2
- data/lib/panda/config.rb +1 -14
- data/lib/panda/connection.rb +15 -18
- data/lib/panda/errors.rb +0 -3
- data/lib/panda/{adapters/faraday.rb → faraday.rb} +21 -10
- data/lib/panda/panda.rb +4 -9
- data/lib/panda/resources/cloud.rb +6 -0
- data/lib/panda/resources/encoding.rb +14 -8
- data/lib/panda/resources/video.rb +10 -6
- data/lib/panda/version.rb +1 -1
- data/panda.gemspec +3 -4
- data/spec/encoding_spec.rb +15 -6
- data/spec/heroku_spec.rb +1 -1
- data/spec/panda_spec.rb +14 -14
- data/spec/spec_helper.rb +0 -1
- data/spec/video_spec.rb +26 -12
- metadata +115 -134
- data/lib/panda/adapters/adapter.rb +0 -6
- data/lib/panda/adapters/restclient.rb +0 -54
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
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/
|
5
|
+
* [Visit panda\_gem on Github](http://github.com/pandastream/panda_gem)
|
6
|
+
* [![Build
|
7
|
+
Status](https://secure.travis-ci.org/pandastream/panda_gem.png?branch=master)](http://travis-ci.org/pandastream/panda_gem)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -13,6 +15,12 @@ Panda gem provides an interface to access the [Panda](http://pandastream.com) AP
|
|
13
15
|
require 'rubygems'
|
14
16
|
require 'panda'
|
15
17
|
|
18
|
+
## Faraday Adapter
|
19
|
+
The gem automatically detects http libraries and sets the default adapter
|
20
|
+
You can just set the default Panda adapter if you are not happy with the current one.
|
21
|
+
|
22
|
+
Panda.default_adapter = :excon
|
23
|
+
|
16
24
|
### Creating an instance of the client
|
17
25
|
|
18
26
|
Panda.configure do
|
@@ -31,7 +39,7 @@ Heroku will store your credentials as an environment variable called PANDASTREAM
|
|
31
39
|
|
32
40
|
If you use a config file like `config/panda.yml` to support multiple environments, do the following in your `config/initializers/panda.rb` :
|
33
41
|
|
34
|
-
Panda.configure((ENV['PANDASTREAM_URL'] || YAML::load_file(File.join(File.dirname(__FILE__),"..", "panda.yml"))[
|
42
|
+
Panda.configure((ENV['PANDASTREAM_URL'] || YAML::load_file(File.join(File.dirname(__FILE__),"..", "panda.yml"))[Rails.env]))
|
35
43
|
|
36
44
|
See the [Rails How-to](http://www.pandastream.com/docs/integrate_with_rails) for more details.
|
37
45
|
|
@@ -43,7 +51,7 @@ If you don't use a config file and want to simply be setup, do the following (wo
|
|
43
51
|
|
44
52
|
### Typical usage
|
45
53
|
|
46
|
-
In most cases you will have used the [panda\_uploader](http://github.com/
|
54
|
+
In most cases you will have used the [panda\_uploader](http://github.com/pandastream/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
55
|
|
48
56
|
The name of the profile can be found in your [Panda account](http://pandastream.com/profiles) when editing an encoding cloud's profiles.
|
49
57
|
|
@@ -394,7 +402,7 @@ The name of the profile can be found in your [Panda account](http://pandastream.
|
|
394
402
|
|
395
403
|
## Generating signatures
|
396
404
|
|
397
|
-
All requests to your Panda cloud are signed using HMAC-SHA256, based on a timestamp and your Panda secret key. This is handled transparently. However, sometimes you will want to generate only this signature, in order to make a request by means other than this library. This is the case when using the [JavaScript panda_uploader](http://github.com/
|
405
|
+
All requests to your Panda cloud are signed using HMAC-SHA256, based on a timestamp and your Panda secret key. This is handled transparently. However, sometimes you will want to generate only this signature, in order to make a request by means other than this library. This is the case when using the [JavaScript panda_uploader](http://github.com/pandastream/panda_uploader).
|
398
406
|
|
399
407
|
To do this, a method `signed_params()` is supported:
|
400
408
|
|
data/Rakefile
CHANGED
data/lib/panda.rb
CHANGED
@@ -15,8 +15,6 @@ require 'panda/proxies/scope'
|
|
15
15
|
require 'panda/proxies/encoding_scope'
|
16
16
|
require 'panda/proxies/video_scope'
|
17
17
|
require 'panda/proxies/profile_scope'
|
18
|
-
require 'panda/adapters/adapter'
|
19
|
-
require 'panda/adapters/faraday'
|
20
18
|
require 'panda/errors'
|
21
19
|
require 'panda/base'
|
22
20
|
require 'panda/resources/resource'
|
@@ -24,4 +22,7 @@ require 'panda/resources/cloud'
|
|
24
22
|
require 'panda/resources/encoding'
|
25
23
|
require 'panda/resources/profile'
|
26
24
|
require 'panda/resources/video'
|
25
|
+
|
27
26
|
require 'panda/panda'
|
27
|
+
require 'panda/faraday'
|
28
|
+
|
data/lib/panda/base.rb
CHANGED
data/lib/panda/config.rb
CHANGED
@@ -11,7 +11,7 @@ module Panda
|
|
11
11
|
config.secret_key = panda_uri.password
|
12
12
|
config.cloud_id = panda_uri.path[1..-1]
|
13
13
|
config.api_host = panda_uri.host
|
14
|
-
config.api_port =
|
14
|
+
config.api_port = panda_uri.port
|
15
15
|
config
|
16
16
|
end
|
17
17
|
|
@@ -50,19 +50,6 @@ module Panda
|
|
50
50
|
def adapter=(adapter_name)
|
51
51
|
Panda.adapter = adapter_name
|
52
52
|
end
|
53
|
-
|
54
|
-
# Setup connection for Heroku
|
55
|
-
# @deprecated: use Config.from_panda_url(panda_url)
|
56
|
-
def parse_panda_url(panda_url)
|
57
|
-
panda_uri = URI.parse(panda_url)
|
58
|
-
|
59
|
-
config['access_key'] = panda_uri.user
|
60
|
-
config['secret_key'] = panda_uri.password
|
61
|
-
config['cloud_id'] = panda_uri.path[1..-1]
|
62
|
-
config['api_host'] = panda_uri.host
|
63
|
-
config['api_port'] = API_PORT
|
64
|
-
config
|
65
|
-
end
|
66
53
|
|
67
54
|
# Set the correct api_host for US/EU
|
68
55
|
def region(region)
|
data/lib/panda/connection.rb
CHANGED
@@ -7,34 +7,41 @@ module Panda
|
|
7
7
|
class Connection
|
8
8
|
attr_accessor :api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id
|
9
9
|
|
10
|
-
def initialize(auth_params={})
|
10
|
+
def initialize(auth_params={})
|
11
|
+
params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(auth_params)
|
11
12
|
@api_version = 2
|
12
|
-
|
13
|
+
|
14
|
+
@cloud_id = params["cloud_id"] || params[:cloud_id]
|
15
|
+
@access_key = params["access_key"] || params[:access_key]
|
16
|
+
@secret_key = params["secret_key"] || params[:secret_key]
|
17
|
+
@api_host = params["api_host"] || params[:api_host]
|
18
|
+
@api_port = params["api_port"] || params[:api_port]
|
19
|
+
@prefix = params["prefix_url"] || "v#{api_version}"
|
13
20
|
end
|
14
21
|
|
15
|
-
def
|
16
|
-
|
22
|
+
def http_client
|
23
|
+
Panda::HttpClient::Faraday.new(api_url)
|
17
24
|
end
|
18
25
|
|
19
26
|
# Authenticated requests
|
20
27
|
def get(request_uri, params={})
|
21
28
|
sp = signed_params("GET", request_uri, params)
|
22
|
-
|
29
|
+
http_client.get(request_uri, sp)
|
23
30
|
end
|
24
31
|
|
25
32
|
def post(request_uri, params={})
|
26
33
|
sp = signed_params("POST", request_uri, params)
|
27
|
-
|
34
|
+
http_client.post(request_uri, sp)
|
28
35
|
end
|
29
36
|
|
30
37
|
def put(request_uri, params={})
|
31
38
|
sp = signed_params("PUT", request_uri, params)
|
32
|
-
|
39
|
+
http_client.put(request_uri, sp)
|
33
40
|
end
|
34
41
|
|
35
42
|
def delete(request_uri, params={})
|
36
43
|
sp = signed_params("DELETE", request_uri, params)
|
37
|
-
|
44
|
+
http_client.delete(request_uri, sp)
|
38
45
|
end
|
39
46
|
|
40
47
|
# Signing methods
|
@@ -89,16 +96,6 @@ module Panda
|
|
89
96
|
end
|
90
97
|
end
|
91
98
|
|
92
|
-
def init_from_hash(hash_params)
|
93
|
-
params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(hash_params)
|
94
|
-
|
95
|
-
@cloud_id = params["cloud_id"] || params[:cloud_id]
|
96
|
-
@access_key = params["access_key"] || params[:access_key]
|
97
|
-
@secret_key = params["secret_key"] || params[:secret_key]
|
98
|
-
@api_host = params["api_host"] || params[:api_host]
|
99
|
-
@api_port = params["api_port"] || params[:api_port]
|
100
|
-
@prefix = params["prefix_url"] || "v#{api_version}"
|
101
|
-
end
|
102
99
|
end
|
103
100
|
end
|
104
101
|
|
data/lib/panda/errors.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'multi_json'
|
3
3
|
|
4
4
|
module Panda
|
5
|
-
module
|
5
|
+
module HttpClient
|
6
6
|
class Faraday
|
7
7
|
|
8
8
|
def initialize(api_url)
|
@@ -11,7 +11,7 @@ module Panda
|
|
11
11
|
|
12
12
|
def get(request_uri, params)
|
13
13
|
rescue_json_parsing do
|
14
|
-
|
14
|
+
connection.get do |req|
|
15
15
|
req.url File.join(connection.path_prefix, request_uri), params
|
16
16
|
end.body
|
17
17
|
end
|
@@ -19,9 +19,7 @@ module Panda
|
|
19
19
|
|
20
20
|
def post(request_uri, params)
|
21
21
|
# multipart upload
|
22
|
-
|
23
|
-
params['file'] = ::Faraday::UploadIO.new(f.path, 'multipart/form-data')
|
24
|
-
end
|
22
|
+
params['file'] = ::Faraday::UploadIO.new(params['file'], 'multipart/form-data') if params['file']
|
25
23
|
|
26
24
|
rescue_json_parsing do
|
27
25
|
connection.post do |req|
|
@@ -54,18 +52,31 @@ module Panda
|
|
54
52
|
@conn ||= ::Faraday.new(:url => @api_url) do |builder|
|
55
53
|
builder.request :multipart
|
56
54
|
builder.request :url_encoded
|
57
|
-
builder.adapter
|
55
|
+
builder.adapter Panda.default_adapter
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
59
|
def rescue_json_parsing(&block)
|
62
60
|
begin
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
data = yield
|
62
|
+
MultiJson.load(data)
|
63
|
+
rescue MultiJson::DecodeError
|
64
|
+
raise ServiceNotAvailable, data
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
end
|
70
69
|
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if defined?(Typhoeus)
|
73
|
+
Panda.default_adapter = :typhoeus
|
74
|
+
elsif defined?(Excon)
|
75
|
+
Panda.default_adapter = :excon
|
76
|
+
elsif defined?(Patron)
|
77
|
+
Panda.default_adapter = :patron
|
78
|
+
elsif defined?(NetHttpPersistent)
|
79
|
+
Panda.default_adapter = :net_http_persisten
|
80
|
+
else
|
81
|
+
Panda.default_adapter = :net_http
|
71
82
|
end
|
data/lib/panda/panda.rb
CHANGED
@@ -42,25 +42,20 @@ module Panda
|
|
42
42
|
@connection
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
@
|
45
|
+
def default_adapter=(adapter_name)
|
46
|
+
@adapter = adapter_name.to_sym
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
@
|
49
|
+
def default_adapter
|
50
|
+
@adapter
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
|
-
def default_adapter
|
56
|
-
Panda::Adapter::Faraday
|
57
|
-
end
|
58
|
-
|
59
55
|
def configure_with_auth_params(config)
|
60
56
|
config.validate!
|
61
57
|
connect!(config.to_hash)
|
62
58
|
@clouds = {}
|
63
59
|
@cloud = Cloud::new(:id => @connection.cloud_id)
|
64
60
|
end
|
65
|
-
|
66
61
|
end
|
@@ -11,17 +11,23 @@ module Panda
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def url
|
14
|
+
def url(options={})
|
15
|
+
default_options = {:https => false}
|
16
|
+
options = default_options.merge(options)
|
15
17
|
full_path = "#{path}#{extname}"
|
16
|
-
get_url(full_path) if files.include?(full_path)
|
18
|
+
get_url(full_path, options[:https]) if files.include?(full_path)
|
17
19
|
end
|
18
20
|
|
19
|
-
def urls
|
20
|
-
|
21
|
+
def urls(options={})
|
22
|
+
default_options = {:https => false}
|
23
|
+
options = default_options.merge(options)
|
24
|
+
files.map {|f| get_url(f, options[:https])}
|
21
25
|
end
|
22
26
|
|
23
|
-
def screenshots
|
24
|
-
|
27
|
+
def screenshots(options={})
|
28
|
+
default_options = {:https => false}
|
29
|
+
options = default_options.merge(options)
|
30
|
+
((1..7).map{|i| get_url("#{path}_#{i}.jpg", options[:https])} if success?) || []
|
25
31
|
end
|
26
32
|
|
27
33
|
def cancel
|
@@ -34,8 +40,8 @@ module Panda
|
|
34
40
|
|
35
41
|
private
|
36
42
|
|
37
|
-
def get_url(end_path)
|
38
|
-
"#{cloud.url}#{end_path}"
|
43
|
+
def get_url(end_path, https)
|
44
|
+
"#{https ? cloud.https_url : cloud.url}#{end_path}"
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -13,18 +13,22 @@ module Panda
|
|
13
13
|
connection.get("/videos/#{id}/metadata.json")
|
14
14
|
end
|
15
15
|
|
16
|
-
def preview_url
|
17
|
-
|
16
|
+
def preview_url(options={})
|
17
|
+
default_options = {:https => false}
|
18
|
+
options = default_options.merge(options)
|
19
|
+
get_url("#{path}_1.jpg", options[:https]) if success?
|
18
20
|
end
|
19
21
|
|
20
|
-
def url
|
21
|
-
|
22
|
+
def url(options={})
|
23
|
+
default_options = {:https => false}
|
24
|
+
options = default_options.merge(options)
|
25
|
+
get_url("#{path}#{extname}", options[:https]) if success?
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
26
|
-
def get_url(end_path)
|
27
|
-
"#{cloud.url}#{end_path}"
|
30
|
+
def get_url(end_path, https)
|
31
|
+
"#{https ? cloud.https_url : cloud.url}#{end_path}"
|
28
32
|
end
|
29
33
|
|
30
34
|
end
|
data/lib/panda/version.rb
CHANGED
data/panda.gemspec
CHANGED
@@ -14,13 +14,12 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency "ruby-hmac", ">= 0.3.2"
|
16
16
|
s.add_dependency "faraday", ">= 0.7.0"
|
17
|
-
s.add_dependency "
|
18
|
-
s.add_dependency "multi_json"
|
17
|
+
s.add_dependency "multi_json", ">= 1.3.2"
|
19
18
|
|
20
19
|
s.add_development_dependency "rake"
|
21
20
|
s.add_development_dependency "timecop"
|
22
|
-
s.add_development_dependency "rspec", "2.
|
23
|
-
s.add_development_dependency "webmock"
|
21
|
+
s.add_development_dependency "rspec", ">= 2.8.0"
|
22
|
+
s.add_development_dependency "webmock", ">= 1.8.2"
|
24
23
|
|
25
24
|
s.rubyforge_project = "panda"
|
26
25
|
|
data/spec/encoding_spec.rb
CHANGED
@@ -63,24 +63,33 @@ describe Panda::Encoding do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should return the encoding url" do
|
66
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://
|
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
70
|
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda", "files" => ["abc/panda.ext"], :status => 'success'})
|
71
|
-
encoding.url.should == "http://
|
71
|
+
encoding.url.should == "http://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return the secure encoding url" do
|
75
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
76
|
+
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
77
|
+
to_return(:body => cloud_json)
|
78
|
+
|
79
|
+
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda", "files" => ["abc/panda.ext"], :status => 'success'})
|
80
|
+
encoding.url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
72
81
|
end
|
73
82
|
|
74
|
-
it "should generate a
|
75
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://
|
83
|
+
it "should generate a screenshot array" do
|
84
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
76
85
|
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
77
86
|
to_return(:body => cloud_json)
|
78
87
|
|
79
88
|
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
80
|
-
encoding.screenshots[0].should == "http://
|
89
|
+
encoding.screenshots[0].should == "http://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
81
90
|
end
|
82
91
|
|
83
|
-
it "should generate a
|
92
|
+
it "should generate a screenshot array" do
|
84
93
|
encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :status => "fail"})
|
85
94
|
encoding.screenshots.should == []
|
86
95
|
end
|
data/spec/heroku_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Panda::Video do
|
|
6
6
|
stub_http_request(:get, /api.example.com:443\/v2\/clouds\/my_cloud_id.json/).
|
7
7
|
to_return(:body => cloud_json)
|
8
8
|
|
9
|
-
my_heroku_url = "http://access_key:secret_key@api.example.com:
|
9
|
+
my_heroku_url = "http://access_key:secret_key@api.example.com:443/my_cloud_id"
|
10
10
|
ENV['PANDASTREAM_URL']= my_heroku_url
|
11
11
|
end
|
12
12
|
|
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.utc(
|
6
|
+
new_time = Time.utc(2010, 1, 12, 1, 0, 0)
|
7
7
|
Timecop.freeze(new_time)
|
8
8
|
end
|
9
9
|
|
@@ -70,7 +70,7 @@ describe Panda do
|
|
70
70
|
shared_examples_for "Connected" do
|
71
71
|
|
72
72
|
it "should make get request with signed request to panda server" do
|
73
|
-
stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=
|
73
|
+
stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=kAiCpkP52a2XKISJjRCBWzWCN5CaeLK3Nj1AT25S/Go=×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"abc\":\"d\"}")
|
74
74
|
@panda.get("/videos").should == {'abc' => 'd'}
|
75
75
|
end
|
76
76
|
|
@@ -81,9 +81,9 @@ describe Panda do
|
|
81
81
|
)
|
82
82
|
signed_params.should == {
|
83
83
|
'access_key' => "my_access_key",
|
84
|
-
'timestamp' => "
|
84
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
85
85
|
'cloud_id' => 'my_cloud_id',
|
86
|
-
'signature' => '
|
86
|
+
'signature' => '/Yu4CqImbYNXWwpNSIfHzdWeMsR5J7O6tfbSHXQO0aA=',
|
87
87
|
'param1' => 'one',
|
88
88
|
'param2' => 'two'
|
89
89
|
}
|
@@ -92,9 +92,9 @@ describe Panda do
|
|
92
92
|
it "should create a signed version of the parameters without additional arguments" do
|
93
93
|
@panda.signed_params('POST', '/videos.json').should == {
|
94
94
|
'access_key' => "my_access_key",
|
95
|
-
'timestamp' => "
|
95
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
96
96
|
'cloud_id' => 'my_cloud_id',
|
97
|
-
'signature' => '
|
97
|
+
'signature' => 'QpQQm0guSLSEXmQ+EP2qnKT0av5llLWBUylEk9NEStU='
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
@@ -106,9 +106,9 @@ describe Panda do
|
|
106
106
|
)
|
107
107
|
signed_params.should == {
|
108
108
|
'access_key' => "my_access_key",
|
109
|
-
'timestamp' => "
|
109
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
110
110
|
'cloud_id' => 'my_cloud_id',
|
111
|
-
'signature' => '
|
111
|
+
'signature' => 'v7++pgmzztwOWzZ+MoflgD1TT8Jxnqzl1v8gNnEbhX8=',
|
112
112
|
'tilde' => '~',
|
113
113
|
'space' => ' '
|
114
114
|
}
|
@@ -118,9 +118,9 @@ describe Panda do
|
|
118
118
|
it "should not include file inside the signature" do
|
119
119
|
@panda.signed_params('POST', '/videos.json', { "file" => "my_file" }).should == {
|
120
120
|
'access_key' => "my_access_key",
|
121
|
-
'timestamp' => "
|
121
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
122
122
|
'cloud_id' => 'my_cloud_id',
|
123
|
-
'signature' => '
|
123
|
+
'signature' => 'QpQQm0guSLSEXmQ+EP2qnKT0av5llLWBUylEk9NEStU=',
|
124
124
|
'file' => "my_file"
|
125
125
|
}
|
126
126
|
end
|
@@ -128,9 +128,9 @@ describe Panda do
|
|
128
128
|
it "should stringify keys" do
|
129
129
|
@panda.signed_params('POST', '/videos.json', { :file => "symbol_key" }).should == {
|
130
130
|
'access_key' => "my_access_key",
|
131
|
-
'timestamp' => "
|
131
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
132
132
|
'cloud_id' => 'my_cloud_id',
|
133
|
-
'signature' => '
|
133
|
+
'signature' => 'QpQQm0guSLSEXmQ+EP2qnKT0av5llLWBUylEk9NEStU=',
|
134
134
|
'file' => "symbol_key"
|
135
135
|
}
|
136
136
|
end
|
@@ -165,7 +165,7 @@ describe Panda do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should make get request" do
|
168
|
-
stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=
|
168
|
+
stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=kAiCpkP52a2XKISJjRCBWzWCN5CaeLK3Nj1AT25S/Go=×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"key\":\"value\"}")
|
169
169
|
@panda.get("/videos").should == {'key' => 'value'}
|
170
170
|
end
|
171
171
|
|
@@ -177,7 +177,7 @@ describe Panda do
|
|
177
177
|
# @panda = Panda::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
|
178
178
|
# Panda.adapter = 'restclient'
|
179
179
|
#
|
180
|
-
# stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D×tamp=
|
180
|
+
# stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "abc")
|
181
181
|
#
|
182
182
|
#
|
183
183
|
# module ActiveSupport
|
data/spec/spec_helper.rb
CHANGED
data/spec/video_spec.rb
CHANGED
@@ -226,11 +226,7 @@ describe Panda::Video do
|
|
226
226
|
it "should return a json on attributes" do
|
227
227
|
video = Panda::Video.new(:attr => "value")
|
228
228
|
|
229
|
-
|
230
|
-
video.to_json.should == "{\"attr\":\"value\",\"cloud_id\":\"my_cloud_id\"}"
|
231
|
-
else
|
232
|
-
video.to_json.should == "{\"cloud_id\":\"my_cloud_id\",\"attr\":\"value\"}"
|
233
|
-
end
|
229
|
+
MultiJson.load( video.to_json ).should == {"attr" => "value", "cloud_id" => "my_cloud_id"}
|
234
230
|
end
|
235
231
|
|
236
232
|
it "should create an encoding using video scope" do
|
@@ -284,25 +280,43 @@ describe Panda::Video do
|
|
284
280
|
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
285
281
|
stub_http_request(:get, /api.example.com:85\/v2\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
286
282
|
|
287
|
-
video.encodings.first.to_json.should ==
|
283
|
+
MultiJson.load( video.encodings.first.to_json ).should == {"abc" => "my_source_url", "id" => "456", "cloud_id" => "my_cloud_id"}
|
288
284
|
end
|
289
285
|
|
290
286
|
it "should return the video url" do
|
291
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://
|
287
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
292
288
|
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
293
289
|
to_return(:body => cloud_json)
|
294
290
|
|
295
291
|
video = Panda::Video.new({:id => "456", :extname => ".ext", :path => "abc/panda", :status => 'success'})
|
296
|
-
video.url.should == "http://
|
292
|
+
video.url.should == "http://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should return the secure video url" do
|
296
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
297
|
+
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
298
|
+
to_return(:body => cloud_json)
|
299
|
+
|
300
|
+
video = Panda::Video.new({:id => "456", :extname => ".ext", :path => "abc/panda", :status => 'success'})
|
301
|
+
video.url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
297
302
|
end
|
298
303
|
|
299
|
-
it "should generate a
|
300
|
-
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://
|
304
|
+
it "should generate a screenshot url" do
|
305
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
306
|
+
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
307
|
+
to_return(:body => cloud_json)
|
308
|
+
|
309
|
+
video = Panda::Video.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
310
|
+
video.preview_url.should == "http://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should generate a secure screenshot url" do
|
314
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
301
315
|
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
|
302
316
|
to_return(:body => cloud_json)
|
303
317
|
|
304
318
|
video = Panda::Video.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
305
|
-
video.preview_url.should == "
|
319
|
+
video.preview_url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
306
320
|
end
|
307
321
|
|
308
322
|
it "should call the request if the scope has changed" do
|
@@ -382,4 +396,4 @@ describe Panda::Video do
|
|
382
396
|
video = Panda::Video.find "123"
|
383
397
|
video.cloud.s3_videos_bucket.should == "my_bucket"
|
384
398
|
end
|
385
|
-
end
|
399
|
+
end
|
metadata
CHANGED
@@ -1,166 +1,150 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: panda
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 1.5.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Pandastream
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: ruby-hmac
|
22
|
-
|
23
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 23
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 3
|
32
|
-
- 2
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 0.3.2
|
22
|
+
type: :runtime
|
34
23
|
prerelease: false
|
35
|
-
|
36
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
37
31
|
name: faraday
|
38
|
-
|
39
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
40
33
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 7
|
48
|
-
- 0
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
49
37
|
version: 0.7.0
|
50
|
-
prerelease: false
|
51
|
-
requirement: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: typhoeus
|
54
38
|
type: :runtime
|
55
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
64
39
|
prerelease: false
|
65
|
-
|
66
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.7.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
67
47
|
name: multi_json
|
68
|
-
|
69
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
70
49
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.2
|
54
|
+
type: :runtime
|
78
55
|
prerelease: false
|
79
|
-
|
80
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
81
63
|
name: rake
|
82
|
-
|
83
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
84
65
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
|
90
|
-
- 0
|
91
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
92
71
|
prerelease: false
|
93
|
-
|
94
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
95
79
|
name: timecop
|
96
|
-
|
97
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
98
81
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
103
|
-
|
104
|
-
- 0
|
105
|
-
version: "0"
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
106
87
|
prerelease: false
|
107
|
-
|
108
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
109
95
|
name: rspec
|
110
|
-
|
111
|
-
version_requirements: &id007 !ruby/object:Gem::Requirement
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
112
97
|
none: false
|
113
|
-
requirements:
|
114
|
-
- -
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
|
117
|
-
|
118
|
-
- 2
|
119
|
-
- 4
|
120
|
-
- 0
|
121
|
-
version: 2.4.0
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.8.0
|
102
|
+
type: :development
|
122
103
|
prerelease: false
|
123
|
-
|
124
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.8.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
125
111
|
name: webmock
|
126
|
-
|
127
|
-
version_requirements: &id008 !ruby/object:Gem::Requirement
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
128
113
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
|
134
|
-
- 0
|
135
|
-
version: "0"
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.8.2
|
118
|
+
type: :development
|
136
119
|
prerelease: false
|
137
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.8.2
|
138
126
|
description: Panda Client
|
139
|
-
email:
|
127
|
+
email:
|
140
128
|
- info@pandastream.com
|
141
129
|
executables: []
|
142
|
-
|
143
130
|
extensions: []
|
144
|
-
|
145
131
|
extra_rdoc_files: []
|
146
|
-
|
147
|
-
files:
|
132
|
+
files:
|
148
133
|
- .gitignore
|
149
134
|
- .rspec
|
135
|
+
- .travis.yml
|
150
136
|
- CHANGELOG.md
|
151
137
|
- Gemfile
|
152
138
|
- LICENSE
|
153
139
|
- README.md
|
154
140
|
- Rakefile
|
155
141
|
- lib/panda.rb
|
156
|
-
- lib/panda/adapters/adapter.rb
|
157
|
-
- lib/panda/adapters/faraday.rb
|
158
|
-
- lib/panda/adapters/restclient.rb
|
159
142
|
- lib/panda/api_authentication.rb
|
160
143
|
- lib/panda/base.rb
|
161
144
|
- lib/panda/config.rb
|
162
145
|
- lib/panda/connection.rb
|
163
146
|
- lib/panda/errors.rb
|
147
|
+
- lib/panda/faraday.rb
|
164
148
|
- lib/panda/modules/associations.rb
|
165
149
|
- lib/panda/modules/builders.rb
|
166
150
|
- lib/panda/modules/cloud_connection.rb
|
@@ -191,38 +175,35 @@ files:
|
|
191
175
|
- spec/video_spec.rb
|
192
176
|
homepage: http://github.com/pandastream/panda_gem
|
193
177
|
licenses: []
|
194
|
-
|
195
178
|
post_install_message:
|
196
179
|
rdoc_options: []
|
197
|
-
|
198
|
-
require_paths:
|
180
|
+
require_paths:
|
199
181
|
- lib
|
200
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
183
|
none: false
|
202
|
-
requirements:
|
203
|
-
- -
|
204
|
-
- !ruby/object:Gem::Version
|
205
|
-
|
206
|
-
segments:
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
segments:
|
207
189
|
- 0
|
208
|
-
|
209
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
hash: -2129573717660849291
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
192
|
none: false
|
211
|
-
requirements:
|
212
|
-
- -
|
213
|
-
- !ruby/object:Gem::Version
|
214
|
-
|
215
|
-
segments:
|
193
|
+
requirements:
|
194
|
+
- - ! '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
segments:
|
216
198
|
- 0
|
217
|
-
|
199
|
+
hash: -2129573717660849291
|
218
200
|
requirements: []
|
219
|
-
|
220
201
|
rubyforge_project: panda
|
221
|
-
rubygems_version: 1.8.
|
202
|
+
rubygems_version: 1.8.24
|
222
203
|
signing_key:
|
223
204
|
specification_version: 3
|
224
205
|
summary: Panda Client
|
225
|
-
test_files:
|
206
|
+
test_files:
|
226
207
|
- spec/cloud_spec.rb
|
227
208
|
- spec/encoding_spec.rb
|
228
209
|
- spec/heroku_spec.rb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'restclient'
|
2
|
-
|
3
|
-
module Panda
|
4
|
-
module Adapter
|
5
|
-
class RestClient
|
6
|
-
|
7
|
-
def initialize(api_url)
|
8
|
-
@api_url = api_url
|
9
|
-
end
|
10
|
-
|
11
|
-
def get(request_uri, params)
|
12
|
-
rescue_json_parsing do
|
13
|
-
query = ApiAuthentication.hash_to_query(params)
|
14
|
-
connection[request_uri + '?' + query].get
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def post(request_uri, params)
|
19
|
-
rescue_json_parsing do
|
20
|
-
connection[request_uri].post(params)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def put(request_uri, params)
|
25
|
-
rescue_json_parsing do
|
26
|
-
connection[request_uri].put(params)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def delete(request_uri, params)
|
31
|
-
rescue_json_parsing do
|
32
|
-
query = ApiAuthentication.hash_to_query(params)
|
33
|
-
connection[request_uri + '?' + query].delete
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def connection
|
40
|
-
@conn ||= ::RestClient::Resource.new(@api_url)
|
41
|
-
end
|
42
|
-
|
43
|
-
def rescue_json_parsing(&block)
|
44
|
-
begin
|
45
|
-
MultiJson.decode(yield)
|
46
|
-
rescue MultiJson::DecodeError => e
|
47
|
-
raise(ServiceNotAvailable)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|