vj-sdk 0.2.1

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.
Files changed (88) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +0 -0
  4. data/README.rdoc +7 -0
  5. data/Rakefile +70 -0
  6. data/VERSION.yml +4 -0
  7. data/lib/core_ext/cgi.rb +12 -0
  8. data/lib/core_ext/hash.rb +52 -0
  9. data/lib/core_ext/object.rb +15 -0
  10. data/lib/core_ext/string.rb +11 -0
  11. data/lib/sdk_connection_harness.rb +101 -0
  12. data/lib/videojuicer/asset/audio.rb +13 -0
  13. data/lib/videojuicer/asset/base.rb +80 -0
  14. data/lib/videojuicer/asset/flash.rb +8 -0
  15. data/lib/videojuicer/asset/image.rb +10 -0
  16. data/lib/videojuicer/asset/text.rb +8 -0
  17. data/lib/videojuicer/asset/video.rb +22 -0
  18. data/lib/videojuicer/campaign.rb +19 -0
  19. data/lib/videojuicer/campaign_policy.rb +116 -0
  20. data/lib/videojuicer/criterion/base.rb +56 -0
  21. data/lib/videojuicer/criterion/date_range.rb +15 -0
  22. data/lib/videojuicer/criterion/geolocation.rb +18 -0
  23. data/lib/videojuicer/criterion/request.rb +15 -0
  24. data/lib/videojuicer/criterion/time.rb +15 -0
  25. data/lib/videojuicer/criterion/week_day.rb +20 -0
  26. data/lib/videojuicer/oauth/multipart_helper.rb +96 -0
  27. data/lib/videojuicer/oauth/proxy_factory.rb +18 -0
  28. data/lib/videojuicer/oauth/request_proxy.rb +280 -0
  29. data/lib/videojuicer/presentation.rb +38 -0
  30. data/lib/videojuicer/preset.rb +29 -0
  31. data/lib/videojuicer/promo/base.rb +72 -0
  32. data/lib/videojuicer/resource/base.rb +175 -0
  33. data/lib/videojuicer/resource/collection.rb +36 -0
  34. data/lib/videojuicer/resource/embeddable.rb +30 -0
  35. data/lib/videojuicer/resource/errors.rb +17 -0
  36. data/lib/videojuicer/resource/inferrable.rb +141 -0
  37. data/lib/videojuicer/resource/property_registry.rb +145 -0
  38. data/lib/videojuicer/resource/relationships/belongs_to.rb +39 -0
  39. data/lib/videojuicer/resource/types.rb +28 -0
  40. data/lib/videojuicer/session.rb +74 -0
  41. data/lib/videojuicer/shared/configurable.rb +103 -0
  42. data/lib/videojuicer/shared/exceptions.rb +32 -0
  43. data/lib/videojuicer/user.rb +43 -0
  44. data/lib/videojuicer.rb +110 -0
  45. data/spec/assets/audio_spec.rb +25 -0
  46. data/spec/assets/flash_spec.rb +24 -0
  47. data/spec/assets/image_spec.rb +25 -0
  48. data/spec/assets/text_spec.rb +24 -0
  49. data/spec/assets/video_spec.rb +25 -0
  50. data/spec/belongs_to_spec.rb +45 -0
  51. data/spec/campaign_policy_spec.rb +41 -0
  52. data/spec/campaign_spec.rb +25 -0
  53. data/spec/collection_spec.rb +31 -0
  54. data/spec/criterion/date_range_spec.rb +24 -0
  55. data/spec/criterion/geolocation_spec.rb +23 -0
  56. data/spec/criterion/request_spec.rb +23 -0
  57. data/spec/criterion/time_spec.rb +23 -0
  58. data/spec/criterion/week_day_spec.rb +23 -0
  59. data/spec/files/audio.mp3 +0 -0
  60. data/spec/files/empty_file +0 -0
  61. data/spec/files/flash.swf +0 -0
  62. data/spec/files/image.jpg +0 -0
  63. data/spec/files/text.txt +1 -0
  64. data/spec/files/video.mov +0 -0
  65. data/spec/helpers/be_equal_to.rb +26 -0
  66. data/spec/helpers/spec_fixtures.rb +227 -0
  67. data/spec/helpers/spec_helper.rb +53 -0
  68. data/spec/presentation_spec.rb +25 -0
  69. data/spec/preset_spec.rb +30 -0
  70. data/spec/promos/audio_spec.rb +23 -0
  71. data/spec/promos/image_spec.rb +24 -0
  72. data/spec/promos/text_spec.rb +23 -0
  73. data/spec/promos/video_spec.rb +23 -0
  74. data/spec/property_registry_spec.rb +130 -0
  75. data/spec/request_proxy_spec.rb +90 -0
  76. data/spec/session_spec.rb +98 -0
  77. data/spec/shared/asset_spec.rb +39 -0
  78. data/spec/shared/configurable_spec.rb +75 -0
  79. data/spec/shared/dependent_spec.rb +40 -0
  80. data/spec/shared/embeddable_spec.rb +34 -0
  81. data/spec/shared/model_spec.rb +74 -0
  82. data/spec/shared/resource_spec.rb +140 -0
  83. data/spec/spec.opts +3 -0
  84. data/spec/user_spec.rb +42 -0
  85. data/spec/videojuicer_spec.rb +122 -0
  86. data/tasks/vj-core.rb +72 -0
  87. data/vj-sdk.gemspec +168 -0
  88. metadata +209 -0
