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.
Files changed (72) hide show
  1. data/Rakefile +3 -3
  2. data/VERSION.yml +1 -1
  3. data/lib/core_ext/hash.rb +13 -1
  4. data/lib/core_ext/object.rb +15 -0
  5. data/lib/core_ext/string.rb +11 -0
  6. data/lib/sdk_connection_harness.rb +25 -11
  7. data/lib/videojuicer.rb +13 -9
  8. data/lib/videojuicer/asset/audio.rb +5 -4
  9. data/lib/videojuicer/asset/base.rb +30 -15
  10. data/lib/videojuicer/asset/flash.rb +8 -0
  11. data/lib/videojuicer/asset/image.rb +2 -2
  12. data/lib/videojuicer/asset/video.rb +12 -9
  13. data/lib/videojuicer/campaign.rb +10 -1
  14. data/lib/videojuicer/campaign_policy.rb +116 -0
  15. data/lib/videojuicer/criterion/base.rb +56 -0
  16. data/lib/videojuicer/criterion/date_range.rb +7 -17
  17. data/lib/videojuicer/criterion/geolocation.rb +11 -20
  18. data/lib/videojuicer/criterion/request.rb +8 -17
  19. data/lib/videojuicer/criterion/time.rb +8 -18
  20. data/lib/videojuicer/criterion/week_day.rb +13 -17
  21. data/lib/videojuicer/oauth/request_proxy.rb +19 -13
  22. data/lib/videojuicer/presentation.rb +6 -0
  23. data/lib/videojuicer/promo/base.rb +72 -0
  24. data/lib/videojuicer/resource/base.rb +17 -15
  25. data/lib/videojuicer/resource/embeddable.rb +30 -0
  26. data/lib/videojuicer/resource/inferrable.rb +67 -7
  27. data/lib/videojuicer/resource/property_registry.rb +19 -0
  28. data/lib/videojuicer/resource/relationships/belongs_to.rb +2 -1
  29. data/lib/videojuicer/resource/types.rb +28 -0
  30. data/spec/assets/audio_spec.rb +24 -0
  31. data/spec/assets/flash_spec.rb +24 -0
  32. data/spec/assets/image_spec.rb +24 -0
  33. data/spec/assets/text_spec.rb +24 -0
  34. data/spec/assets/video_spec.rb +24 -0
  35. data/spec/campaign_policy_spec.rb +41 -0
  36. data/spec/campaign_spec.rb +0 -12
  37. data/spec/criterion/date_range_spec.rb +24 -0
  38. data/spec/criterion/geolocation_spec.rb +23 -0
  39. data/spec/criterion/request_spec.rb +23 -0
  40. data/spec/criterion/time_spec.rb +23 -0
  41. data/spec/criterion/week_day_spec.rb +23 -0
  42. data/spec/files/flash.swf +0 -0
  43. data/spec/helpers/be_equal_to.rb +26 -0
  44. data/spec/helpers/spec_fixtures.rb +214 -0
  45. data/spec/helpers/spec_helper.rb +27 -25
  46. data/spec/presentation_spec.rb +2 -15
  47. data/spec/promos/audio_spec.rb +23 -0
  48. data/spec/promos/image_spec.rb +24 -0
  49. data/spec/promos/text_spec.rb +23 -0
  50. data/spec/promos/video_spec.rb +23 -0
  51. data/spec/request_proxy_spec.rb +8 -12
  52. data/spec/session_spec.rb +3 -1
  53. data/spec/shared/dependent_spec.rb +40 -0
  54. data/spec/shared/embeddable_spec.rb +34 -0
  55. data/spec/shared/model_spec.rb +74 -0
  56. data/spec/shared/resource_spec.rb +12 -41
  57. data/spec/spec.opts +1 -1
  58. data/spec/user_spec.rb +5 -27
  59. data/tasks/vj-core.rb +3 -2
  60. data/vj-sdk.gemspec +56 -24
  61. metadata +53 -23
  62. data/lib/videojuicer/criterion/affiliate.rb +0 -21
  63. data/lib/videojuicer/criterion/embed.rb +0 -12
  64. data/spec/audio_spec.rb +0 -45
  65. data/spec/criteria/date_range_spec.rb +0 -37
  66. data/spec/criteria/geolocation_spec.rb +0 -38
  67. data/spec/criteria/request_spec.rb +0 -36
  68. data/spec/criteria/time_spec.rb +0 -37
  69. data/spec/criteria/week_day_spec.rb +0 -39
  70. data/spec/image_spec.rb +0 -44
  71. data/spec/text_spec.rb +0 -42
  72. data/spec/video_spec.rb +0 -50
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Promo::Image do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Promo::Image
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/image"
18
+ end
19
+
20
+ it_should_behave_like "a dependent non-resource object"
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), "..", "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Promo::Text do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Promo::Text
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/text"
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::Promo::Video do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Promo::Video
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/video"
18
+ end
19
+
20
+ it_should_behave_like "a dependent non-resource object"
21
+ end
22
+
23
+ end
@@ -2,7 +2,9 @@ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
2
 
