telestream_cloud 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +357 -0
- data/Rakefile +9 -0
- data/lib/telestream_cloud.rb +30 -0
- data/lib/telestream_cloud/api_authentication.rb +66 -0
- data/lib/telestream_cloud/base.rb +111 -0
- data/lib/telestream_cloud/config.rb +87 -0
- data/lib/telestream_cloud/connection.rb +101 -0
- data/lib/telestream_cloud/errors.rb +17 -0
- data/lib/telestream_cloud/faraday.rb +84 -0
- data/lib/telestream_cloud/flip.rb +9 -0
- data/lib/telestream_cloud/modules/associations.rb +55 -0
- data/lib/telestream_cloud/modules/builders.rb +45 -0
- data/lib/telestream_cloud/modules/destroyers.rb +25 -0
- data/lib/telestream_cloud/modules/factory_connection.rb +7 -0
- data/lib/telestream_cloud/modules/finders.rb +68 -0
- data/lib/telestream_cloud/modules/router.rb +62 -0
- data/lib/telestream_cloud/modules/updatable.rb +31 -0
- data/lib/telestream_cloud/modules/video_state.rb +16 -0
- data/lib/telestream_cloud/proxies/encoding_scope.rb +56 -0
- data/lib/telestream_cloud/proxies/profile_scope.rb +7 -0
- data/lib/telestream_cloud/proxies/proxy.rb +27 -0
- data/lib/telestream_cloud/proxies/scope.rb +94 -0
- data/lib/telestream_cloud/proxies/video_scope.rb +28 -0
- data/lib/telestream_cloud/resources/encoding.rb +47 -0
- data/lib/telestream_cloud/resources/factory.rb +72 -0
- data/lib/telestream_cloud/resources/profile.rb +22 -0
- data/lib/telestream_cloud/resources/resource.rb +48 -0
- data/lib/telestream_cloud/resources/video.rb +39 -0
- data/lib/telestream_cloud/telestream_cloud.rb +69 -0
- data/lib/telestream_cloud/upload_session.rb +102 -0
- data/lib/telestream_cloud/version.rb +3 -0
- data/spec/cloud_spec.rb +132 -0
- data/spec/encoding_spec.rb +260 -0
- data/spec/heroku_spec.rb +32 -0
- data/spec/panda_spec.rb +206 -0
- data/spec/profile_spec.rb +117 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/video_spec.rb +399 -0
- data/telestream_cloud.gemspec +30 -0
- metadata +191 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Associations
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def has_one(relation_name)
|
10
|
+
# for example creates : @video ||= VideoScope.new(self)
|
11
|
+
|
12
|
+
define_method relation_name do
|
13
|
+
param_id = "#{relation_name}_id"
|
14
|
+
if instance_var = instance_variable_get("@#{relation_name}")
|
15
|
+
instance_var
|
16
|
+
else
|
17
|
+
@associations ||= []
|
18
|
+
@associations << relation_name
|
19
|
+
instance_variable_set("@#{relation_name}",
|
20
|
+
TelestreamCloud::const_get(relation_name.to_s.capitalize).find(send(param_id.to_sym)))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_many(relation_name)
|
26
|
+
# for example creates : @encodings ||= EncodingScope.new(self)
|
27
|
+
|
28
|
+
define_method relation_name do
|
29
|
+
model_name = "#{relation_name.to_s[0..-2].capitalize}"
|
30
|
+
if instance_var = instance_variable_get("@#{relation_name}")
|
31
|
+
instance_var
|
32
|
+
else
|
33
|
+
@associations ||= []
|
34
|
+
@associations << relation_name
|
35
|
+
instance_variable_set("@#{relation_name}",
|
36
|
+
TelestreamCloud::const_get("#{model_name}Scope").new(self))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias :belongs_to :has_one
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def reset_associations
|
47
|
+
if @associations
|
48
|
+
@associations.each do |a|
|
49
|
+
instance_variable_set("@#{a}",nil)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Builders
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def create(attributes={})
|
11
|
+
resource = build_resource(attributes)
|
12
|
+
yield resource if block_given?
|
13
|
+
|
14
|
+
resource.create
|
15
|
+
resource
|
16
|
+
end
|
17
|
+
|
18
|
+
def create!(attributes={})
|
19
|
+
resource = build_resource(attributes)
|
20
|
+
yield resource if block_given?
|
21
|
+
|
22
|
+
resource.create!
|
23
|
+
resource
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_resource(attributes)
|
29
|
+
TelestreamCloud::const_get("#{sti_name}").new(attributes.merge('factory_id' => factory.id))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
raise "Can't create attribute. Already have an id=#{attributes['id']}" if attributes['id']
|
35
|
+
uri = replace_pattern_with_self_variables(self.class.many_path)
|
36
|
+
response = connection.post(uri, attributes)
|
37
|
+
load_and_reset(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create!
|
41
|
+
create || raise(errors.last)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Destroyers
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def delete(id)
|
11
|
+
uri = create_rest_url(one_path,{:id =>id})
|
12
|
+
response = connection.delete(uri)
|
13
|
+
!!response['deleted']
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete
|
19
|
+
uri = replace_pattern_with_self_variables(self.class.one_path)
|
20
|
+
response = connection.delete(uri)
|
21
|
+
!!response['deleted']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Finders
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(FindOne)
|
6
|
+
base.extend(FindMany)
|
7
|
+
end
|
8
|
+
|
9
|
+
module FindOne
|
10
|
+
|
11
|
+
def find(id)
|
12
|
+
raise 'find method requires a correct value' if id.nil? || id == ''
|
13
|
+
find_by_path(one_path, {:id => id})
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_object_by_path(url, map={})
|
17
|
+
rest_url = create_rest_url(url, map)
|
18
|
+
params = extract_unmapped_variables(url, map)
|
19
|
+
connection.get(rest_url, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_by_path(url, map={})
|
23
|
+
object = find_object_by_path(url, map)
|
24
|
+
kclass = TelestreamCloud::const_get("#{sti_name}")
|
25
|
+
|
26
|
+
if object.is_a?(Array)
|
27
|
+
object.map{|o| kclass.new(o)}
|
28
|
+
elsif object['id']
|
29
|
+
kclass.new(object)
|
30
|
+
else
|
31
|
+
raise APIError.new(object)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
module FindMany
|
38
|
+
|
39
|
+
def find_by(map)
|
40
|
+
all(map).first
|
41
|
+
end
|
42
|
+
|
43
|
+
def all(map={})
|
44
|
+
find_by_path(many_path, map)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def find_all_by_has_many(relation_name, relation_value)
|
50
|
+
map = {}
|
51
|
+
map[relation_name.to_sym] = relation_value
|
52
|
+
has_many_path = build_hash_many_path(many_path, relation_name)
|
53
|
+
find_by_path(has_many_path, map)
|
54
|
+
end
|
55
|
+
|
56
|
+
def method_missing(method_symbol, *arguments)
|
57
|
+
method_name = method_symbol.to_s
|
58
|
+
if method_name =~ /^find_all_by_([_a-zA-Z]\w*)$/
|
59
|
+
find_all_by_has_many($1, arguments.pop)
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Router
|
3
|
+
VAR_PATTERN = /:\w+/
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def resource_path
|
12
|
+
@url || "/#{sti_name.downcase}s"
|
13
|
+
end
|
14
|
+
|
15
|
+
def match(url)
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
def many_path
|
20
|
+
resource_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def one_path
|
24
|
+
resource_path + "/:id"
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_hash_many_path(end_path, relation_attr)
|
28
|
+
relation_class_name = relation_attr[0..relation_attr.rindex("_id")-1].capitalize
|
29
|
+
prefix_path = TelestreamCloud::const_get(relation_class_name).resource_path + "/:" + relation_attr
|
30
|
+
prefix_path + end_path
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_rest_url(url, map)
|
34
|
+
new_url = replace_pattern_with_variables(url, map)
|
35
|
+
json_path(new_url).gsub('factorys', 'factories')
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def replace_pattern_with_variables(url, map)
|
41
|
+
new_url = url.clone
|
42
|
+
new_url.gsub(VAR_PATTERN){|key| map[key[1..-1].to_sym] || map[key[1..-1].to_s]}
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_unmapped_variables(url, map)
|
46
|
+
params = map.clone
|
47
|
+
url.scan(VAR_PATTERN).map{|key| params.reject!{|k,v| k==key[1..-1] } }
|
48
|
+
params
|
49
|
+
end
|
50
|
+
|
51
|
+
def json_path(uri)
|
52
|
+
uri + ".json"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def replace_pattern_with_self_variables(url)
|
57
|
+
self.class.create_rest_url(url, attributes)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
module Updatable
|
3
|
+
|
4
|
+
def save
|
5
|
+
new? ? create : update
|
6
|
+
end
|
7
|
+
|
8
|
+
def save!
|
9
|
+
save || raise(errors.last)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_attribute(name, value)
|
13
|
+
send("#{name}=".to_sym, value) && save
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_attributes(attributes)
|
17
|
+
load(attributes) && save
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_attributes!(attributes)
|
21
|
+
update_attributes(attributes) || raise(errors.last)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
uri = replace_pattern_with_self_variables(self.class.one_path)
|
26
|
+
response = connection.put(uri, @changed_attributes)
|
27
|
+
load_and_reset(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
class EncodingScope < Scope
|
3
|
+
|
4
|
+
def initialize(parent)
|
5
|
+
super(parent, Encoding)
|
6
|
+
end
|
7
|
+
|
8
|
+
def non_delegate_methods
|
9
|
+
super + [:status, :profile_id, :profile_name, :video, :page, :per_page, :[]]
|
10
|
+
end
|
11
|
+
|
12
|
+
def page(this_page)
|
13
|
+
@scoped_attributes[:page] = this_page
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def per_page(this_per_page)
|
18
|
+
@scoped_attributes[:per_page] = this_per_page
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def video(this_video_id)
|
23
|
+
@scoped_attributes[:video_id] = this_video_id
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def status(this_status)
|
28
|
+
@scoped_attributes[:status] = this_status
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def profile(this_profile_id)
|
33
|
+
@scoped_attributes[:profile_id] = this_profile_id
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def profile_name(this_profile_name)
|
38
|
+
@scoped_attributes[:profile_name] = this_profile_name
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_by_profile_name(this_profile_name)
|
43
|
+
@scoped_attributes[:profile_name] = this_profile_name
|
44
|
+
trigger_request.first
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](index)
|
48
|
+
if(index.is_a? String)
|
49
|
+
proxy_found.select{|e| e.profile_name == index}[0]
|
50
|
+
else
|
51
|
+
proxy_found[index]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TelestreamCloud
|
2
|
+
class Proxy
|
3
|
+
include TelestreamCloud::Router::ClassMethods
|
4
|
+
include TelestreamCloud::Builders::ClassMethods
|
5
|
+
|
6
|
+
include TelestreamCloud::Finders::FindMany
|
7
|
+
include TelestreamCloud::Finders::FindOne
|
8
|
+
|
9
|
+
include TelestreamCloud::FactoryConnection
|
10
|
+
|
11
|
+
attr_accessor :parent, :klass
|
12
|
+
|
13
|
+
def initialize(parent, klass)
|
14
|
+
@parent = parent
|
15
|
+
@klass = klass
|
16
|
+
end
|
17
|
+
|
18
|
+
def factory
|
19
|
+
@parent.is_a?(Factory) ? @parent : @parent.factory
|
20
|
+
end
|
21
|
+
|
22
|
+
def sti_name
|
23
|
+
klass.sti_name
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module TelestreamCloud
|
4
|
+
class Scope < Proxy
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def respond_to?(method)
|
8
|
+
scoped_methods = [].methods.map{|i| i.to_sym} - non_delegate_methods + [:reload, :non_delegate_methods]
|
9
|
+
!(scoped_methods).include?(method.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
def non_delegate_methods
|
13
|
+
[:nil?, :send, :object_id, :respond_to?, :class, :find, :find_by, :create, :create!, :all, :factory, :connection]
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(parent, klass)
|
17
|
+
super
|
18
|
+
|
19
|
+
initialize_scope_attributes
|
20
|
+
initialize_scopes
|
21
|
+
end
|
22
|
+
|
23
|
+
# Overide the function to set the factory_id as the same as the scope
|
24
|
+
def find_by_path(url, map={})
|
25
|
+
object = find_object_by_path(url, map)
|
26
|
+
|
27
|
+
if object.is_a?(Array)
|
28
|
+
object.map{|o| klass.new(o.merge('factory_id' => factory.id))}
|
29
|
+
elsif object['id']
|
30
|
+
klass.new(object.merge('factory_id' => factory.id))
|
31
|
+
else
|
32
|
+
raise APIError.new(object)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create(attributes)
|
37
|
+
scoped_attrs = attributes.merge(@scoped_attributes)
|
38
|
+
super(scoped_attrs)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create!(attributes)
|
42
|
+
scoped_attrs = attributes.merge(@scoped_attributes)
|
43
|
+
super(scoped_attrs)
|
44
|
+
end
|
45
|
+
|
46
|
+
def all(attributes={})
|
47
|
+
@scoped_attributes.merge!(attributes)
|
48
|
+
trigger_request
|
49
|
+
end
|
50
|
+
|
51
|
+
def reload
|
52
|
+
@found = trigger_request
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def initialize_scope_attributes
|
58
|
+
@scoped_attributes={}
|
59
|
+
if @parent.is_a?(TelestreamCloud::Resource)
|
60
|
+
@scoped_attributes[parent_relation_name.to_sym] = @parent.id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def proxy_found
|
65
|
+
@found ||= trigger_request
|
66
|
+
end
|
67
|
+
|
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
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
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
|
83
|
+
end
|
84
|
+
|
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
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|