kaltura_fu 0.1.3.prel → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,271 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class MetadataSpecTester
4
+ include KalturaFu::Entry::Metadata
5
+ end
6
+
7
+ class EntryUploader
8
+ include KalturaFu::Entry
9
+ end
10
+
11
+ describe "Actions on an entries metadata" do
12
+ before(:all) do
13
+ KalturaFuTestConfiguration.setup
14
+ end
15
+
16
+ before(:each) do
17
+ @entry_id = EntryUploader.upload(KalturaFuTestConfiguration.video,:source=>:file)
18
+ end
19
+
20
+ after(:each) do
21
+ EntryUploader.new.delete_entry(@entry_id)
22
+ end
23
+
24
+ it "should respond to getting valid entry attributes" do
25
+ test = MetadataSpecTester.new
26
+ test.should respond_to :get_name
27
+ end
28
+
29
+ it "should respond to getting valid entry attributes" do
30
+ test = MetadataSpecTester.new
31
+ test.should respond_to :get_description
32
+ end
33
+
34
+ it "should respond to getting valid entry attributes" do
35
+ test = MetadataSpecTester.new
36
+ test.should respond_to :get_categories
37
+ end
38
+
39
+ it "should respond to setting valid entry attributes" do
40
+ test = MetadataSpecTester.new
41
+ test.should respond_to :set_description
42
+ end
43
+
44
+ it "should respond to setting valid entry attributes" do
45
+ test = MetadataSpecTester.new
46
+ test.should respond_to :set_name
47
+ end
48
+
49
+ it "should respond to setting valid entry attributes" do
50
+ test = MetadataSpecTester.new
51
+ test.should respond_to :set_categories
52
+ end
53
+
54
+ it "should respond to adding valid entry attributes" do
55
+ test = MetadataSpecTester.new
56
+ test.should respond_to :add_category
57
+ end
58
+
59
+ it "should respond to adding valid entry attributes" do
60
+ test = MetadataSpecTester.new
61
+ test.should respond_to :add_categories
62
+ end
63
+
64
+ it "should respond to adding valid entry attributes" do
65
+ test = MetadataSpecTester.new
66
+ test.should respond_to :add_tag
67
+ end
68
+
69
+ it "should respond to adding valid entry attributes" do
70
+ test = MetadataSpecTester.new
71
+ test.should respond_to :add_tags
72
+ end
73
+
74
+ it "should respond to adding valid entry attributes" do
75
+ test = MetadataSpecTester.new
76
+ test.should respond_to :add_admin_tag
77
+ end
78
+
79
+ it "should respond to adding valid entry attributes" do
80
+ test = MetadataSpecTester.new
81
+ test.should respond_to :add_admin_tags
82
+ end
83
+
84
+ it "should not respond to getting invalid entry attributes" do
85
+ test = MetadataSpecTester.new
86
+ test.should_not respond_to :get_barack_obama
87
+ end
88
+
89
+ it "should not respond to setting invalid entry attributes" do
90
+ test = MetadataSpecTester.new
91
+ test.should_not respond_to :set_magic
92
+ end
93
+
94
+ it "should not respond to adding invalid entry attributes" do
95
+ test = MetadataSpecTester.new
96
+ test.should_not respond_to :add_waffles
97
+ end
98
+
99
+ it "should not respond to adding valid entry attributes, but improperly typed" do
100
+ test = MetadataSpecTester.new
101
+ test.should_not respond_to :add_name
102
+ end
103
+
104
+ it "should not respond to adding valid entry attributes, but improperly typed" do
105
+ test = MetadataSpecTester.new
106
+ test.should_not respond_to :add_names
107
+ end
108
+
109
+ it "should set the name field when asked kindly" do
110
+ test = MetadataSpecTester.new
111
+ test.set_name(@entry_id,"waffles").should == "waffles"
112
+ end
113
+
114
+ it "should set the desription field when asked kindly" do
115
+ test = MetadataSpecTester.new
116
+ test.set_description(@entry_id,"The beginning of the end of the beginning").should == "The beginning of the end of the beginning"
117
+ end
118
+
119
+ it "should be a little weirder when setting a group of tags" do
120
+ test = MetadataSpecTester.new
121
+ test.set_tags(@entry_id,"waffles,awesome,rock,hard").should == "waffles, awesome, rock, hard"
122
+ test.get_tags(@entry_id).should == "waffles, awesome, rock, hard"
123
+ end
124
+
125
+ it "should just be weird with tags, admin tags don't act this way either" do
126
+ test = MetadataSpecTester.new
127
+ test.set_admin_tags(@entry_id,"waffles,awesome,rock,hard").should == "waffles,awesome,rock,hard"
128
+ test.get_admin_tags(@entry_id).should == "waffles,awesome,rock,hard"
129
+ end
130
+
131
+ it "shouldn't act like tags with categories" do
132
+ test = MetadataSpecTester.new
133
+ test.set_categories(@entry_id,"waffles,awesome,rock,hard").should == "waffles,awesome,rock,hard"
134
+ end
135
+
136
+ it "should raise a Kaltura::APIError when you give it a bogus entry" do
137
+ test = MetadataSpecTester.new
138
+
139
+ lambda {test.set_name("waffles","waffles")}.should raise_error(Kaltura::APIError)
140
+ end
141
+
142
+ it "should not increment the version when you perform set actions" do
143
+ test = MetadataSpecTester.new
144
+
145
+ version_count = test.get_version(@entry_id).to_i
146
+
147
+ test.set_name(@entry_id,"my new name")
148
+ test.get_version(@entry_id).to_i.should == version_count
149
+ end
150
+
151
+ it "should not increment the version when you perform set actions on tags" do
152
+ test = MetadataSpecTester.new
153
+
154
+ version_count = test.get_version(@entry_id).to_i
155
+
156
+ test.set_tags(@entry_id,"buttons,kittens,pirates")
157
+ test.get_version(@entry_id).to_i.should == version_count
158
+ end
159
+
160
+ it "should be making KMC categories for every category you set unless it already exists." do
161
+ test = MetadataSpecTester.new
162
+
163
+ categories = "waffles#{rand(10)},pirates#{rand(18)},peanuts#{rand(44)}"
164
+ categories.split(",").each do |category|
165
+ test.category_exists?(category).should be_false
166
+ end
167
+
168
+ test.set_categories(@entry_id,categories)
169
+
170
+ categories.split(",").each do |category|
171
+ cat = test.category_exists?(category)
172
+ cat.should_not be_false
173
+ end
174
+
175
+ bob = KalturaFu.client.category_service.list.objects
176
+ bob.each do |cat|
177
+ if cat.name =~/^(waffles|pirates|peanuts)(.*)/
178
+ KalturaFu.client.category_service.delete(cat.id)
179
+ end
180
+ end
181
+
182
+ end
183
+
184
+ it "should allow you to add tags onto an existing tag string without knowing the original tags" do
185
+ test = MetadataSpecTester.new
186
+
187
+ original_tags = test.set_tags(@entry_id,"gorillaz, pop, damon, albarn")
188
+
189
+ test.add_tags(@entry_id,"mos,def").should == original_tags + ", mos, def"
190
+ end
191
+
192
+ it "should let you add a single tag too, syntax sugar is rad." do
193
+ test = MetadataSpecTester.new
194
+
195
+ original_tags = test.set_tags(@entry_id,"gorillaz, pop, damon, albarn")
196
+
197
+ test.add_tag(@entry_id,"mos").should == original_tags + ", mos"
198
+ end
199
+
200
+ it "should allow you to add admin tags onto an existing tag string without knowing the original tags" do
201
+ test = MetadataSpecTester.new
202
+
203
+ original_tags = test.set_admin_tags(@entry_id,"gorillaz,pop,damon,albarn")
204
+
205
+ test.add_admin_tags(@entry_id,"mos,def").should == original_tags + ",mos,def"
206
+ end
207
+
208
+ it "should let you add a single admin tag too, syntax sugar is rad." do
209
+ test = MetadataSpecTester.new
210
+
211
+ original_tags = test.set_admin_tags(@entry_id,"gorillaz, pop, damon, albarn")
212
+
213
+ test.add_admin_tag(@entry_id,"mos").should == original_tags + ",mos"
214
+ end
215
+
216
+ it "should let you add categories onto an existing category string as well." do
217
+ test = MetadataSpecTester.new
218
+
219
+ original_categories = test.set_categories(@entry_id,"peanuts#{rand(10)}")
220
+
221
+ new_cats = "pirates#{rand(10)},waffles#{rand(10)}"
222
+ test.add_categories(@entry_id,new_cats).should == original_categories + ",#{new_cats}"
223
+ check_string = original_categories + ",#{new_cats}"
224
+ check_string.split(",").each do |category|
225
+ cat = test.category_exists?(category)
226
+ cat.should_not be_false
227
+ end
228
+ bob = KalturaFu.client.category_service.list.objects
229
+ bob.each do |cat|
230
+ if cat.name =~/^(waffles|pirates|peanuts)(.*)/
231
+ KalturaFu.client.category_service.delete(cat.id)
232
+ end
233
+ end
234
+ end
235
+
236
+ it "should create categories for each one you add if they don't exist." do
237
+ test = MetadataSpecTester.new
238
+
239
+ original_categories = test.set_categories(@entry_id,"peanuts#{rand(10)}")
240
+
241
+ new_cats = "pirates#{rand(10)},waffles#{rand(10)}"
242
+ test.add_categories(@entry_id,new_cats)
243
+ check_string = original_categories + ",#{new_cats}"
244
+ check_string.split(",").each do |category|
245
+ cat = test.category_exists?(category)
246
+ cat.should_not be_false
247
+ end
248
+ bob = KalturaFu.client.category_service.list.objects
249
+ bob.each do |cat|
250
+ if cat.name =~/^(waffles|pirates|peanuts)(.*)/
251
+ KalturaFu.client.category_service.delete(cat.id)
252
+ end
253
+ end
254
+ end
255
+
256
+ it "should let you add categories onto an existing category string as well." do
257
+ test = MetadataSpecTester.new
258
+
259
+ original_categories = test.set_categories(@entry_id,"peanuts#{rand(10)},pirates#{rand(10)}")
260
+
261
+ new_cat = "waffles#{rand(10)}"
262
+ test.add_category(@entry_id,new_cat).should == original_categories + ",#{new_cat}"
263
+
264
+ bob = KalturaFu.client.category_service.list.objects
265
+ bob.each do |cat|
266
+ if cat.name =~/^(waffles|pirates|peanuts)(.*)/
267
+ KalturaFu.client.category_service.delete(cat.id)
268
+ end
269
+ end
270
+ end
271
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,28 @@
1
- begin
2
- require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
3
- rescue LoadError
4
- puts "You need to install rspec in your base app"
5
- exit
6
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'kaltura_fu'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'rubygems'
7
+ require 'kaltura'
8
+ require 'yaml'
9
+ require 'active_support'
7
10
 