3
3
  describe Videojuicer::OAuth::RequestProxy do
4
4
 
5
- before(:each) { configure_test_settings }
5
+ before(:each) do
6
+ configure_test_settings
7
+ end
6
8
 
7
9
  describe "instantiation" do
8
10
  before(:all) do
@@ -29,12 +31,9 @@ describe Videojuicer::OAuth::RequestProxy do
29
31
  end
30
32
  it "can sort complex nested parameter hashes correctly" do
31
33
  @proxy.normalize_params(:a=>"1", :b=>"2", :c=>{:a=>"AAA", :b=>"BBB", :c=>"CCC"}, :d=>{:e=>"foo"}).should == "a=1&b=2&c%5Ba%5D=AAA&c%5Bb%5D=BBB&c%5Bc%5D=CCC&d%5Be%5D=foo"
32
- end
33
-
34
- it "does not include binary file parameters in the signature"
35
-
34
+ end
36
35
  it "escapes the signature base string elements and adjoins them with an ampersand" do
37
- @proxy.signature_base_string(:get, "/test", :foo=>"bar", :bar=>"baz").should == "GET&#{CGI.escape "http://localhost/test"}&#{CGI.escape "bar=baz&foo=bar"}"
36
+ @proxy.signature_base_string(:get, "/test", :foo=>"bar", :bar=>"baz").should == "GET&#{CGI.rfc3986_escape "http://localhost/test"}&#{CGI.rfc3986_escape "bar=baz&foo=bar"}"
38
37
  end
39
38
 
40
39
  describe "with no token supplied" do
@@ -77,18 +76,15 @@ describe Videojuicer::OAuth::RequestProxy do
77
76
  describe "request factory" do
78
77
  before(:all) do
79
78
  @seed = fixtures.seed
80
- @fixtures = fixtures["write-master"]
81
- @proxy = Videojuicer::OAuth::RequestProxy.new(:seed_name=>@seed.name, :consumer_key=>@fixtures.consumer.consumer_key, :consumer_secret=>@fixtures.consumer.consumer_secret, :token=>nil, :token_secret=>nil)
79
+ @fix = fixtures["write-master"]
80
+ @proxy = Videojuicer::OAuth::RequestProxy.new(:seed_name=>@seed.name, :consumer_key=>@fix.consumer.consumer_key, :consumer_secret=>@fix.consumer.consumer_secret, :token=>nil, :token_secret=>nil)
82
81
  end
83
82
 
84
83
  it "can successfully retrieve a request token (indicating a successful signature verification)" do
85
- @proxy.consumer_key.should == @fixtures.consumer.consumer_key
84
+ @proxy.consumer_key.should == @fix.consumer.consumer_key
86
85
  response = @proxy.get("/oauth/tokens")
87
86
  response.body.should =~ /oauth_token=[a-zA-Z0-9]+&oauth_token_secret=[a-zA-Z0-9]+/
88
87
  end
89
-
90
- it "throws an exception when given a 401 return status"
91
- it "throws an exception when given a 406 return status"
92
88
  end
93
89
 
94
90
  end
@@ -8,7 +8,9 @@ describe Videojuicer::Session do
8
8
  @session = Videojuicer::Session.new(
9
9
  :seed_name => fixtures.seed.name,
10
10
  :consumer_key => fixtures["write-master"].consumer.consumer_key,
11
- :consumer_secret => fixtures["write-master"].consumer.consumer_secret
11
+ :consumer_secret => fixtures["write-master"].consumer.consumer_secret,
12
+ :token => nil,
13
+ :token_secret => nil
12
14
  )
