videojuicer-vj-sdk 0.1.5 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/VERSION.yml +1 -1
- data/lib/core_ext/hash.rb +13 -1
- data/lib/core_ext/object.rb +15 -0
- data/lib/core_ext/string.rb +11 -0
- data/lib/sdk_connection_harness.rb +25 -11
- data/lib/videojuicer.rb +13 -9
- data/lib/videojuicer/asset/audio.rb +5 -4
- data/lib/videojuicer/asset/base.rb +30 -15
- data/lib/videojuicer/asset/flash.rb +8 -0
- data/lib/videojuicer/asset/image.rb +2 -2
- data/lib/videojuicer/asset/video.rb +12 -9
- data/lib/videojuicer/campaign.rb +10 -1
- data/lib/videojuicer/campaign_policy.rb +116 -0
- data/lib/videojuicer/criterion/base.rb +56 -0
- data/lib/videojuicer/criterion/date_range.rb +7 -17
- data/lib/videojuicer/criterion/geolocation.rb +11 -20
- data/lib/videojuicer/criterion/request.rb +8 -17
- data/lib/videojuicer/criterion/time.rb +8 -18
- data/lib/videojuicer/criterion/week_day.rb +13 -17
- data/lib/videojuicer/oauth/request_proxy.rb +19 -13
- data/lib/videojuicer/presentation.rb +6 -0
- data/lib/videojuicer/promo/base.rb +72 -0
- data/lib/videojuicer/resource/base.rb +17 -15
- data/lib/videojuicer/resource/embeddable.rb +30 -0
- data/lib/videojuicer/resource/inferrable.rb +67 -7
- data/lib/videojuicer/resource/property_registry.rb +19 -0
- data/lib/videojuicer/resource/relationships/belongs_to.rb +2 -1
- data/lib/videojuicer/resource/types.rb +28 -0
- data/spec/assets/audio_spec.rb +24 -0
- data/spec/assets/flash_spec.rb +24 -0
- data/spec/assets/image_spec.rb +24 -0
- data/spec/assets/text_spec.rb +24 -0
- data/spec/assets/video_spec.rb +24 -0
- data/spec/campaign_policy_spec.rb +41 -0
- data/spec/campaign_spec.rb +0 -12
- data/spec/criterion/date_range_spec.rb +24 -0
- data/spec/criterion/geolocation_spec.rb +23 -0
- data/spec/criterion/request_spec.rb +23 -0
- data/spec/criterion/time_spec.rb +23 -0
- data/spec/criterion/week_day_spec.rb +23 -0
- data/spec/files/flash.swf +0 -0
- data/spec/helpers/be_equal_to.rb +26 -0
- data/spec/helpers/spec_fixtures.rb +214 -0
- data/spec/helpers/spec_helper.rb +27 -25
- data/spec/presentation_spec.rb +2 -15
- data/spec/promos/audio_spec.rb +23 -0
- data/spec/promos/image_spec.rb +24 -0
- data/spec/promos/text_spec.rb +23 -0
- data/spec/promos/video_spec.rb +23 -0
- data/spec/request_proxy_spec.rb +8 -12
- data/spec/session_spec.rb +3 -1
- data/spec/shared/dependent_spec.rb +40 -0
- data/spec/shared/embeddable_spec.rb +34 -0
- data/spec/shared/model_spec.rb +74 -0
- data/spec/shared/resource_spec.rb +12 -41
- data/spec/spec.opts +1 -1
- data/spec/user_spec.rb +5 -27
- data/tasks/vj-core.rb +3 -2
- data/vj-sdk.gemspec +56 -24
- metadata +53 -23
- data/lib/videojuicer/criterion/affiliate.rb +0 -21
- data/lib/videojuicer/criterion/embed.rb +0 -12
- data/spec/audio_spec.rb +0 -45
- data/spec/criteria/date_range_spec.rb +0 -37
- data/spec/criteria/geolocation_spec.rb +0 -38
- data/spec/criteria/request_spec.rb +0 -36
- data/spec/criteria/time_spec.rb +0 -37
- data/spec/criteria/week_day_spec.rb +0 -39
- data/spec/image_spec.rb +0 -44
- data/spec/text_spec.rb +0 -42
- data/spec/video_spec.rb +0 -50
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Criterion::Request do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Criterion::Request
|
7
|
+
configure_test_settings
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "instantiation" do
|
11
|
+
it_should_behave_like "a configurable"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general interface:" do
|
15
|
+
before(:all) do
|
16
|
+
@singular_name = "criterion"
|
17
|
+
@plural_name = "criteria/request"
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like "a dependent non-resource object"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Criterion::Time do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Criterion::Time
|
7
|
+
configure_test_settings
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "instantiation" do
|
11
|
+
it_should_behave_like "a configurable"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general interface:" do
|
15
|
+
before(:all) do
|
16
|
+
@singular_name = "criterion"
|
17
|
+
@plural_name = "criteria/time"
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like "a dependent non-resource object"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Criterion::WeekDay do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Criterion::WeekDay
|
7
|
+
configure_test_settings
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "instantiation" do
|
11
|
+
it_should_behave_like "a configurable"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general interface:" do
|
15
|
+
before(:all) do
|
16
|
+
@singular_name = "criterion"
|
17
|
+
@plural_name = "criteria/week_day"
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like "a dependent non-resource object"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class BeEqualTo
|
2
|
+
def initialize(expectation)
|
3
|
+
@expectation = expectation
|
4
|
+
end
|
5
|
+
|
6
|
+
def matches?(instance)
|
7
|
+
@instance = instance
|
8
|
+
return @instance == @expectation
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
"be equal to #{@expectation}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
" expected to be equal to #{@expectation}, but was not, and had the following errors:\n #{@instance}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def negative_failure_message
|
20
|
+
" expected to not be valid, but was. (Are you missing a validation?)"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def be_equal_to(expectation)
|
25
|
+
BeEqualTo.new(expectation)
|
26
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
SDK Fixtures
|
3
|
+
|
4
|
+
Here is a fixture helper. It helps you generate good attributes for use in your
|
5
|
+
test instances.
|
6
|
+
=end
|
7
|
+
|
8
|
+
module Videojuicer
|
9
|
+
|
10
|
+
module FixtureHelper
|
11
|
+
def self.included(base)
|
12
|
+
base.send(:include, InstanceMethods)
|
13
|
+
base.send(:extend, ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def gen(fixture=:default, overrides={})
|
18
|
+
fixture, overrides = :default, fixture if fixture.is_a?(Hash)
|
19
|
+
create(gen_attributes(fixture).merge(overrides))
|
20
|
+
end
|
21
|
+
|
22
|
+
def gen_attributes(fixture=:default)
|
23
|
+
attribute_proc(fixture).call
|
24
|
+
end
|
25
|
+
def blank_attributes(fixture=:default)
|
26
|
+
gen_attributes(fixture).inject({}) do |memo, (key, value)|
|
27
|
+
memo.update(key => " ")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def attribute_proc(fixture=:default)
|
31
|
+
@attribute_procs[fixture]
|
32
|
+
end
|
33
|
+
def set_attribute_proc(fixture=:default, &block)
|
34
|
+
@attribute_procs ||= {}
|
35
|
+
@attribute_procs[fixture] = block
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module InstanceMethods
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class User
|
45
|
+
include FixtureHelper
|
46
|
+
set_attribute_proc {{
|
47
|
+
:login => /testuser(\d{1,5})/.gen,
|
48
|
+
:name => /(\d{1,5}) Jones/.gen,
|
49
|
+
:email => /test(\d{1,5}+)@test\.videojuicer\.com/.gen,
|
50
|
+
:password => "#{p = rand(99999)}",
|
51
|
+
:password_confirmation => p
|
52
|
+
}}
|
53
|
+
end
|
54
|
+
|
55
|
+
class Presentation
|
56
|
+
include FixtureHelper
|
57
|
+
set_attribute_proc {{
|
58
|
+
:title=>/Presentation title (\d{1,5})/.gen,
|
59
|
+
:abstract=>/Presentation abstract (\d{1,5})/.gen,
|
60
|
+
:author=>"Bob Anon"
|
61
|
+
}}
|
62
|
+
end
|
63
|
+
|
64
|
+
class Campaign
|
65
|
+
include FixtureHelper
|
66
|
+
set_attribute_proc {{
|
67
|
+
:name => /\w+/.gen
|
68
|
+
}}
|
69
|
+
end
|
70
|
+
|
71
|
+
class Campaign::CampaignPolicy
|
72
|
+
include FixtureHelper
|
73
|
+
set_attribute_proc {{
|
74
|
+
:campaign_id => Campaign.gen.id,
|
75
|
+
:presentation_id => (Presentation.first.id rescue Presentation.gen.id)
|
76
|
+
}}
|
77
|
+
end
|
78
|
+
|
79
|
+
class Criterion::DateRange
|
80
|
+
include FixtureHelper
|
81
|
+
set_attribute_proc {{
|
82
|
+
:until => DateTime.send(:today) + 1,
|
83
|
+
:from => DateTime.send(:today) - 1
|
84
|
+
}}
|
85
|
+
end
|
86
|
+
|
87
|
+
class Criterion::Geolocation
|
88
|
+
include FixtureHelper
|
89
|
+
set_attribute_proc {{
|
90
|
+
:city => "Columbus",
|
91
|
+
:region => "OH",
|
92
|
+
:country => "United States"
|
93
|
+
}}
|
94
|
+
end
|
95
|
+
|
96
|
+
class Criterion::Request
|
97
|
+
include FixtureHelper
|
98
|
+
set_attribute_proc {{
|
99
|
+
:referrer => "http://www.google.com"
|
100
|
+
}}
|
101
|
+
end
|
102
|
+
|
103
|
+
class Criterion::Time
|
104
|
+
include FixtureHelper
|
105
|
+
set_attribute_proc {{
|
106
|
+
:from => (Time.now - 3600).strftime("%H:%M"),
|
107
|
+
:until => (Time.now + 3600).strftime("%H:%M")
|
108
|
+
}}
|
109
|
+
end
|
110
|
+
|
111
|
+
class Criterion::WeekDay
|
112
|
+
include FixtureHelper
|
113
|
+
set_attribute_proc {{
|
114
|
+
:monday => true
|
115
|
+
}}
|
116
|
+
end
|
117
|
+
|
118
|
+
class Promo::Image
|
119
|
+
include FixtureHelper
|
120
|
+
set_attribute_proc {{
|
121
|
+
:role => "Thumbnail",
|
122
|
+
:href => "http://www.videojuicer.com",
|
123
|
+
:asset_id => 1
|
124
|
+
}}
|
125
|
+
end
|
126
|
+
|
127
|
+
class Promo::Audio
|
128
|
+
include FixtureHelper
|
129
|
+
set_attribute_proc {{
|
130
|
+
:role => "Voice Over",
|
131
|
+
:href => "http://www.videojuicer.com",
|
132
|
+
:asset_id => 1
|
133
|
+
}}
|
134
|
+
end
|
135
|
+
|
136
|
+
class Promo::Video
|
137
|
+
include FixtureHelper
|
138
|
+
set_attribute_proc {{
|
139
|
+
:role => "preroll",
|
140
|
+
:href => "http://www.videojuicer.com",
|
141
|
+
:asset_id => 1
|
142
|
+
}}
|
143
|
+
end
|
144
|
+
|
145
|
+
class Promo::Text
|
146
|
+
include FixtureHelper
|
147
|
+
set_attribute_proc {{
|
148
|
+
:role => "Description",
|
149
|
+
:href => "http://www.videojuicer.com",
|
150
|
+
:asset_id => 1
|
151
|
+
}}
|
152
|
+
end
|
153
|
+
|
154
|
+
class Asset::Audio
|
155
|
+
include FixtureHelper
|
156
|
+
set_attribute_proc {{
|
157
|
+
:user_id => rand(100) + 1,
|
158
|
+
:licensed_at => Time.now,
|
159
|
+
:licensed_by => "foo, bar",
|
160
|
+
:licensed_under => "CC BY:NC:SA",
|
161
|
+
:published_at => Time.now,
|
162
|
+
:file => File.open(File.join(File.dirname(__FILE__), "..", "files", "audio.mp3"))
|
163
|
+
}}
|
164
|
+
end
|
165
|
+
|
166
|
+
class Asset::Image
|
167
|
+
include FixtureHelper
|
168
|
+
set_attribute_proc {{
|
169
|
+
:user_id => rand(100) + 1,
|
170
|
+
:licensed_at => Time.now,
|
171
|
+
:licensed_by => "foo, bar",
|
172
|
+
:licensed_under => "CC BY:NC:SA",
|
173
|
+
:published_at => Time.now,
|
174
|
+
:file => File.open(File.join(File.dirname(__FILE__), "..", "files", "image.jpg"))
|
175
|
+
}}
|
176
|
+
end
|
177
|
+
|
178
|
+
class Asset::Flash
|
179
|
+
include FixtureHelper
|
180
|
+
set_attribute_proc {{
|
181
|
+
:user_id => rand(100) + 1,
|
182
|
+
:licensed_at => Time.now,
|
183
|
+
:licensed_by => "foo, bar",
|
184
|
+
:licensed_under => "CC BY:NC:SA",
|
185
|
+
:published_at => Time.now,
|
186
|
+
:file => File.open(File.join(File.dirname(__FILE__), "..", "files", "flash.swf"))
|
187
|
+
}}
|
188
|
+
end
|
189
|
+
|
190
|
+
class Asset::Text
|
191
|
+
include FixtureHelper
|
192
|
+
set_attribute_proc {{
|
193
|
+
:user_id => rand(100) + 1,
|
194
|
+
:licensed_at => Time.now,
|
195
|
+
:licensed_by => "foo, bar",
|
196
|
+
:licensed_under => "CC BY:NC:SA",
|
197
|
+
:published_at => Time.now,
|
198
|
+
:file => File.open(File.join(File.dirname(__FILE__), "..", "files", "text.txt"))
|
199
|
+
}}
|
200
|
+
end
|
201
|
+
|
202
|
+
class Asset::Video
|
203
|
+
include FixtureHelper
|
204
|
+
set_attribute_proc {{
|
205
|
+
:user_id => rand(100) + 1,
|
206
|
+
:licensed_at => Time.now,
|
207
|
+
:licensed_by => "foo, bar",
|
208
|
+
:licensed_under => "CC BY:NC:SA",
|
209
|
+
:published_at => Time.now,
|
210
|
+
:file => File.open(File.join(File.dirname(__FILE__), "..", "files", "video.mov"))
|
211
|
+
}}
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
data/spec/helpers/spec_helper.rb
CHANGED
@@ -1,46 +1,48 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spec'
|
3
|
-
require 'mash'
|
4
3
|
require 'yaml'
|
5
|
-
require File.join(File.dirname(__FILE__), "..", "..", "lib", "videojuicer")
|
6
4
|
|
5
|
+
unless defined?(Mash)
|
6
|
+
# Don't require Mash twice. It causes cranial trauma.
|
7
|
+
require 'mash'
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'randexp'
|
12
|
+
rescue LoadError
|
13
|
+
raise "The Randexp gem is required in order to run the test suites, but it is not required to use the SDK in production environments. To run the tests, please `sudo gem install randexp`"
|
14
|
+
end
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), "..", "..", "lib", "videojuicer")
|
7
17
|
require File.join(File.dirname(__FILE__), "..", "shared", "configurable_spec")
|
18
|
+
require File.join(File.dirname(__FILE__), "..", "shared", "model_spec")
|
8
19
|
require File.join(File.dirname(__FILE__), "..", "shared", "resource_spec")
|
20
|
+
require File.join(File.dirname(__FILE__), "..", "shared", "embeddable_spec")
|
21
|
+
require File.join(File.dirname(__FILE__), "..", "shared", "dependent_spec")
|
22
|
+
|
23
|
+
# Load the fixture helper
|
24
|
+
require File.join(File.dirname(__FILE__), "spec_fixtures")
|
9
25
|
|
10
26
|
module SpecHelper
|
11
27
|
|
12
28
|
def configure_test_settings(overrides={})
|
13
29
|
Videojuicer.configure!({
|
14
|
-
:consumer_key => nil,
|
15
|
-
:consumer_secret => nil,
|
16
30
|
:api_version => 1,
|
17
31
|
:protocol => "http",
|
18
32
|
:host => "localhost",
|
19
|
-
:port =>
|
33
|
+
:port => 6666,
|
34
|
+
:consumer_key => fixtures["write-master"]["consumer"]["consumer_key"],
|
35
|
+
:consumer_secret => fixtures["write-master"]["consumer"]["consumer_secret"],
|
36
|
+
:token => fixtures["write-master"]["authorized_token"]["oauth_token"],
|
37
|
+
:token_secret => fixtures["write-master"]["authorized_token"]["oauth_token_secret"],
|
38
|
+
:seed_name => fixtures["seed"]["name"]
|
20
39
|
}.merge(overrides))
|
21
40
|
end
|
22
41
|
|
23
42
|
def fixtures
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def cycle_attributes(attrs)
|
28
|
-
r = rand(99999)
|
29
|
-
attrs.inject({}) do |memo, (key, value)|
|
30
|
-
memo.merge({
|
31
|
-
key => if value.respond_to?(:read)
|
32
|
-
value
|
33
|
-
elsif value.is_a?(Date) or value.is_a?(DateTime) or value.is_a?(Time)
|
34
|
-
value
|
35
|
-
else
|
36
|
-
value.to_s.gsub(/\d+/, r.to_s)
|
37
|
-
end
|
38
|
-
})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def strip_files(attrs)
|
43
|
-
|
43
|
+
fixture_path = File.join(File.dirname(__FILE__), "..", "..", "core-fixtures.yml")
|
44
|
+
fixture_src = File.open(fixture_path).read
|
45
|
+
@core_fixtures ||= Mash.new(YAML.load(fixture_src))
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
data/spec/presentation_spec.rb
CHANGED
@@ -5,17 +5,8 @@ describe Videojuicer::Presentation do
|
|
5
5
|
before(:all) do
|
6
6
|
@klass = Videojuicer::Presentation
|
7
7
|
configure_test_settings
|
8
|
-
Videojuicer.enter_scope :seed_name => fixtures.seed.name,
|
9
|
-
:consumer_key=>fixtures["write-master"].consumer.consumer_key,
|
10
|
-
:consumer_secret=>fixtures["write-master"].consumer.consumer_secret,
|
11
|
-
:token=>fixtures["write-master"].authorized_token.oauth_token,
|
12
|
-
:token_secret=>fixtures["write-master"].authorized_token.oauth_token_secret
|
13
8
|
end
|
14
|
-
|
15
|
-
after(:all) do
|
16
|
-
Videojuicer.exit_scope
|
17
|
-
end
|
18
|
-
|
9
|
+
|
19
10
|
describe "instantiation" do
|
20
11
|
it_should_behave_like "a configurable"
|
21
12
|
end
|
@@ -24,14 +15,10 @@ describe Videojuicer::Presentation do
|
|
24
15
|
before(:all) do
|
25
16
|
@singular_name = "presentation"
|
26
17
|
@plural_name = "presentations"
|
27
|
-
@good_attributes = {
|
28
|
-
:title=>"Presentation title #{rand 99999}",
|
29
|
-
:abstract=>"Presentation abstract #{rand 99999}",
|
30
|
-
:author=>"Bob Anon"
|
31
|
-
}
|
32
18
|
end
|
33
19
|
|
34
20
|
it_should_behave_like "a RESTFUL resource model"
|
21
|
+
it_should_behave_like "an embeddable"
|
35
22
|
end
|
36
23
|
|
37
24
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
|
2
|
+
|
3
|
+
describe Videojuicer::Promo::Audio do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@klass = Videojuicer::Promo::Audio
|
7
|
+
configure_test_settings
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "instantiation" do
|
11
|
+
it_should_behave_like "a configurable"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general interface:" do
|
15
|
+
before(:all) do
|
16
|
+
@singular_name = "promo"
|
17
|
+
@plural_name = "promos/audio"
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like "a dependent non-resource object"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|