8
- plugin_spec_dir = File.dirname(__FILE__)
9
- ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
11
+ Spec::Runner.configure do |config|
12
+
13
+ end
10
14
 
15
+ class KalturaFuTestConfiguration
16
+ def self.setup
17
+ kaltura_yml = File.join(File.dirname(__FILE__),'config','kaltura.yml')
18
+ KalturaFu.config = YAML.load_file(kaltura_yml).symbolize_keys
19
+
20
+ #remove any lingering and possibly incorrect client information
21
+ KalturaFu.client = nil
22
+ KalturaFu.client_configuration = nil
23
+ end
24
+
25
+ def self.video
26
+ File.open(File.join(File.dirname(__FILE__),'config','video.flv'))
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaltura_fu
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1876988255
5
- prerelease: true
4
+ hash: 29
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 3
10
- - prel
11
- version: 0.1.3.prel
10
+ version: 0.1.3
12
11
  platform: ruby
13
12
  authors:
14
13
  - Patrick Robertson
@@ -16,13 +15,29 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-10-12 00:00:00 -04:00
18
+ date: 2010-11-01 00:00:00 -04:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: velir_kaltura-ruby
22
+ name: rspec
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: velir_kaltura-ruby
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
26
41
  none: false
27
42
  requirements:
28
43
  - - ">="