13
15
  end
14
16
 
@@ -0,0 +1,40 @@
1
+ shared_examples_for "a dependent non-resource object" do
2
+
3
+ =begin
4
+ Dependent objects are non-resource objects that are typically members of a collection that is an attribute of a resource object.
5
+
6
+ Rather than a classic has_many/belongs_to relationship between RESTful objects, these objects are expressed as properties on the parent object -
7
+ they are *dependent* and unable to exist on their own.
8
+
9
+ In the SDK, helper classes for dependent objects are provided to allow creation and validation, but they do not allow dependent objects to be
10
+ saved as first-order objects. Instead, a parent object must be given the dependent object to add to its collection attribute.
11
+
12
+ This model currently applies to Criteria and Promo objects.
13
+
14
+ Expects @klass to be a reference to the model class being tested
15
+ Expects @parent to be a valid object ready to have objects of type @klass added to it.
16
+ Expects @singular_name to be a string containing the expected resource name, e.g. Videojuicer::User => "user"
17
+ Expects @plural_name to be a string containing the expected pluralised name, e.g. Videojuicer::User => "users"
18
+ Expects @good_attributes to be a hash of attributes for objects of the tested type that will successfully create a valid object.
19
+ =end
20
+
21
+ it_should_behave_like "a model"
22
+
23
+ it "has no get class method" do
24
+ lambda {@klass.get(9)}.should raise_error(NoMethodError)
25
+ end
26
+ it "has no all class method" do
27
+ lambda {@klass.all}.should raise_error(NoMethodError)
28
+ end
29
+ it "has no first class method" do
30
+ lambda {@klass.first}.should raise_error(NoMethodError)
31
+ end
32
+ it "has no save instance method" do
33
+ lambda {@klass.new.save}.should raise_error(NoMethodError)
34
+ end
35
+ it "has no destroy instance method" do
36
+ lambda {@klass.new.destroy}.should raise_error(NoMethodError)
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,34 @@
1
+ shared_examples_for "an embeddable" do
2
+
3
+ # Requires same variables to be set as the shared resource spec.
4
+
5
+ before(:all) do
6
+ @record = @klass.gen
7
+ @record.save.should be_true
8
+ end
9
+
10
+ describe "getting the oembed payload" do
11
+ before(:all) do
12
+ @oembed_payload = @record.oembed_payload(700, 700)
13
+ end
14
+
15
+ it "should be parsed from JSON" do
16
+ @oembed_payload.should be_kind_of(Hash)
17
+ end
18
+
19
+ it "should have the embed source" do
20
+ @oembed_payload["html"].should_not be_blank
21
+ end
22
+ end
23
+
24
+ describe "getting the embed code" do
25
+ before(:all) do
26
+ @src = @record.embed_code(700, 700)
27
+ end
28
+
29
+ it "should be populated" do
30
+ @src.should_not be_blank
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,74 @@
1
+ shared_examples_for "a model" do
2
+
3
+ =begin
4
+
5
+ vj-sdk model classes, whether for first-order resources or for dependent objects, offer a suite of common functionality
6
+
7
+ this test covers those methods.
8
+
9
+ =end
10
+
11
+ # Expects @klass to be a reference to the model class being tested
12
+ # Expects @singular_name to be a string containing the expected resource name, e.g. Videojuicer::User => "user"
13
+ # Expects @plural_name to be a string containing the expected pluralised name, e.g. Videojuicer::User => "users"
14
+ # Expects @good_attributes to be a hash of attributes for objects of the tested type that will successfully create a valid object.
15
+
16
+ describe "a new record" do
17
+ before(:each) do
18
+ @record = @klass.new
19
+ end
20
+
21
+ it "returns true to #new_record?" do
22
+ @record.new_record?.should be_true
23
+ end
24
+
25
+ it "raises an exception when trying to pull attributes remotely" do
26
+ lambda {@record.reload}.should raise_error(Videojuicer::Exceptions::NoResource)
27
+ end
28
+
29
+ it "returns false to #valid?" do
30
+ @record.valid?.should be_false
31
+ end
32
+ end
33
+
34
+ describe "inferrable naming" do
35
+ before(:all) do
36
+ class ::Nester
37
+ include Videojuicer::Resource::Inferrable
38
+
39
+ class Nested
40
+ include Videojuicer::Resource::Inferrable
41
+
42
+ class Leaf
43
+ include Videojuicer::Resource::Inferrable
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ it "has a resource name that matches the singular class name" do
50
+ @klass.resource_name.should == @singular_name
51
+ end
52
+ it "has a parameter name inferred from the resource name" do
53
+ @klass.parameter_name.should == @singular_name
54
+ end
55
+ it "has a resource path that properly pluralises the resource name" do
56
+ @klass.resource_route.should =~ /\/#{@plural_name}/
57
+ end
58
+
59
+ it "ascertains the containing class" do
60
+ ::Nester.containing_class.should be_nil
61
+ ::Nester::Nested.containing_class.should == ::Nester
62
+ ::Nester::Nested::Leaf.containing_class.should == ::Nester::Nested
63
+ end
64
+
65
+ it "builds a nested route" do
66
+ ::Nester::Nested::Leaf.resource_route.should == "/nesters/:nester_id/nesteds/:nested_id/leafs"
67
+ end
68
+
69
+ it "compiles a route" do
70
+ ::Nester.compile_route("/foo/bar/:foo/:bar/foo", :foo=>"OMG", :bar=>"ROFLMAO").should == "/foo/bar/OMG/ROFLMAO/foo"
71
+ end
72
+ end
73
+
74
+ end
@@ -5,43 +5,21 @@ shared_examples_for "a RESTFUL resource model" do
5
5
  # Expects @plural_name to be a string containing the expected pluralised name, e.g. Videojuicer::User => "users"
