videojuicer-vj-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +0 -0
  3. data/README.rdoc +7 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/core_ext/hash.rb +40 -0
  6. data/lib/sdk_connection_harness.rb +87 -0
  7. data/lib/videojuicer/asset/audio.rb +11 -0
  8. data/lib/videojuicer/asset/base.rb +50 -0
  9. data/lib/videojuicer/asset/image.rb +12 -0
  10. data/lib/videojuicer/asset/text.rb +8 -0
  11. data/lib/videojuicer/asset/video.rb +13 -0
  12. data/lib/videojuicer/campaign.rb +8 -0
  13. data/lib/videojuicer/oauth/multipart_helper.rb +96 -0
  14. data/lib/videojuicer/oauth/proxy_factory.rb +18 -0
  15. data/lib/videojuicer/oauth/request_proxy.rb +234 -0
  16. data/lib/videojuicer/presentation.rb +32 -0
  17. data/lib/videojuicer/resource/base.rb +174 -0
  18. data/lib/videojuicer/resource/collection.rb +34 -0
  19. data/lib/videojuicer/resource/errors.rb +17 -0
  20. data/lib/videojuicer/resource/inferrable.rb +81 -0
  21. data/lib/videojuicer/resource/property_registry.rb +126 -0
  22. data/lib/videojuicer/resource/relationships/belongs_to.rb +38 -0
  23. data/lib/videojuicer/session.rb +74 -0
  24. data/lib/videojuicer/shared/configurable.rb +103 -0
  25. data/lib/videojuicer/shared/exceptions.rb +20 -0
  26. data/lib/videojuicer/user.rb +43 -0
  27. data/lib/videojuicer.rb +97 -0
  28. data/spec/audio_spec.rb +43 -0
  29. data/spec/belongs_to_spec.rb +45 -0
  30. data/spec/campaign_spec.rb +37 -0
  31. data/spec/collection_spec.rb +25 -0
  32. data/spec/files/audio.mp3 +0 -0
  33. data/spec/files/empty_file +0 -0
  34. data/spec/files/image.jpg +0 -0
  35. data/spec/files/text.txt +1 -0
  36. data/spec/files/video.mov +0 -0
  37. data/spec/helpers/spec_helper.rb +50 -0
  38. data/spec/image_spec.rb +44 -0
  39. data/spec/presentation_spec.rb +38 -0
  40. data/spec/property_registry_spec.rb +130 -0
  41. data/spec/request_proxy_spec.rb +94 -0
  42. data/spec/session_spec.rb +96 -0
  43. data/spec/shared/configurable_spec.rb +75 -0
  44. data/spec/shared/resource_spec.rb +170 -0
  45. data/spec/spec.opts +3 -0
  46. data/spec/text_spec.rb +42 -0
  47. data/spec/user_spec.rb +64 -0
  48. data/spec/video_spec.rb +45 -0
  49. data/spec/videojuicer_spec.rb +122 -0
  50. metadata +136 -0