@@ -34,7 +49,7 @@ dependencies:
34
49
  - 3
35
50
  version: 0.4.3
36
51
  type: :runtime
37
- version_requirements: *id001
52
+ version_requirements: *id002
38
53
  description:
39
54
  email: patrick.robertson@velir.com
40
55
  executables: []
@@ -55,16 +70,23 @@ files:
55
70
  - install.rb
56
71
  - kaltura_fu.gemspec
57
72
  - lib/kaltura_fu.rb
58
- - lib/kaltura_fu/category.rb
73
+ - lib/kaltura_fu/configuration.rb
74
+ - lib/kaltura_fu/entry.rb
75
+ - lib/kaltura_fu/entry/class_methods.rb
76
+ - lib/kaltura_fu/entry/instance_methods.rb
77
+ - lib/kaltura_fu/entry/metadata.rb
78
+ - lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb
79
+ - lib/kaltura_fu/flavor.rb
59
80
  - lib/kaltura_fu/railtie.rb
60
81
  - lib/kaltura_fu/report.rb
61
82
  - lib/kaltura_fu/video.rb
62
83
  - lib/kaltura_fu/view_helpers.rb
63
84
  - rails/init.rb
85
+ - spec/entry_spec.rb
64
86
  - spec/kaltura_fu_spec.rb
87
+ - spec/metadata_spec.rb
88
+ - spec/spec.opts
65
89
  - spec/spec_helper.rb
66
- - test/kaltura_fu_test.rb
67
- - test/test_helper.rb
68
90
  - uninstall.rb
69
91
  has_rdoc: true
70
92
  homepage: http://github.com/Velir/kaltura_fu
@@ -87,14 +109,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
109
  required_rubygems_version: !ruby/object:Gem::Requirement
88
110
  none: false
89
111
  requirements:
90
- - - ">"
112
+ - - ">="
91
113
  - !ruby/object:Gem::Version
92
- hash: 25
114
+ hash: 3
93
115
  segments:
94
- - 1
95
- - 3
96
- - 1
97
- version: 1.3.1
116
+ - 0
117
+ version: "0"
98
118
  requirements: []
99
119
 
100
120
  rubyforge_project:
@@ -103,7 +123,7 @@ signing_key:
103
123
  specification_version: 3
104
124
  summary: Rails gem for making Kaltura integrations easier.
105
125
  test_files:
126
+ - spec/entry_spec.rb
106
127
  - spec/kaltura_fu_spec.rb
128
+ - spec/metadata_spec.rb
107
129
  - spec/spec_helper.rb
108
- - test/kaltura_fu_test.rb
109
- - test/test_helper.rb
@@ -1,112 +0,0 @@
1
- module KalturaFu
2
-
3
- ##
4
- # The Category module provides class methods to add/append category metadata to Kaltura entries.
5
- #
6
- # @author Patrick Robertson
7
- #
8
- # @example Create a new Category Filter on the Kaltura Management Console:
9
- # create_category('waffles')
10
- #
11
- # @example Append a Category to the end of the Entries metadata list:
12
- # add_category_to_video('1_xw34a324','pancakes')
13
- #
14
- # @example Append a Category and make sure it is a KMC filter if it doesn't exist:
15
- # add_category_to_video('1_wx34a324','pancakes',true)
16
- #
17
- # @example Set the Category metadata to a specific category and overriding the existing values:
18
- # set_category('1_wx34a324','Ninja Pancake Assasin')
19
- ##
20
- module Category
21
- include KalturaFu::Video
22
- ##
23
- # Appends a category to the Kaltura entry. It is capable of adding the category to the Kaltura server
24
- # if it doesn't already exist. This method will not override existing categories, instead it appends the new
25
- # category to the end of the list.
26
- #
27
- # @param [String] video_id Kaltura entry_id of the video.
28
- # @param [String] category The category to add to the Kaltura entry.
29
- # @param [Boolean] force_add true/false flag to force adding the category to the Kaltura server if it doesn't already
30
- # exist. Defaults to false.
31
- #
32
- # @return [Kaltura::MediaEntry] Returns the entry updated with the new category appended.
33
- ##
34
- def add_category_to_video(video_id,category,force_add=false)
35
- KalturaFu.check_for_client_session
36
-
37
- existing_category = category_exists?(category)
38
- if force_add && !existing_category
39
- self.create_category(category)
40
- elsif !force_add && !existing_category
41
- raise "Category: #{category} does not exist. Either use the force add flag or manually add the category."
42
- end
43
-
44
- video = get_video_info(video_id)
45
- updated_entry = Kaltura::MediaEntry.new
46
- if video.categories.nil?
47
- updated_categories = category
48
- else
49
- updated_categories = video.categories + "," + category
50
- end
51
- updated_entry.categories = updated_categories
52
- KalturaFu.client.media_service.update(video_id,updated_entry)
53
- end
54
-
55
- ##
56
- # Creates a category on the Kaltura server if it doesn't already exist.
57
- #
58
- # @param [String] category_name category you wish to add.
59
- ##
60
- def create_category(category_name)
61
- KalturaFu.check_for_client_session
62
-
63
- existing_category = self.category_exists?(category_name)
64
- unless existing_category
65
- category = Kaltura::Category.new
66
- category.name = category_name
67
- KalturaFu.client.category_service.add(category)
68
- else
69
- existing_category
70
- end
71
- end
72
-
73
- ##
74
- # Sets the Kaltura entry metadata to the desired category. It will overwrite existing categories.
75
- #
76
- # @param [String] video_id Kaltura entry_id of the video.
77
- # @param [String] category The category to add to the Kaltura entry.
78
- #
79
- # @return [Boolean] Returns true if the entry was updated, otherwise false.
80
- ##
81
- def set_category(video_id,category)
82
- KalturaFu.check_for_client_session
83
-
84
- if video_exists?(video_id)
85
- updated_entry = Kaltura::MediaEntry.new
86
- updated_entry.categories = category
87
- KalturaFu.client.media_service.update(video_id,updated_entry)
88
- true
89
- else
90
- false
91
- end
92
- end
93
-
94
- protected
95
-
96
- ##
97
- # @private
98
- ##
99
- def category_exists?(category_name)
100
- KalturaFu.check_for_client_session
101
-
102
- category_filter = Kaltura::Filter::CategoryFilter.new
103
- category_filter.full_name_equal = category_name
104
- category_check = KalturaFu.client.category_service.list(category_filter).objects
105
- if category_check.nil?
106
- false
107
- else
108
- category_check
109
- end
110
- end
111
- end
112
- end