6
6
  # Expects @good_attributes to be a hash of attributes for objects of the tested type that will successfully create a valid object.
7
7
 
8
- describe "inferrable naming" do
9
- it "has a resource name that matches the singular class name" do
10
- @klass.resource_name.should == @singular_name
11
- end
12
- it "has a parameter name inferred from the resource name" do
13
- @klass.parameter_name.should == @singular_name
14
- end
15
- it "has a resource path that properly pluralises the resource name" do
16
- @klass.resource_path.should == "/#{@plural_name}"
17
- end
8
+ it_should_behave_like "a model"
9
+
10
+ before(:all) do
11
+ @fixed_attributes ||= []
18
12
  end
19
13
 
20
14
  describe "a new record" do
21
15
  before(:each) do
22
16
  @record = @klass.new
23
17
  end
24
-
25
- it "returns true to #new_record?" do
26
- @record.new_record?.should be_true
27
- end
28
-
29
- it "uses the class resource path as the instance resource path" do
30
- @record.resource_path.should == @klass.resource_path
31
- end
32
-
33
- it "raises an exception when trying to pull attributes remotely" do
34
- lambda {@record.reload}.should raise_error(Videojuicer::Exceptions::NoResource)
35
- end
36
-
37
- it "returns false to #valid?" do
38
- @record.valid?.should be_false
39
- end
40
-
18
+
41
19
  describe "being saved" do
42
20
  describe "successfully" do
43
21
  before(:all) do
44
- @successful = @klass.new(@good_attributes)
22
+ @successful = @klass.gen
45
23
  raise @successful.errors.inspect unless @successful.valid?
46
24
  @successful.valid?.should be_true
47
25
  @saved = @successful.save
@@ -59,8 +37,8 @@ shared_examples_for "a RESTFUL resource model" do
59
37
  end
60
38
  describe "unsuccessfully" do
61
39
  before(:all) do
62
- @bad_attributes = @good_attributes.inject({}) do |memo, (key,value)|
63
- memo.merge({key=>""})
40
+ @bad_attributes = @klass.gen_attributes.inject({}) do |memo, (key,value)|
41
+ memo.merge({key=>(@fixed_attributes.include?(key)? value : "")})
64
42
  end
65
43
  @fail = @klass.new(@bad_attributes)
66
44
  @saved = @fail.save
@@ -86,8 +64,7 @@ shared_examples_for "a RESTFUL resource model" do
86
64
 
87
65
  describe "finding a record by ID" do