Binary file
Binary file
@@ -0,0 +1 @@
1
+ Today, we celebrate the first glorious anniversary of the Information Purification Directives. We have created, for the first time in all history, a garden of pure ideology. Where each worker may bloom secure from the pests purveying contradictory thoughts. Our Unification of Thoughts is more powerful a weapon than any fleet or army on earth. We are one people, with one will, one resolve, one cause. Our enemies shall talk themselves to death and we will bury them with their own confusion. We shall prevail!
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,227 @@
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
+ class Preset
215
+ include FixtureHelper
216
+ set_attribute_proc {{
217
+ :name => /\w{10}/.gen,
218
+ :derived_type => "Video",
219
+ :file_format => "mp4",
220
+ :audio_format => "libfaac",
221
+ :video_format => "mpeg4",
222
+ :width => 640,
223
+ :height => 480
224
+ }}
225
+ end
226
+
227
+ end
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'yaml'
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")
17
+ require File.join(File.dirname(__FILE__), "..", "shared", "configurable_spec")
18
+ require File.join(File.dirname(__FILE__), "..", "shared", "model_spec")
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
+ require File.join(File.dirname(__FILE__), "..", "shared", "asset_spec")
23
+
24
+ # Load the fixture helper
25
+ require File.join(File.dirname(__FILE__), "spec_fixtures")
26
+
27
+ module SpecHelper
28
+
29
+ def configure_test_settings(overrides={})
30
+ Videojuicer.configure!({
31
+ :api_version => 1,
32
+ :protocol => "http",
33
+ :host => "localhost",
34
+ :port => 6666,
35
+ :consumer_key => fixtures["write-master"]["consumer"]["consumer_key"],
36
+ :consumer_secret => fixtures["write-master"]["consumer"]["consumer_secret"],
37
+ :token => fixtures["write-master"]["authorized_token"]["oauth_token"],
38
+ :token_secret => fixtures["write-master"]["authorized_token"]["oauth_token_secret"],
39
+ :seed_name => fixtures["seed"]["name"]
40
+ }.merge(overrides))
41
+ end
42
+
43
+ def fixtures
44
+ fixture_path = File.join(File.dirname(__FILE__), "..", "..", "core-fixtures.yml")
45
+ fixture_src = File.open(fixture_path).read
46
+ @core_fixtures ||= Mash.new(YAML.load(fixture_src))
47
+ end
48
+
49
+ end
50
+
51
+ Spec::Runner.configure do |config|
52
+ config.include(SpecHelper)
53
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Presentation do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Presentation
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 = "presentation"
17
+ @plural_name = "presentations"
18
+ end
19
+
20
+ it_should_behave_like "a RESTFUL resource model"
21
+ it_should_behave_like "an embeddable"
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Preset do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Preset
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 = "preset"
17
+ @plural_name = "presets"
18
+ end
19
+
20
+ it_should_behave_like "a RESTFUL resource model"
21
+ end
22
+
23
+ describe "formats" do
24
+ it "should return a hash of available file, audio and video formats" do
25
+ formats = @klass.formats
26
+ formats.should be_kind_of(Hash)
27
+ formats.keys.sort.should == %w(audio_formats file_formats video_formats)
28
+ end
29
+ end
30
+ end
@@ -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
@@ -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
@@ -0,0 +1,130 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Resource::PropertyRegistry do
4
+
5
+ describe "attribute registry" do
6
+ before(:all) do
7
+ class ::FooAttributeRegistry
8
+ include Videojuicer::Resource::PropertyRegistry
9
+
10
+ property :integer, Integer
11
+ property :string, String
12
+ property :string_with_default, String, :default=>"this is the default"
13
+ end
14
+
15
+ class ::BarAttributeRegistry
16
+ include Videojuicer::Resource::PropertyRegistry
17
+
18
+ property :bar, String
19
+ end
20
+
21
+ class ::NameConditionTestRegistry
22
+ include Videojuicer::Resource::PropertyRegistry
23
+
24
+ property :name, String
25
+ property :email, String
26
+ end
27
+
28
+ class ::PrivatePropertyRegistry
29
+ include Videojuicer::Resource::PropertyRegistry
30
+
31
+ property :private_attr, String, :writer=>:private
32
+ property :public_attr, String
33
+ end
34
+
35
+ class ::DateRegistry
36
+ include Videojuicer::Resource::PropertyRegistry
37
+
38
+ property :date, DateTime
39
+ end
40
+ end
41
+ before(:each) do
42
+ @example_registry = ::FooAttributeRegistry.new
43
+ @example_private_prop_registry = ::PrivatePropertyRegistry.new
44
+ @date_registry = ::DateRegistry.new
45
+ end
46
+
47
+ it "registers an attribute with a type at the class scope" do
48
+ ::FooAttributeRegistry.attributes.should include(:integer)
49
+ ::FooAttributeRegistry.attributes.should include(:string)
50
+ ::FooAttributeRegistry.attributes.should include(:string_with_default)
51
+ ::FooAttributeRegistry.attributes.should_not include(:bar)
52
+
53
+ ::BarAttributeRegistry.attributes.should include(:bar)
54
+ ::BarAttributeRegistry.attributes.should_not include(:integer)
55
+ ::BarAttributeRegistry.attributes.should_not include(:string)
56
+ ::BarAttributeRegistry.attributes.should_not include(:string_with_default)
57
+ end
58
+ it "registers an attribute with a type at the instance scope" do
59
+ @example_registry.attributes.should include(:integer)
60
+ @example_registry.attributes.should include(:string)
61
+ @example_registry.attributes.should include(:string_with_default)
62
+ end
63
+ it "respects specific defaults on properties" do
64
+ @example_registry.string_with_default.should == "this is the default"
65
+ end
66
+ it "sets the default to be nil" do
67
+ @example_registry.string.should be_nil
68
+ end
69
+
70
+ it "allows an object to be set and read directly" do
71
+ @example_registry.string = "1234567"
72
+ @example_registry.string.should == "1234567"
73
+ end
74
+
75
+ it "allows an object to be set and read via the indirect helper" do
76
+ @example_registry.attr_set :string, "987654321"
77
+ @example_registry.attr_get(:string).should == "987654321"
78
+ end
79
+
80
+ it "converts attributes to a date when a string is passed into a datetime object" do
81
+ @date_registry.date = "2009-07-01 13:14:15"
82
+ @date_registry.date.should be_kind_of(DateTime)
83
+ @date_registry.date.year.should == 2009
84
+ @date_registry.date.month.should == 7
85
+ @date_registry.date.day.should == 1
86
+ @date_registry.date.hour.should == 13
87
+ @date_registry.date.min.should == 14
88
+ @date_registry.date.sec.should == 15
89
+ end
90
+
91
+ it "does not include the ID in the returnable attributes" do
92
+ @example_private_prop_registry.returnable_attributes.should_not include(:id)
93
+ end
94
+ it "does not include the private attributes in the returnable attributes" do
95
+ @example_private_prop_registry.returnable_attributes.should_not include(:private_attr)
96
+ @example_private_prop_registry.returnable_attributes.should include(:public_attr)
97
+ end
98
+
99
+ it "allows an object to be created with a hash of attributes" do
100
+ created = ::FooAttributeRegistry.new(:integer=>0, :string=>"0000", :string_with_default=>"1111")
101
+ created.integer.should == 0
102
+ created.string.should == "0000"
103
+ created.string_with_default.should == "1111"
104
+ end
105
+
106
+ it "allows attributes to be set with a hash" do
107
+ created = ::FooAttributeRegistry.new
108
+ created.attributes = {:integer=>0, :string=>"0000", :string_with_default=>"1111"}
109
+ created.integer.should == 0
110
+ created.string.should == "0000"
111
+ created.string_with_default.should == "1111"
112
+ end
113
+ it "allows attributes to be read as a hash" do
114
+ created = ::FooAttributeRegistry.new(:integer=>0, :string=>"0000", :string_with_default=>"1111", :id=>5)
115
+ created.attributes.should == {:integer=>0, :string=>"0000", :string_with_default=>"1111", :id=>5}
116
+ end
117
+
118
+ it "allows mass assignment with indifferent access" do
119
+ created = ::NameConditionTestRegistry.new
120
+ created.attributes = {"name"=>"name set", "email"=>"gooooo"}
121
+ created.name.should == "name set"
122
+ created.email.should == "gooooo"
123
+
124
+ created = ::NameConditionTestRegistry.new
125
+ created.attributes = {:name=>"name set", :email=>"gooooo"}
126
+ created.name.should == "name set"
127
+ created.email.should == "gooooo"
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::OAuth::RequestProxy do
4
+
5
+ before(:each) do
6
+ configure_test_settings
7
+ end
8
+
9
+ describe "instantiation" do
10
+ before(:all) do
11
+ @klass = Videojuicer::OAuth::RequestProxy
12
+ end
13
+ it_should_behave_like "a configurable"
14
+ end
15
+
16
+ describe "URL normalizer" do
17
+ before(:all) do
18
+ @proxy = Videojuicer::OAuth::RequestProxy.new
19
+ end
20
+
21
+ it "can split a parameter hash into a regular and multipart hash" do
22
+ f = File.open(__FILE__)
23
+ params = {:user=>{:attributes=>{:file=>f, :name=>"user name"}}, :foo=>"bar"}
24
+ normal, multipart = @proxy.split_by_signature_eligibility(params)
25
+ normal.should == {:user=>{:attributes=>{:name=>"user name"}}, :foo=>"bar"}
26
+ multipart.should == {:user=>{:attributes=>{:file=>f}}}
27
+ end
28
+
29
+ it "can sort a basic parameter hash correctly" do
30
+ @proxy.normalize_params(:a=>"1", :b=>"2", :c=>"2", :d=>1).should == "a=1&b=2&c=2&d=1"
31
+ end
32
+ it "can sort complex nested parameter hashes correctly" do
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"
34
+ end
35
+ it "escapes the signature base string elements and adjoins them with an ampersand" do
36
+ @proxy.signature_base_string(:get, "/test", :foo=>"bar", :bar=>"baz").should == "GET&#{CGI.rfc3986_escape "http://localhost:6666/test"}&#{CGI.rfc3986_escape "bar=baz&foo=bar"}"
37
+ end
38
+
39
+ describe "with no token supplied" do
40
+ before(:all) do
41
+ @proxy = Videojuicer::OAuth::RequestProxy.new(:token=>nil, :token_secret=>nil, :consumer_key=>"conkey", :consumer_secret=>"consec")
42
+ end
43
+
44
+ it "omits the token secret from the signature secret" do
45
+ @proxy.signature_secret.should == "consec&"
46
+ end
47
+
48
+ it "omits the token from the signature params" do
49
+ ap = @proxy.authify_params(:get, "/test", :a=>1, :b=>2)
50
+ ap[:a].should == 1
51
+ ap[:b].should == 2
52
+ ap.include?(:oauth_token).should be_false
53
+ ap[:oauth_consumer_key].should == "conkey"
54
+ end
55
+ end
56
+
57
+ describe "with a token supplied" do
58
+ before(:all) do
59
+ @proxy = Videojuicer::OAuth::RequestProxy.new(:token=>"token", :token_secret=>"tosec", :consumer_key=>"conkey", :consumer_secret=>"consec")
60
+ end
61
+
62
+ it "includes the token secret in the signature secret" do
63
+ @proxy.signature_secret.should == "consec&tosec"
64
+ end
65
+
66
+ it "includes the token automatically in the signature params" do
67
+ ap = @proxy.authify_params(:get, "/test", :a=>1, :b=>2)
68
+ ap[:a].should == 1
69
+ ap[:b].should == 2
70
+ ap[:oauth_token].should == "token"
71
+ ap[:oauth_consumer_key].should == "conkey"
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "request factory" do
77
+ before(:all) do
78
+ @seed = fixtures.seed
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)
81
+ end
82
+
83
+ it "can successfully retrieve a request token (indicating a successful signature verification)" do
84
+ @proxy.consumer_key.should == @fix.consumer.consumer_key
85
+ response = @proxy.get("/oauth/tokens")
86
+ response.body.should =~ /oauth_token=[a-zA-Z0-9]+&oauth_token_secret=[a-zA-Z0-9]+/
87
+ end
88
+ end
89
+
90
+ end