@@ -0,0 +1,43 @@
1
+ module Videojuicer
2
+ class User
3
+ include Videojuicer::Resource
4
+ include Videojuicer::Exceptions
5
+
6
+ property :name, String
7
+ property :login, String
8
+ property :email, String
9
+ property :password, String
10
+ property :password_confirmation, String
11
+ property :created_at, DateTime
12
+ property :updated_at, DateTime
13
+
14
+ # Authenticates the given login and password and returns
15
+ # a user if the details are correct. Requires a Master token.
16
+ def self.authenticate(login, password)
17
+ proxy = Videojuicer::OAuth::RequestProxy.new
18
+ begin
19
+ jobj = JSON.parse(proxy.get("/users/authenticate.json", :login=>login, :password=>password).body)
20
+ o = new(:id=>jobj["id"])
21
+ o.reload
22
+ return o
23
+ rescue NoResource =>e
24
+ return nil
25
+ end
26
+ end
27
+
28
+ # Manage virtual attributes that are not sent back to the API
29
+ attr_accessor :roles
30
+ def has_role?(symbol)
31
+ roles.include?(symbol.to_s)
32
+ end
33
+
34
+ def add_role(*symbols)
35
+ symbols.each {|r| proxy_for(config).post(resource_path(:add_role), :role=>r) }
36
+ end
37
+
38
+ def remove_role(*symbols)
39
+ symbols.each {|r| proxy_for(config).post(resource_path(:remove_role), :role=>r) }
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,97 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+
3
+ # Gem and stdlib dependencies
4
+ require 'rubygems'
5
+ require 'cgi'
6
+ require 'json'
7
+ require 'hmac-sha1'
8
+ require 'net/http'
9
+
10
+ # Core ext
11
+ require 'core_ext/hash'
12
+ # Core mixins
13
+ require 'videojuicer/shared/exceptions'
14
+ require 'videojuicer/shared/configurable'
15
+ # Authentication and authorisation
16
+ require 'videojuicer/oauth/request_proxy'
17
+ require 'videojuicer/oauth/proxy_factory'
18
+ # Resource handling
19
+ require 'videojuicer/resource/relationships/belongs_to'
20
+ require 'videojuicer/resource/errors'
21
+ require 'videojuicer/resource/collection'
22
+ require 'videojuicer/resource/inferrable'
23
+ require 'videojuicer/resource/property_registry'
24
+ require 'videojuicer/resource/base'
25
+ require 'videojuicer/session'
26
+ # Frontend models
27
+ require 'videojuicer/user'
28
+ require 'videojuicer/campaign'
29
+ require 'videojuicer/presentation'
30
+ require 'videojuicer/asset/audio'
31
+ require 'videojuicer/asset/video'
32
+ require 'videojuicer/asset/text'
33
+ require 'videojuicer/asset/image'
34
+
35
+ module Videojuicer
36
+
37
+ DEFAULTS = {
38
+ :consumer_key => nil,
39
+ :consumer_secret => nil,
40
+ :token => nil,
41
+ :token_secret => nil,
42
+ :api_version => nil,
43
+ :seed_name => nil,
44
+ :user_id => nil,
45
+ :protocol => "http",
46
+ :host => "api.videojuicer.com",
47
+ :port => 80
48
+ }.freeze
49
+
50
+ @default_options = {}
51
+ @scope_stack = []
52
+
53
+ class << self
54
+
55
+ def scopes
56
+ ([default_options]+@scope_stack).compact
57
+ end
58
+
59
+ def in_scope?
60
+ !@scope_stack.empty?
61
+ end
62
+
63
+ def current_scope
64
+ scopes.last
65
+ end
66
+
67
+ def enter_scope(config)
68
+ @scope_stack.push current_scope.merge(config)
69
+ end
70
+
71
+ def exit_scope
72
+ @scope_stack.pop
73
+ end
74
+
75
+ def exit_all!
76
+ @scope_stack = []
77
+ end
78
+
79
+ def [](key)
80
+ @default_options[key]
81
+ end
82
+
83
+ def configure!(options={})
84
+ @default_options = DEFAULTS.merge(@default_options.merge(options))
85
+ end
86
+
87
+ def unconfigure!
88
+ @default_options = DEFAULTS
89
+ end
90
+
91
+ def default_options
92
+ @default_options
93
+ end
94
+ end
95
+
96
+
97
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Asset::Audio do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Asset::Audio
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
+ end
18
+
19
+ describe "instantiation" do
20
+ it_should_behave_like "a configurable"
21
+ end
22
+
23
+ describe "general interface:" do
24
+ before(:all) do
25
+ @singular_name = "asset"
26
+ @plural_name = "assets/audio"
27
+ @good_attributes = {
28
+ :user_id => rand(100) + 1,
29
+ :licensed_at => Time.now,
30
+ :licensed_by => "foo, bar",
31
+ :licensed_under => "CC BY:NC:SA",
32
+ :published_at => Time.now,
33
+ :duration => 180000,
34
+ :bit_rate => 262144,
35
+ :file => File.open(File.join(File.dirname(__FILE__), "files", "audio.mp3"))
36
+ }
37
+ end
38
+
39
+ it_should_behave_like "a RESTFUL resource model"
40
+ end
41
+
42
+
43
+ end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Resource::Relationships::BelongsTo do
4
+
5
+ after(:all) do
6
+ Videojuicer.exit_scope
7
+ end
8
+
9
+ before(:all) do
10
+ configure_test_settings
11
+ Videojuicer.enter_scope :seed_name => fixtures.seed.name,
12
+ :consumer_key=>fixtures["write-master"].consumer.consumer_key,
13
+ :consumer_secret=>fixtures["write-master"].consumer.consumer_secret,
14
+ :token=>fixtures["write-master"].authorized_token.oauth_token,
15
+ :token_secret=>fixtures["write-master"].authorized_token.oauth_token_secret
16
+
17
+ @user = Videojuicer::User.first
18
+ @user.should be_kind_of(Videojuicer::User)
19
+
20
+ class ::BelongsToExample
21
+ include Videojuicer::Resource
22
+
23
+ property :user_id, Integer
24
+ belongs_to :user, :class=>Videojuicer::User
25
+ end
26
+
27
+ @example = ::BelongsToExample.new
28
+ @example.user_id = @user.id
29
+ end
30
+
31
+ it "retrieves the user" do
32
+ @example.user.id.should == @user.id
33
+ end
34
+
35
+ it "returns nil when the user_id is nonsense" do
36
+ bad_example = ::BelongsToExample.new(:user_id=>9900000000)
37
+ bad_example.user.should be_nil
38
+ end
39
+
40
+ it "sets the user" do
41
+ @example.user = @user
42
+ @example.user_id.should == @user.id
43
+ end
44
+
45
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Campaign do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Campaign
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
+ end
18
+
19
+ describe "instantiation" do
20
+ it_should_behave_like "a configurable"
21
+ end
22
+
23
+ describe "general interface:" do
24
+ before(:all) do
25
+ string_mash = (("A".."z").to_a + ("a".."z").to_a)
26
+ @singular_name = "campaign"
27
+ @plural_name = "campaigns"
28
+ @good_attributes = {
29
+ :name => (0..rand(75)).map{ string_mash[rand(string_mash.size - 1)] }.join
30
+ }
31
+ end
32
+
33
+ it_should_behave_like "a RESTFUL resource model"
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Resource::Collection do
4
+
5
+ before(:all) do
6
+ @objects = [:foo]*100
7
+ @collection = Videojuicer::Resource::Collection.new(@objects[0..9], 155, 17, 10)
8
+ end
9
+
10
+ it "is instantiated correctly" do
11
+ @collection.should be_kind_of(Videojuicer::Resource::Collection)
12
+ @collection.total.should == 155
13
+ @collection.offset.should == 17
14
+ @collection.limit.should == 10
15
+ end
16
+
17
+ it "can count the number of pages" do
18
+ @collection.page_count.should == 16
19
+ end
20
+
21
+ it "can tell the current page" do
22
+ @collection.page_number.should == 2
23
+ end
24
+
25
+ end
Binary file
File without changes
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,50 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'mash'
4
+ require 'yaml'
5
+ require File.join(File.dirname(__FILE__), "..", "..", "lib", "videojuicer")
6
+
7
+ require File.join(File.dirname(__FILE__), "..", "shared", "configurable_spec")
8
+ require File.join(File.dirname(__FILE__), "..", "shared", "resource_spec")
9
+
10
+ module SpecHelper
11
+
12
+ def configure_test_settings(overrides={})
13
+ Videojuicer.configure!({
14
+ :consumer_key => nil,
15
+ :consumer_secret => nil,
16
+ :api_version => 1,
17
+ :protocol => "http",
18
+ :host => "localhost",
19
+ :port => 5555
20
+ }.merge(overrides))
21
+ end
22
+
23
+ def fixtures
24
+ @fixtures ||= Mash.new(YAML.load(File.open(File.join(File.dirname(__FILE__), "..", "..", "core-fixtures.yml")).read))
25
+ end
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
+
44
+ end
45
+
46
+ end
47
+
48
+ Spec::Runner.configure do |config|
49
+ config.include(SpecHelper)
50
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::Asset::Image do
4
+
5
+ before(:all) do
6
+ @klass = Videojuicer::Asset::Image
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
+ end
18
+
19
+ describe "instantiation" do
20
+ it_should_behave_like "a configurable"
21
+ end
22
+
23
+ describe "general interface:" do
24
+ before(:all) do
25
+ @singular_name = "asset"
26
+ @plural_name = "assets/image"
27
+ @good_attributes = {
28
+ :user_id => rand(100) + 1,
29
+ :licensed_at => Time.now,
30
+ :licensed_by => "foo, bar",
31
+ :licensed_under => "CC BY:NC:SA",
32
+ :published_at => Time.now,
33
+ :duration => 180000,
34
+ :width => 640,
35
+ :height => 480,
36
+ :file => File.open(File.join(File.dirname(__FILE__), "files", "image.jpg"))
37
+ }
38
+ end
39
+
40
+ it_should_behave_like "a RESTFUL resource model"
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,38 @@
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
+ 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
+ end
18
+
19
+ describe "instantiation" do
20
+ it_should_behave_like "a configurable"
21
+ end
22
+
23
+ describe "general interface:" do
24
+ before(:all) do
25
+ @singular_name = "presentation"
26
+ @plural_name = "presentations"
27
+ @good_attributes = {
28
+ :title=>"Presentation title #{rand 99999}",
29
+ :abstract=>"Presentation abstract #{rand 99999}",
30
+ :author=>"Bob Anon"
31
+ }
32
+ end
33
+
34
+ it_should_behave_like "a RESTFUL resource model"
35
+ end
36
+
37
+
38
+ 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,94 @@
1
+ require File.join(File.dirname(__FILE__), "helpers", "spec_helper")
2
+
3
+ describe Videojuicer::OAuth::RequestProxy do
4
+
5
+ before(:each) { configure_test_settings }
6
+
7
+ describe "instantiation" do
8
+ before(:all) do
9
+ @klass = Videojuicer::OAuth::RequestProxy
10
+ end
11
+ it_should_behave_like "a configurable"
12
+ end
13
+
14
+ describe "URL normalizer" do
15
+ before(:all) do
16
+ @proxy = Videojuicer::OAuth::RequestProxy.new
17
+ end
18
+
19
+ it "can split a parameter hash into a regular and multipart hash" do
20
+ f = File.open(__FILE__)
21
+ params = {:user=>{:attributes=>{:file=>f, :name=>"user name"}}, :foo=>"bar"}
22
+ normal, multipart = @proxy.split_by_signature_eligibility(params)
23
+ normal.should == {:user=>{:attributes=>{:name=>"user name"}}, :foo=>"bar"}
24
+ multipart.should == {:user=>{:attributes=>{:file=>f}}}
25
+ end
26
+
27
+ it "can sort a basic parameter hash correctly" do
28
+ @proxy.normalize_params(:a=>"1", :b=>"2", :c=>"2", :d=>1).should == "a=1&b=2&c=2&d=1"
29
+ end
30
+ it "can sort complex nested parameter hashes correctly" do
31
+ @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
+
36
+ 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"}"
38
+ end
39
+
40
+ describe "with no token supplied" do
41
+ before(:all) do
42
+ @proxy = Videojuicer::OAuth::RequestProxy.new(:token=>nil, :token_secret=>nil, :consumer_key=>"conkey", :consumer_secret=>"consec")
43
+ end
44
+
45
+ it "omits the token secret from the signature secret" do
46
+ @proxy.signature_secret.should == "consec&"
47
+ end
48
+
49
+ it "omits the token from the signature params" do
50
+ ap = @proxy.authify_params(:get, "/test", :a=>1, :b=>2)
51
+ ap[:a].should == 1
52
+ ap[:b].should == 2
53
+ ap.include?(:oauth_token).should be_false
54
+ ap[:oauth_consumer_key].should == "conkey"
55
+ end
56
+ end
57
+
58
+ describe "with a token supplied" do
59
+ before(:all) do
60
+ @proxy = Videojuicer::OAuth::RequestProxy.new(:token=>"token", :token_secret=>"tosec", :consumer_key=>"conkey", :consumer_secret=>"consec")
61
+ end
62
+
63
+ it "includes the token secret in the signature secret" do
64
+ @proxy.signature_secret.should == "consec&tosec"
65
+ end
66
+
67
+ it "includes the token automatically in the signature params" do
68
+ ap = @proxy.authify_params(:get, "/test", :a=>1, :b=>2)
69
+ ap[:a].should == 1
70
+ ap[:b].should == 2
71
+ ap[:oauth_token].should == "token"
72
+ ap[:oauth_consumer_key].should == "conkey"
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "request factory" do
78
+ before(:all) do
79
+ @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)
82
+ end
83
+
84
+ it "can successfully retrieve a request token (indicating a successful signature verification)" do
85
+ @proxy.consumer_key.should == @fixtures.consumer.consumer_key
86
+ response = @proxy.get("/oauth/tokens")
87
+ response.body.should =~ /oauth_token=[a-zA-Z0-9]+&oauth_token_secret=[a-zA-Z0-9]+/
88
+ 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
+ end
93
+
94
+ end