88
66
  before(:all) do
89
- @random_attributes ||= cycle_attributes(@good_attributes)
90
- @record = @klass.new(@random_attributes)
67
+ @record = @klass.gen
91
68
  @record.save.should be_true
92
69
  @found = @klass.get(@record.id)
93
70
  end
@@ -126,14 +103,9 @@ shared_examples_for "a RESTFUL resource model" do
126
103
  end
127
104
  end
128
105
 
129
- describe "finding a record by conditions" do
130
- it "should translate a conditions hash to filterable format"
131
- end
132
-
133
106
  describe "an existing record" do
134
107
  before(:all) do
135
- @random_attributes ||= cycle_attributes(@good_attributes)
136
- @record = @klass.new(@random_attributes)
108
+ @record = @klass.gen
137
109
  @record.save.should be_true
138
110
  end
139
111
 
@@ -142,7 +114,7 @@ shared_examples_for "a RESTFUL resource model" do
142
114
  end
143
115
 
144
116
  it "uses an instance-specific resource path" do
145
- @record.resource_path.should == "/#{@plural_name}/#{@record.id}.json"
117
+ @record.resource_path.should =~ /\/#{@plural_name}\/#{@record.id}\.json$/
146
118
  end
147
119
 
148
120
  it "reloads from the remote API successfully" do
@@ -158,8 +130,7 @@ shared_examples_for "a RESTFUL resource model" do
158
130
 
159
131
  describe "deleting a record" do
160
132
  before(:each) do
161
- @random_attributes ||= cycle_attributes(@good_attributes)
162
- @record = @klass.new(@random_attributes)
133
+ @record = @klass.gen
163
134
  @record.save.should be_true
164
135
  end
165
136
 
@@ -1,3 +1,3 @@
1
- --colour
1
+ --color
2
2
  --format
3
3
  specdoc
@@ -5,15 +5,6 @@ describe Videojuicer::User do
5
5
  before(:all) do
6
6
  @klass = Videojuicer::User
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
- end
14
-
15
- after(:all) do
16
- Videojuicer.exit_scope
17
8
  end
18
9
 
19
10
  describe "instantiation" do
@@ -24,13 +15,6 @@ describe Videojuicer::User do
24
15
  before(:all) do
25
16
  @singular_name = "user"
26
17
  @plural_name = "users"
27
- @good_attributes = {
28
- :login => "testuser#{rand 99999}",
29
- :name => "#{rand 9999} Jones",
30
- :email => "test#{rand 999999}@test.videojuicer.com",
31
- :password => "#{p = rand(99999)}",
32
- :password_confirmation => p
33
- }
34
18
  end
35
19
 
36
20
  it_should_behave_like "a RESTFUL resource model"
@@ -38,26 +22,20 @@ describe Videojuicer::User do
38
22
 
39
23
  describe "authentication" do
40
24
  before(:all) do
41
- @good_attributes = {
42
- :login => "testuser#{rand 99999}",
43
- :name => "#{rand 9999} Jones",
44
- :email => "test#{rand 999999}@test.videojuicer.com",
45
- :password => "#{p = rand(99999)}",
46
- :password_confirmation => p
47
- }
48
- @auth_user = Videojuicer::User.new(@good_attributes)
25
+ @attrs = Videojuicer::User.gen_attributes
26
+ @auth_user = Videojuicer::User.new(@attrs)
49
27
  @auth_user.save.should be_true
50
28
  end
51
29
 
52
30
 
53
31
  it "returns User with good credentials" do
54
- u = Videojuicer::User.authenticate(@good_attributes[:login], @good_attributes[:password])
32
+ u = Videojuicer::User.authenticate(@attrs[:login], @attrs[:password])
55
33
  u.should be_kind_of(Videojuicer::User)
56
- u.login.should == @good_attributes[:login]
34
+ u.login.should == @attrs[:login]
57
35
  end
58
36
 
59
37
  it "returns nil with bad credentials" do
60
- Videojuicer::User.authenticate(@good_attributes[:login], "FOOOOBARRRRRR").should be_nil
38
+ Videojuicer::User.authenticate(@attrs[:login], "FOOOOBARRRRRR").should be_nil
61
39
  end
62
40
  end
63
41