panda 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/{spec/spec.opts → .rspec} +0 -0
- data/CHANGELOG.md +52 -0
- data/Gemfile +2 -14
- data/README.md +38 -32
- data/Rakefile +9 -27
- data/lib/panda.rb +9 -3
- data/lib/panda/adapters/adapter.rb +4 -0
- data/lib/panda/adapters/faraday.rb +70 -0
- data/lib/panda/adapters/restclient.rb +67 -0
- data/lib/panda/api_authentication.rb +2 -0
- data/lib/panda/base.rb +23 -21
- data/lib/panda/config.rb +58 -0
- data/lib/panda/connection.rb +33 -122
- data/lib/panda/errors.rb +17 -0
- data/lib/panda/modules/builders.rb +18 -10
- data/lib/panda/modules/destroyers.rb +25 -0
- data/lib/panda/modules/finders.rb +10 -4
- data/lib/panda/modules/router.rb +16 -10
- data/lib/panda/modules/updatable.rb +3 -2
- data/lib/panda/modules/video_state.rb +16 -0
- data/lib/panda/modules/viewable.rb +19 -0
- data/lib/panda/panda.rb +41 -20
- data/lib/panda/proxies/proxy.rb +3 -1
- data/lib/panda/proxies/scope.rb +34 -28
- data/lib/panda/resources/cloud.rb +13 -11
- data/lib/panda/resources/encoding.rb +4 -19
- data/lib/panda/resources/resource.rb +2 -12
- data/lib/panda/resources/video.rb +4 -1
- data/lib/panda/version.rb +3 -0
- data/panda.gemspec +22 -105
- data/spec/cloud_spec.rb +44 -35
- data/spec/encoding_spec.rb +28 -9
- data/spec/heroku_spec.rb +15 -5
- data/spec/panda_spec.rb +41 -68
- data/spec/profile_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -4
- data/spec/video_spec.rb +68 -19
- metadata +44 -98
- data/VERSION +0 -1
- data/lib/panda/error.rb +0 -29
- data/lib/panda/modules/short_status.rb +0 -13
@@ -19,8 +19,9 @@ module Panda
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def update
|
22
|
-
|
23
|
-
|
22
|
+
uri = replace_pattern_with_self_variables(self.class.one_path)
|
23
|
+
response = connection.put(uri, @changed_attributes)
|
24
|
+
load_and_reset(response)
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Panda
|
2
|
+
module Viewable
|
3
|
+
|
4
|
+
def screenshots
|
5
|
+
((1..screenshots_size||0).map{|i| get_url("_#{i}.jpg")} if success?) || []
|
6
|
+
end
|
7
|
+
|
8
|
+
def url
|
9
|
+
get_url("#{extname}") if success?
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_url(end_path)
|
15
|
+
"#{cloud.url}#{path}#{end_path}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/panda/panda.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
require 'restclient'
|
2
|
-
require 'forwardable'
|
3
|
-
require 'json' unless defined?(ActiveSupport::JSON) || defined?(JSON::JSON_LOADED)
|
4
|
-
|
5
1
|
module Panda
|
2
|
+
|
6
3
|
extend self
|
7
4
|
extend Forwardable
|
8
5
|
|
@@ -11,33 +8,57 @@ module Panda
|
|
11
8
|
|
12
9
|
def_delegators :connection, :get, :post, :put, :delete, :api_url, :setup_bucket, :signed_params
|
13
10
|
|
14
|
-
def configure(auth_params=nil)
|
15
|
-
@clouds = {}
|
11
|
+
def configure(auth_params=nil, &block)
|
16
12
|
|
17
|
-
if auth_params
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
if !auth_params
|
14
|
+
configure = Config.new
|
15
|
+
if (block.arity > 0)
|
16
|
+
block.call(configure)
|
17
|
+
else
|
18
|
+
configure.instance_eval(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
auth_params = configure.to_hash
|
22
|
+
elsif auth_params.is_a?(String)
|
23
|
+
auth_params = Config.new.parse_panda_url(auth_params)
|
21
24
|
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
configure_with_auth_params(auth_params)
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure_heroku
|
31
|
+
configure_with_auth_params Config.new.parse_panda_url(ENV['PANDASTREAM_URL'])
|
32
|
+
true
|
26
33
|
end
|
27
34
|
|
28
|
-
def connect!(auth_params
|
29
|
-
@connection = Connection.new(auth_params
|
35
|
+
def connect!(auth_params)
|
36
|
+
@connection = Connection.new(auth_params)
|
30
37
|
end
|
31
38
|
|
32
39
|
def connection
|
33
|
-
raise "
|
40
|
+
raise "Panda is not configured!" unless @connection
|
34
41
|
@connection
|
35
42
|
end
|
36
43
|
|
37
|
-
def
|
38
|
-
|
39
|
-
f.read.strip
|
40
|
-
}
|
44
|
+
def adapter=(klass)
|
45
|
+
@adapter_class = klass
|
41
46
|
end
|
42
47
|
|
48
|
+
def adapter
|
49
|
+
@adapter_class ||= default_adapter
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def default_adapter
|
55
|
+
Panda::Adapter::Faraday
|
56
|
+
end
|
57
|
+
|
58
|
+
def configure_with_auth_params(auth_params)
|
59
|
+
connect!(auth_params)
|
60
|
+
@clouds = {}
|
61
|
+
@cloud = Cloud::new(:id => @connection.cloud_id)
|
62
|
+
end
|
63
|
+
|
43
64
|
end
|
data/lib/panda/proxies/proxy.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Panda
|
2
2
|
class Proxy
|
3
3
|
include Panda::Router::ClassMethods
|
4
|
+
include Panda::Builders::ClassMethods
|
5
|
+
|
4
6
|
include Panda::Finders::FindMany
|
5
7
|
include Panda::Finders::FindOne
|
6
|
-
|
8
|
+
|
7
9
|
include Panda::CloudConnection
|
8
10
|
|
9
11
|
attr_accessor :parent, :klass
|
data/lib/panda/proxies/scope.rb
CHANGED
@@ -19,7 +19,7 @@ module Panda
|
|
19
19
|
initialize_scope_attributes
|
20
20
|
initialize_scopes
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# Overide the function to set the cloud_id as the same as the scope
|
24
24
|
def find_by_path(url, map={})
|
25
25
|
object = find_object_by_path(url, map)
|
@@ -29,7 +29,7 @@ module Panda
|
|
29
29
|
elsif object['id']
|
30
30
|
klass.new(object.merge('cloud_id' => cloud.id))
|
31
31
|
else
|
32
|
-
|
32
|
+
raise APIError.new(object)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,6 +38,11 @@ module Panda
|
|
38
38
|
super(scoped_attrs)
|
39
39
|
end
|
40
40
|
|
41
|
+
def create!(attributes)
|
42
|
+
scoped_attrs = attributes.merge(@scoped_attributes)
|
43
|
+
super(scoped_attrs)
|
44
|
+
end
|
45
|
+
|
41
46
|
def all(attributes={})
|
42
47
|
@scoped_attributes.merge!(attributes)
|
43
48
|
trigger_request
|
@@ -46,42 +51,43 @@ module Panda
|
|
46
51
|
def reload
|
47
52
|
@found = trigger_request
|
48
53
|
end
|
49
|
-
|
54
|
+
|
50
55
|
private
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
+
def initialize_scope_attributes
|
58
|
+
@scoped_attributes={}
|
59
|
+
if @parent.is_a?(Panda::Resource)
|
60
|
+
@scoped_attributes[parent_relation_name.to_sym] = @parent.id
|
57
61
|
end
|
62
|
+
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
def proxy_found
|
65
|
+
@found ||= trigger_request
|
66
|
+
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
68
|
+
def initialize_scopes
|
69
|
+
([].methods + [:to_json]).each do |m|
|
70
|
+
unless m.to_s =~ /^__/ || non_delegate_methods.include?(m.to_sym)
|
71
|
+
self.class.class_eval do
|
72
|
+
def_delegators :proxy_found, m.to_sym
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
76
|
+
end
|
72
77
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
find_by_path(path, @scoped_attributes)
|
78
|
+
def trigger_request
|
79
|
+
if @parent.is_a?(Resource)
|
80
|
+
path = build_hash_many_path(many_path, parent_relation_name)
|
81
|
+
else
|
82
|
+
path = many_path
|
81
83
|
end
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
find_by_path(path, @scoped_attributes)
|
86
|
+
end
|
87
|
+
|
88
|
+
def parent_relation_name
|
89
|
+
"#{@parent.class.sti_name.downcase}_id"
|
90
|
+
end
|
91
|
+
|
86
92
|
end
|
87
93
|
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
module Panda
|
2
2
|
class Cloud < Base
|
3
3
|
include Panda::Updatable
|
4
|
+
|
4
5
|
attr_reader :connection
|
5
6
|
|
6
7
|
def initialize(attributes={})
|
7
8
|
super(attributes)
|
8
|
-
connection_params = Panda.connection.to_hash.merge!(:cloud_id => id
|
9
|
+
connection_params = Panda.connection.to_hash.merge!(:cloud_id => id)
|
9
10
|
@connection = Connection.new(connection_params)
|
10
11
|
Panda.clouds[id] = self
|
11
12
|
end
|
12
13
|
|
13
14
|
class << self
|
14
|
-
include Panda::Finders::FindOne
|
15
|
-
|
16
|
-
def find(id, options=nil)
|
17
|
-
super(id)
|
18
|
-
end
|
19
15
|
|
20
16
|
def connection
|
21
17
|
Panda.connection
|
22
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_resource(attributes)
|
23
|
+
resource = Panda::Cloud.new(attributes)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def eu?
|
@@ -31,8 +33,8 @@ module Panda
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def region
|
34
|
-
return "eu" if connection.api_host == Panda::
|
35
|
-
return "us" if connection.api_host == Panda::
|
36
|
+
return "eu" if connection.api_host == Panda::EU_API_HOST
|
37
|
+
return "us" if connection.api_host == Panda::US_API_HOST
|
36
38
|
end
|
37
39
|
|
38
40
|
def videos
|
@@ -52,10 +54,10 @@ module Panda
|
|
52
54
|
super
|
53
55
|
end
|
54
56
|
|
55
|
-
private
|
56
|
-
|
57
|
+
private
|
58
|
+
|
57
59
|
def lazy_load
|
58
|
-
|
60
|
+
reload unless @loaded
|
59
61
|
end
|
60
62
|
|
61
63
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Panda
|
2
2
|
class Encoding < Resource
|
3
|
-
include
|
4
|
-
|
3
|
+
include VideoState
|
4
|
+
include Viewable
|
5
|
+
|
5
6
|
belongs_to :video
|
6
7
|
has_one :profile
|
7
8
|
|
@@ -11,23 +12,7 @@ module Panda
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
get_url("#{extname}")
|
16
|
-
end
|
17
|
-
|
18
|
-
def error_log
|
19
|
-
get_url(".log") if fail?
|
20
|
-
end
|
15
|
+
def screenshots_size; 7 end
|
21
16
|
|
22
|
-
def screenshots
|
23
|
-
((1..7).map{|i| get_url("_#{i}.jpg")} if success?) || []
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def get_url(end_path)
|
29
|
-
"#{cloud.url}#{path}#{end_path}"
|
30
|
-
end
|
31
|
-
|
32
17
|
end
|
33
18
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Panda
|
2
2
|
class Resource < Base
|
3
|
-
include Panda::
|
3
|
+
include Panda::Destroyers
|
4
4
|
include Panda::Associations
|
5
5
|
include Panda::CloudConnection
|
6
6
|
|
@@ -10,7 +10,6 @@ module Panda
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class << self
|
13
|
-
include Panda::Finders::FindMany
|
14
13
|
include Panda::CloudConnection
|
15
14
|
|
16
15
|
def cloud
|
@@ -33,20 +32,11 @@ module Panda
|
|
33
32
|
Panda.clouds[cloud_id]
|
34
33
|
end
|
35
34
|
|
36
|
-
def create
|
37
|
-
raise "Can't create attribute. Already have an id=#{attributes['id']}" if attributes['id']
|
38
|
-
response = connection.post(object_url_map(self.class.many_path), attributes)
|
39
|
-
load_response(response) ? (@changed_attributes = {}; true) : false
|
40
|
-
end
|
41
|
-
|
42
|
-
def create!
|
43
|
-
create || errors.last.raise!
|
44
|
-
end
|
45
|
-
|
46
35
|
def reload
|
47
36
|
perform_reload("cloud_id" => cloud_id)
|
48
37
|
reset_associations
|
49
38
|
self
|
50
39
|
end
|
40
|
+
|
51
41
|
end
|
52
42
|
end
|
data/panda.gemspec
CHANGED
@@ -1,112 +1,29 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "panda/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "panda"
|
7
|
+
s.version = Panda::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["New Bamboo"]
|
10
|
+
s.email = ["info@pandastream.com"]
|
11
|
+
s.homepage = "http://github.com/newbamboo/panda_gem"
|
12
|
+
s.summary = %q{Panda Client}
|
13
13
|
s.description = %q{Panda Client}
|
14
|
-
s.email = %q{info@pandastream.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"Gemfile",
|
21
|
-
"LICENSE",
|
22
|
-
"README.md",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/panda.rb",
|
26
|
-
"lib/panda/api_authentication.rb",
|
27
|
-
"lib/panda/base.rb",
|
28
|
-
"lib/panda/connection.rb",
|
29
|
-
"lib/panda/error.rb",
|
30
|
-
"lib/panda/modules/associations.rb",
|
31
|
-
"lib/panda/modules/builders.rb",
|
32
|
-
"lib/panda/modules/cloud_connection.rb",
|
33
|
-
"lib/panda/modules/finders.rb",
|
34
|
-
"lib/panda/modules/router.rb",
|
35
|
-
"lib/panda/modules/short_status.rb",
|
36
|
-
"lib/panda/modules/updatable.rb",
|
37
|
-
"lib/panda/panda.rb",
|
38
|
-
"lib/panda/proxies/encoding_scope.rb",
|
39
|
-
"lib/panda/proxies/profile_scope.rb",
|
40
|
-
"lib/panda/proxies/proxy.rb",
|
41
|
-
"lib/panda/proxies/scope.rb",
|
42
|
-
"lib/panda/proxies/video_scope.rb",
|
43
|
-
"lib/panda/resources/cloud.rb",
|
44
|
-
"lib/panda/resources/encoding.rb",
|
45
|
-
"lib/panda/resources/profile.rb",
|
46
|
-
"lib/panda/resources/resource.rb",
|
47
|
-
"lib/panda/resources/video.rb",
|
48
|
-
"panda.gemspec",
|
49
|
-
"spec/cloud_spec.rb",
|
50
|
-
"spec/encoding_spec.rb",
|
51
|
-
"spec/heroku_spec.rb",
|
52
|
-
"spec/panda_spec.rb",
|
53
|
-
"spec/profile_spec.rb",
|
54
|
-
"spec/spec.opts",
|
55
|
-
"spec/spec_helper.rb",
|
56
|
-
"spec/video_spec.rb"
|
57
|
-
]
|
58
|
-
s.homepage = %q{http://github.com/newbamboo/panda_gem}
|
59
|
-
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = %q{1.3.7}
|
61
|
-
s.summary = %q{Panda Client}
|
62
|
-
s.test_files = [
|
63
|
-
"spec/cloud_spec.rb",
|
64
|
-
"spec/encoding_spec.rb",
|
65
|
-
"spec/heroku_spec.rb",
|
66
|
-
"spec/panda_spec.rb",
|
67
|
-
"spec/profile_spec.rb",
|
68
|
-
"spec/spec_helper.rb",
|
69
|
-
"spec/video_spec.rb"
|
70
|
-
]
|
71
14
|
|
72
|
-
|
73
|
-
|
74
|
-
|
15
|
+
s.add_dependency "ruby-hmac", ">= 0.3.2"
|
16
|
+
s.add_dependency "yajl-ruby"
|
17
|
+
s.add_dependency "faraday"
|
75
18
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
s.add_development_dependency(%q<rake>, [">= 0"])
|
82
|
-
s.add_development_dependency(%q<rspec>, ["= 1.3.1"])
|
83
|
-
s.add_development_dependency(%q<webmock>, ["= 1.6.1"])
|
84
|
-
s.add_runtime_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
85
|
-
s.add_runtime_dependency(%q<rest-client>, [">= 1.4"])
|
86
|
-
s.add_runtime_dependency(%q<json>, [">= 1.2"])
|
87
|
-
else
|
88
|
-
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
89
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
90
|
-
s.add_dependency(%q<json>, [">= 0"])
|
91
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
92
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
93
|
-
s.add_dependency(%q<rspec>, ["= 1.3.1"])
|
94
|
-
s.add_dependency(%q<webmock>, ["= 1.6.1"])
|
95
|
-
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
96
|
-
s.add_dependency(%q<rest-client>, [">= 1.4"])
|
97
|
-
s.add_dependency(%q<json>, [">= 1.2"])
|
98
|
-
end
|
99
|
-
else
|
100
|
-
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
101
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
102
|
-
s.add_dependency(%q<json>, [">= 0"])
|
103
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
104
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
105
|
-
s.add_dependency(%q<rspec>, ["= 1.3.1"])
|
106
|
-
s.add_dependency(%q<webmock>, ["= 1.6.1"])
|
107
|
-
s.add_dependency(%q<ruby-hmac>, [">= 0.3.2"])
|
108
|
-
s.add_dependency(%q<rest-client>, [">= 1.4"])
|
109
|
-
s.add_dependency(%q<json>, [">= 1.2"])
|
110
|
-
end
|
111
|
-
end
|
19
|
+
s.add_development_dependency "timecop"
|
20
|
+
s.add_development_dependency "rspec", "2.4.0"
|
21
|
+
s.add_development_dependency "webmock"
|
22
|
+
|
23
|
+
s.rubyforge_project = "panda"
|
112
24
|
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|