fleakr 0.5.2 → 0.6.0
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.
- data/README.rdoc +52 -17
- data/lib/fleakr.rb +37 -29
- data/lib/fleakr/api.rb +1 -0
- data/lib/fleakr/api/authentication_request.rb +32 -0
- data/lib/fleakr/api/file_parameter.rb +4 -2
- data/lib/fleakr/api/method_request.rb +11 -12
- data/lib/fleakr/api/parameter_list.rb +75 -48
- data/lib/fleakr/api/upload_request.rb +1 -1
- data/lib/fleakr/api/value_parameter.rb +3 -3
- data/lib/fleakr/objects/authentication_token.rb +4 -0
- data/lib/fleakr/objects/set.rb +24 -0
- data/lib/fleakr/support.rb +2 -1
- data/lib/fleakr/support/object.rb +10 -6
- data/lib/fleakr/support/request.rb +23 -0
- data/lib/fleakr/version.rb +2 -2
- data/test/fixtures/photosets.getInfo.xml +7 -0
- data/test/test_helper.rb +3 -3
- data/test/unit/fleakr/api/authentication_request_test.rb +37 -0
- data/test/unit/fleakr/api/file_parameter_test.rb +0 -5
- data/test/unit/fleakr/api/method_request_test.rb +67 -85
- data/test/unit/fleakr/api/parameter_list_test.rb +116 -97
- data/test/unit/fleakr/api/upload_request_test.rb +5 -15
- data/test/unit/fleakr/objects/authentication_token_test.rb +9 -0
- data/test/unit/fleakr/objects/set_test.rb +30 -1
- data/test/unit/fleakr/support/object_test.rb +12 -6
- data/test/unit/fleakr/support/request_test.rb +42 -0
- data/test/unit/fleakr_test.rb +36 -90
- metadata +7 -4
- data/lib/fleakr/api/parameter.rb +0 -35
- data/test/unit/fleakr/api/parameter_test.rb +0 -34
@@ -39,7 +39,7 @@ module Fleakr
|
|
39
39
|
@options = options
|
40
40
|
|
41
41
|
@parameters = ParameterList.new(upload_options)
|
42
|
-
|
42
|
+
parameters.add_upload_option(:photo, filename)
|
43
43
|
end
|
44
44
|
|
45
45
|
# A list of upload options for this upload request (see Fleakr::Api::Option)
|
@@ -5,15 +5,15 @@ module Fleakr
|
|
5
5
|
#
|
6
6
|
# A simple name / value parameter for use in API calls
|
7
7
|
#
|
8
|
-
class ValueParameter
|
8
|
+
class ValueParameter
|
9
9
|
|
10
|
-
attr_reader :value
|
10
|
+
attr_reader :name, :value
|
11
11
|
|
12
12
|
# Create a new parameter with the specified name / value pair.
|
13
13
|
#
|
14
14
|
def initialize(name, value, include_in_signature = true)
|
15
|
+
@name = name
|
15
16
|
@value = value
|
16
|
-
super(name, include_in_signature)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Generate the query string representation of this parameter.
|
data/lib/fleakr/objects/set.rb
CHANGED
@@ -24,8 +24,13 @@ module Fleakr
|
|
24
24
|
flickr_attribute :id, :title, :description
|
25
25
|
flickr_attribute :primary_photo_id, :from => '@primary'
|
26
26
|
flickr_attribute :count, :from => '@photos'
|
27
|
+
flickr_attribute :user_id, :from => '@owner'
|
27
28
|
|
28
29
|
find_all :by_user_id, :call => 'photosets.getList', :path => 'photosets/photoset'
|
30
|
+
|
31
|
+
find_one :by_id, :using => :photoset_id, :call => 'photosets.getInfo', :path => 'photoset'
|
32
|
+
|
33
|
+
lazily_load :user_id, :with => :load_info
|
29
34
|
|
30
35
|
# Save all photos in this set to the specified directory for the specified size. Allowed
|
31
36
|
# Sizes include <tt>:square</tt>, <tt>:small</tt>, <tt>:thumbnail</tt>, <tt>:medium</tt>,
|
@@ -46,10 +51,29 @@ module Fleakr
|
|
46
51
|
sprintf("%0#{self.count.length}d_", (index + 1))
|
47
52
|
end
|
48
53
|
|
54
|
+
# Primary photo for this set. See Fleakr::Objects::Photo for more details.
|
55
|
+
#
|
49
56
|
def primary_photo
|
50
57
|
@primary_photo ||= Photo.find_by_id(primary_photo_id)
|
51
58
|
end
|
52
59
|
|
60
|
+
# The URL for this set.
|
61
|
+
#
|
62
|
+
def url
|
63
|
+
"http://www.flickr.com/photos/#{user_id}/sets/#{id}/"
|
64
|
+
end
|
65
|
+
|
66
|
+
# The user who created this set.
|
67
|
+
#
|
68
|
+
def user
|
69
|
+
User.find_by_id(user_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def load_info # :nodoc:
|
73
|
+
response = Fleakr::Api::MethodRequest.with_response!('photosets.getInfo', :photoset_id => self.id)
|
74
|
+
self.populate_from(response.body)
|
75
|
+
end
|
76
|
+
|
53
77
|
end
|
54
78
|
end
|
55
79
|
end
|
data/lib/fleakr/support.rb
CHANGED
@@ -26,7 +26,7 @@ module Fleakr
|
|
26
26
|
|
27
27
|
class_eval <<-CODE
|
28
28
|
def #{attribute}
|
29
|
-
@#{attribute} ||= #{target}.send("find_all_by_#{finder_attribute}".to_sym, self.id)
|
29
|
+
@#{attribute} ||= #{target}.send("find_all_by_#{finder_attribute}".to_sym, self.id, self.authentication_options)
|
30
30
|
end
|
31
31
|
CODE
|
32
32
|
end
|
@@ -41,7 +41,7 @@ module Fleakr
|
|
41
41
|
options.merge!(:#{attribute} => value)
|
42
42
|
|
43
43
|
response = Fleakr::Api::MethodRequest.with_response!('#{options[:call]}', options)
|
44
|
-
(response.body/'rsp/#{options[:path]}').map {|e| #{target_class}.new(e) }
|
44
|
+
(response.body/'rsp/#{options[:path]}').map {|e| #{target_class}.new(e, options) }
|
45
45
|
end
|
46
46
|
CODE
|
47
47
|
end
|
@@ -54,7 +54,7 @@ module Fleakr
|
|
54
54
|
options.merge!(:#{attribute} => value)
|
55
55
|
|
56
56
|
response = Fleakr::Api::MethodRequest.with_response!('#{options[:call]}', options)
|
57
|
-
#{self.name}.new(response.body)
|
57
|
+
#{self.name}.new(response.body, options)
|
58
58
|
end
|
59
59
|
CODE
|
60
60
|
end
|
@@ -64,7 +64,10 @@ module Fleakr
|
|
64
64
|
|
65
65
|
class_eval <<-CODE
|
66
66
|
def search(*parameters)
|
67
|
-
|
67
|
+
options = {:#{key} => self.id}
|
68
|
+
options.merge!(self.authentication_options)
|
69
|
+
|
70
|
+
parameters << options
|
68
71
|
Fleakr::Objects::Search.new(*parameters).results
|
69
72
|
end
|
70
73
|
CODE
|
@@ -88,10 +91,11 @@ module Fleakr
|
|
88
91
|
|
89
92
|
module InstanceMethods
|
90
93
|
|
91
|
-
attr_reader :document
|
94
|
+
attr_reader :document, :authentication_options
|
92
95
|
|
93
|
-
def initialize(document = nil)
|
96
|
+
def initialize(document = nil, options = {})
|
94
97
|
self.populate_from(document) unless document.nil?
|
98
|
+
@authentication_options = options.extract!(:auth_token)
|
95
99
|
end
|
96
100
|
|
97
101
|
def populate_from(document)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fleakr
|
2
|
+
module Support # :nodoc:all
|
3
|
+
module Request
|
4
|
+
|
5
|
+
attr_reader :parameters
|
6
|
+
|
7
|
+
def initialize(additional_parameters = {})
|
8
|
+
authenticate = additional_parameters.delete(:authenticate?)
|
9
|
+
authenticate = authenticate.nil? ? true : authenticate
|
10
|
+
|
11
|
+
@parameters = Fleakr::Api::ParameterList.new(additional_parameters, authenticate)
|
12
|
+
end
|
13
|
+
|
14
|
+
def endpoint_uri
|
15
|
+
uri = URI.parse(endpoint_url)
|
16
|
+
uri.query = self.parameters.to_query
|
17
|
+
uri
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/fleakr/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
2
|
+
<rsp stat="ok">
|
3
|
+
<photoset id="72157622660138146" owner="43955217@N05" primary="4042405768" secret="05ef8f3baf" server="3525" farm="4" photos="2">
|
4
|
+
<title>My First Set!</title>
|
5
|
+
<description>This is a description</description>
|
6
|
+
</photoset>
|
7
|
+
</rsp>
|
data/test/test_helper.rb
CHANGED
@@ -59,7 +59,7 @@ class Test::Unit::TestCase
|
|
59
59
|
object = this_klass.new
|
60
60
|
object.stubs(:id).with().returns('1')
|
61
61
|
|
62
|
-
target_klass.expects("find_all_by_#{finder_attribute}".to_sym).with('1').returns(results)
|
62
|
+
target_klass.expects("find_all_by_#{finder_attribute}".to_sym).with('1', {}).returns(results)
|
63
63
|
object.send(attribute).should == results
|
64
64
|
end
|
65
65
|
|
@@ -87,7 +87,7 @@ class Test::Unit::TestCase
|
|
87
87
|
stub = stub()
|
88
88
|
response = mock_request_cycle :for => options[:call], :with => params
|
89
89
|
|
90
|
-
klass.expects(:new).with(response.body).returns(stub)
|
90
|
+
klass.expects(:new).with(response.body, params).returns(stub)
|
91
91
|
klass.send("find_by_#{options[:by]}".to_sym, condition_value).should == stub
|
92
92
|
end
|
93
93
|
end
|
@@ -111,7 +111,7 @@ class Test::Unit::TestCase
|
|
111
111
|
stub = stub()
|
112
112
|
stubs << stub
|
113
113
|
|
114
|
-
klass.expects(:new).with(element).returns(stub)
|
114
|
+
klass.expects(:new).with(element, finder_options).returns(stub)
|
115
115
|
end
|
116
116
|
|
117
117
|
klass.send("find_all_by_#{options[:by]}".to_sym, condition_value).should == stubs
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Api
|
4
|
+
class AuthenticationRequestTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of AuthenticationRequest" do
|
7
|
+
|
8
|
+
should "know the endpoint URL" do
|
9
|
+
request = AuthenticationRequest.new
|
10
|
+
request.endpoint_url.should == 'http://flickr.com/services/auth/'
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to make a request" do
|
14
|
+
endpoint_uri = stub()
|
15
|
+
|
16
|
+
request = AuthenticationRequest.new
|
17
|
+
request.stubs(:endpoint_uri).with().returns(endpoint_uri)
|
18
|
+
|
19
|
+
Net::HTTP.expects(:get_response).with(endpoint_uri).returns('response')
|
20
|
+
|
21
|
+
request.response.should == 'response'
|
22
|
+
end
|
23
|
+
|
24
|
+
should "know the authorization_url for the authentication request" do
|
25
|
+
response_headers = {'Location' => 'http://example.com/auth'}
|
26
|
+
response = stub() {|r| r.stubs(:header).with().returns(response_headers) }
|
27
|
+
|
28
|
+
request = AuthenticationRequest.new
|
29
|
+
request.stubs(:response).with().returns(response)
|
30
|
+
|
31
|
+
request.authorization_url.should == 'http://example.com/auth'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -14,11 +14,6 @@ module Fleakr::Api
|
|
14
14
|
FileUtils.rm_rf(@temp_dir)
|
15
15
|
end
|
16
16
|
|
17
|
-
should "know not to include itself in the parameter signature" do
|
18
|
-
parameter = FileParameter.new('photo', @filename)
|
19
|
-
parameter.include_in_signature?.should be(false)
|
20
|
-
end
|
21
|
-
|
22
17
|
{'jpg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif'}.each do |ext, mime_type|
|
23
18
|
should "know the correct MIME type for an extension of #{ext}" do
|
24
19
|
parameter = FileParameter.new('photo', "#{@temp_dir}/image.#{ext}")
|
@@ -3,92 +3,74 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Api
|
4
4
|
class MethodRequestTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
context "An instance of MethodRequest" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
Response.expects(:new).with(response_xml).returns(response_stub)
|
59
|
-
|
60
|
-
request = MethodRequest.new('people.findByUsername')
|
61
|
-
request.stubs(:endpoint_uri)
|
62
|
-
|
63
|
-
request.send.should == response_stub
|
64
|
-
end
|
65
|
-
|
66
|
-
should "be able to make a full request and response cycle" do
|
67
|
-
method = 'flickr.people.findByUsername'
|
68
|
-
params = {:username => 'foobar'}
|
69
|
-
|
70
|
-
response = stub(:error? => false)
|
71
|
-
|
72
|
-
MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
|
73
|
-
|
74
|
-
MethodRequest.with_response!(method, params).should == response
|
75
|
-
end
|
76
|
-
|
77
|
-
should "raise an exception when the full request / response cycle has errors" do
|
78
|
-
method = 'flickr.people.findByUsername'
|
79
|
-
params = {:username => 'foobar'}
|
80
|
-
|
81
|
-
response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
|
82
|
-
|
83
|
-
MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
|
84
|
-
|
85
|
-
lambda do
|
86
|
-
MethodRequest.with_response!('flickr.people.findByUsername', :username => 'foobar')
|
87
|
-
end.should raise_error(Fleakr::ApiError)
|
88
|
-
end
|
89
|
-
|
6
|
+
context "An instance of the MethodRequest class" do
|
7
|
+
|
8
|
+
should "know the endpoint URL" do
|
9
|
+
request = MethodRequest.new('people.findByUsername')
|
10
|
+
request.endpoint_url.should == 'http://api.flickr.com/services/rest/'
|
11
|
+
end
|
12
|
+
|
13
|
+
should "add the method name to the list of parameters" do
|
14
|
+
parameter_list = mock() {|p| p.expects(:add_option).with(:method, 'flickr.people.findByUsername') }
|
15
|
+
MethodRequest.any_instance.stubs(:parameters).with().returns(parameter_list)
|
16
|
+
|
17
|
+
MethodRequest.new('flickr.people.findByUsername')
|
18
|
+
end
|
19
|
+
|
20
|
+
should "translate a shorthand API call" do
|
21
|
+
request = MethodRequest.new('people.findByUsername')
|
22
|
+
request.method.should == 'flickr.people.findByUsername'
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be able to make a request" do
|
26
|
+
endpoint_uri = stub()
|
27
|
+
|
28
|
+
request = MethodRequest.new('people.findByUsername')
|
29
|
+
request.stubs(:endpoint_uri).with().returns(endpoint_uri)
|
30
|
+
|
31
|
+
Net::HTTP.expects(:get).with(endpoint_uri).returns('<xml>')
|
32
|
+
|
33
|
+
request.send
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create a response from the request" do
|
37
|
+
response_xml = '<xml>'
|
38
|
+
response_stub = stub()
|
39
|
+
|
40
|
+
Net::HTTP.stubs(:get).returns(response_xml)
|
41
|
+
Response.expects(:new).with(response_xml).returns(response_stub)
|
42
|
+
|
43
|
+
request = MethodRequest.new('people.findByUsername')
|
44
|
+
request.stubs(:endpoint_uri)
|
45
|
+
|
46
|
+
request.send.should == response_stub
|
47
|
+
end
|
48
|
+
|
49
|
+
should "be able to make a full request and response cycle" do
|
50
|
+
method = 'flickr.people.findByUsername'
|
51
|
+
params = {:username => 'foobar'}
|
52
|
+
|
53
|
+
response = stub(:error? => false)
|
54
|
+
|
55
|
+
MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
|
56
|
+
|
57
|
+
MethodRequest.with_response!(method, params).should == response
|
90
58
|
end
|
59
|
+
|
60
|
+
should "raise an exception when the full request / response cycle has errors" do
|
61
|
+
method = 'flickr.people.findByUsername'
|
62
|
+
params = {:username => 'foobar'}
|
63
|
+
|
64
|
+
response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
|
65
|
+
|
66
|
+
MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
|
67
|
+
|
68
|
+
lambda do
|
69
|
+
MethodRequest.with_response!('flickr.people.findByUsername', :username => 'foobar')
|
70
|
+
end.should raise_error(Fleakr::ApiError)
|
71
|
+
end
|
72
|
+
|
91
73
|
end
|
92
|
-
|
74
|
+
|
93
75
|
end
|
94
76
|
end
|
@@ -3,173 +3,192 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Api
|
4
4
|
class ParameterListTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
context "An instance of the ParameterList class" do
|
7
|
-
|
6
|
+
context "An instance of the ParameterList class with an available API key" do
|
8
7
|
setup do
|
9
|
-
@
|
10
|
-
@
|
11
|
-
|
12
|
-
Fleakr.stubs(:api_key).with().returns(@api_key)
|
8
|
+
@api_key_value = 'api_key_value'
|
9
|
+
Fleakr.stubs(:api_key).with().returns(@api_key_value)
|
10
|
+
|
13
11
|
@parameter_list = ParameterList.new
|
14
12
|
end
|
15
|
-
|
16
|
-
should "
|
17
|
-
@parameter_list
|
18
|
-
@parameter_list
|
19
|
-
@parameter_list[:api_key].include_in_signature?.should be(true)
|
13
|
+
|
14
|
+
should "send the authentication token by default if it is available" do
|
15
|
+
@parameter_list.stubs(:authentication_token).with().returns('toke')
|
16
|
+
@parameter_list.send_authentication_token?.should be(true)
|
20
17
|
end
|
21
18
|
|
22
|
-
should "
|
23
|
-
|
24
|
-
|
19
|
+
should "know not to send the authentication token" do
|
20
|
+
pl = ParameterList.new({}, false)
|
21
|
+
pl.stubs(:authentication_token).with().returns('toke')
|
22
|
+
|
23
|
+
pl.send_authentication_token?.should be(false)
|
25
24
|
end
|
26
25
|
|
27
|
-
should "
|
28
|
-
|
29
|
-
|
30
|
-
@parameter_list << parameter
|
31
|
-
@parameter_list['foo'].should == parameter
|
26
|
+
should "know not to send the authentication token if it's not available from the global value" do
|
27
|
+
@parameter_list.stubs(:authentication_token).with().returns(nil)
|
28
|
+
@parameter_list.send_authentication_token?.should be(false)
|
32
29
|
end
|
33
30
|
|
34
|
-
should "
|
35
|
-
|
36
|
-
@parameter_list << parameter
|
37
|
-
|
38
|
-
@parameter_list[:foo].should == parameter
|
31
|
+
should "have a default list of options" do
|
32
|
+
@parameter_list.default_options.should == {:api_key => @api_key_value}
|
39
33
|
end
|
40
34
|
|
41
|
-
should "
|
42
|
-
|
43
|
-
|
35
|
+
should "use the authentication_token in the options if we're to authenticate" do
|
36
|
+
@parameter_list.stubs(:send_authentication_token?).with().returns(true)
|
37
|
+
@parameter_list.stubs(:authentication_token).with().returns('toke')
|
38
|
+
@parameter_list.stubs(:default_options).with().returns({})
|
44
39
|
|
45
|
-
@parameter_list.
|
40
|
+
@parameter_list.options.should == {:auth_token => 'toke'}
|
46
41
|
end
|
47
42
|
|
48
|
-
should "
|
49
|
-
|
50
|
-
|
51
|
-
@parameter_list << ValueParameter.new('foo', 'bar')
|
52
|
-
@parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}foobar")
|
43
|
+
should "add additional options from the constructor" do
|
44
|
+
pl = ParameterList.new(:foo => 'bar')
|
45
|
+
pl.options.should == {:foo => 'bar', :api_key => @api_key_value}
|
53
46
|
end
|
54
47
|
|
55
|
-
should "
|
56
|
-
|
57
|
-
|
58
|
-
@parameter_list << ValueParameter.new('z', 'a')
|
59
|
-
@parameter_list << ValueParameter.new('a', 'z')
|
60
|
-
|
61
|
-
@parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}azapi_key#{@api_key}za")
|
48
|
+
should "know that it doesn't need to sign the request by default" do
|
49
|
+
@parameter_list.sign?.should be(false)
|
62
50
|
end
|
63
51
|
|
64
|
-
should "
|
65
|
-
Fleakr.
|
66
|
-
|
67
|
-
@parameter_list << ValueParameter.new('foo', 'bar')
|
68
|
-
@parameter_list << ValueParameter.new('yes', 'no', false)
|
69
|
-
|
70
|
-
@parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}foobar")
|
52
|
+
should "know that it needs to sign the request when a shared secret is available" do
|
53
|
+
Fleakr.expects(:shared_secret).with().returns('secrit')
|
54
|
+
@parameter_list.sign?.should be(true)
|
71
55
|
end
|
72
56
|
|
73
|
-
should "be able to
|
74
|
-
|
57
|
+
should "be able to add an option to the list" do
|
58
|
+
@parameter_list.stubs(:default_options).with().returns({})
|
75
59
|
|
76
|
-
@parameter_list.
|
77
|
-
@parameter_list.
|
60
|
+
@parameter_list.add_option(:foo, 'bar')
|
61
|
+
@parameter_list.options.should == {:foo => 'bar'}
|
78
62
|
end
|
79
63
|
|
80
|
-
should "
|
81
|
-
@parameter_list.
|
64
|
+
should "have an empty list of upload options by default" do
|
65
|
+
@parameter_list.upload_options.should == {}
|
82
66
|
end
|
83
67
|
|
84
|
-
should "
|
85
|
-
|
86
|
-
@parameter_list.
|
68
|
+
should "be able to add an upload option to the list" do
|
69
|
+
@parameter_list.add_upload_option(:file, '/path/to/foo')
|
70
|
+
@parameter_list.upload_options.should == {:file => '/path/to/foo'}
|
87
71
|
end
|
88
72
|
|
89
|
-
should "
|
90
|
-
@parameter_list.
|
73
|
+
should "be able to generate the list of parameters without a signature" do
|
74
|
+
@parameter_list.stubs(:options).with().returns({:foo => 'bar', :api_sig => '1234'})
|
75
|
+
@parameter_list.options_without_signature.should == {:foo => 'bar'}
|
91
76
|
end
|
92
77
|
|
93
|
-
should "
|
94
|
-
Fleakr.stubs(:
|
95
|
-
|
78
|
+
should "be able to calculate the signature of the parameters" do
|
79
|
+
Fleakr.stubs(:shared_secret).with().returns('sekrit')
|
80
|
+
|
81
|
+
options = {:api_key => @api_key_value, :foo => 'bar', :blip => 'zeeez'}
|
82
|
+
@parameter_list.stubs(:options_without_signature).with().returns(options)
|
96
83
|
|
97
|
-
parameter_list.
|
84
|
+
@parameter_list.signature.should == Digest::MD5.hexdigest("sekritapi_key#{@api_key_value}blipzeeezfoobar")
|
98
85
|
end
|
99
86
|
|
100
|
-
should "
|
101
|
-
|
87
|
+
should "be able to generate a list of options with a signature" do
|
88
|
+
parameters = [ValueParameter.new('foo', 'bar')]
|
89
|
+
|
90
|
+
@parameter_list.stubs(:options_without_signature).with().returns(:foo => 'bar')
|
91
|
+
@parameter_list.stubs(:signature).with().returns('sig')
|
102
92
|
|
103
|
-
parameter_list
|
104
|
-
parameter_list.authenticate?.should be(false)
|
93
|
+
@parameter_list.options_with_signature.should == {:foo => 'bar', :api_sig => 'sig'}
|
105
94
|
end
|
106
95
|
|
96
|
+
should "know the auth token when provided to the constructor" do
|
97
|
+
pl = ParameterList.new(:auth_token => 'toke')
|
98
|
+
pl.authentication_token.should == 'toke'
|
99
|
+
end
|
100
|
+
|
101
|
+
should "know the auth token when available as a global value" do
|
102
|
+
Fleakr.stubs(:auth_token).with().returns('toke')
|
103
|
+
|
104
|
+
pl = ParameterList.new
|
105
|
+
pl.authentication_token.should == 'toke'
|
106
|
+
end
|
107
107
|
|
108
|
-
should "know
|
109
|
-
Fleakr.
|
108
|
+
should "know that there is no authentication token if it is not available as a param or global value" do
|
109
|
+
Fleakr.stubs(:auth_token).with().returns(nil)
|
110
110
|
|
111
|
-
|
112
|
-
|
111
|
+
pl = ParameterList.new
|
112
|
+
pl.authentication_token.should be_nil
|
113
|
+
end
|
114
|
+
|
115
|
+
should "be able to generate a boundary for post data" do
|
116
|
+
rand = '0.123'
|
117
|
+
|
118
|
+
@parameter_list.stubs(:rand).with().returns(stub(:to_s => rand))
|
119
|
+
@parameter_list.boundary.should == Digest::MD5.hexdigest(rand)
|
120
|
+
end
|
121
|
+
|
122
|
+
should "be able to generate a list of parameters without a signature" do
|
123
|
+
parameter = stub()
|
124
|
+
|
125
|
+
@parameter_list.stubs(:sign?).with().returns(false)
|
126
|
+
@parameter_list.expects(:options_without_signature).with().returns(:foo => 'bar')
|
127
|
+
|
128
|
+
ValueParameter.expects(:new).with(:foo, 'bar').returns(parameter)
|
129
|
+
|
130
|
+
@parameter_list.list.should == [parameter]
|
113
131
|
end
|
114
132
|
|
115
|
-
should "
|
116
|
-
|
133
|
+
should "be able to generate a list of parameters with a signature" do
|
134
|
+
parameter = stub()
|
117
135
|
|
118
|
-
parameter_list
|
119
|
-
|
136
|
+
@parameter_list.stubs(:sign?).with().returns(true)
|
137
|
+
@parameter_list.expects(:options_with_signature).with().returns(:foo => 'bar')
|
138
|
+
|
139
|
+
ValueParameter.expects(:new).with(:foo, 'bar').returns(parameter)
|
120
140
|
|
121
|
-
|
122
|
-
auth_param.value.should == 'toke'
|
123
|
-
auth_param.include_in_signature?.should be(true)
|
141
|
+
@parameter_list.list.should == [parameter]
|
124
142
|
end
|
125
143
|
|
126
|
-
should "
|
127
|
-
|
144
|
+
should "be able to generate a list of parameters with upload parameters if available" do
|
145
|
+
value_parameter = stub()
|
146
|
+
file_parameter = stub()
|
128
147
|
|
129
|
-
parameter_list.stubs(:sign?).with().returns(true)
|
130
|
-
parameter_list.
|
148
|
+
@parameter_list.stubs(:sign?).with().returns(true)
|
149
|
+
@parameter_list.expects(:options_with_signature).with().returns(:foo => 'bar')
|
150
|
+
@parameter_list.expects(:upload_options).with().returns(:file => 'path')
|
131
151
|
|
132
|
-
|
152
|
+
ValueParameter.expects(:new).with(:foo, 'bar').returns(value_parameter)
|
153
|
+
FileParameter.expects(:new).with(:file, 'path').returns(file_parameter)
|
133
154
|
|
134
|
-
|
135
|
-
signature_param.value.should == 'sig'
|
136
|
-
signature_param.include_in_signature?.should be(false)
|
155
|
+
@parameter_list.list.should == [value_parameter, file_parameter]
|
137
156
|
end
|
138
|
-
|
157
|
+
|
139
158
|
context "with associated parameters" do
|
140
|
-
|
159
|
+
|
141
160
|
setup do
|
142
161
|
@p1 = ValueParameter.new('a', 'b')
|
143
162
|
@p2 = ValueParameter.new('c', 'd')
|
144
|
-
|
163
|
+
|
145
164
|
@p1.stubs(:to_query).with().returns('q1')
|
146
165
|
@p1.stubs(:to_form).with().returns('f1')
|
147
|
-
|
166
|
+
|
148
167
|
@p2.stubs(:to_query).with().returns('q2')
|
149
168
|
@p2.stubs(:to_form).with().returns('f2')
|
150
|
-
|
151
|
-
@parameter_list.stubs(:list).with().returns(
|
169
|
+
|
170
|
+
@parameter_list.stubs(:list).with().returns([@p1, @p2])
|
152
171
|
end
|
153
|
-
|
172
|
+
|
154
173
|
should "be able to generate a query representation of itself" do
|
155
174
|
@parameter_list.to_query.should == 'q1&q2'
|
156
175
|
end
|
157
|
-
|
176
|
+
|
158
177
|
should "be able to represent a form representation of itself" do
|
159
178
|
@parameter_list.stubs(:boundary).returns('bound')
|
160
|
-
|
179
|
+
|
161
180
|
expected =
|
162
181
|
"--bound\r\n" +
|
163
182
|
"f1" +
|
164
183
|
"--bound\r\n" +
|
165
184
|
"f2" +
|
166
185
|
"--bound--"
|
167
|
-
|
186
|
+
|
168
187
|
@parameter_list.to_form.should == expected
|
169
188
|
end
|
170
|
-
|
189
|
+
|
171
190
|
end
|
172
|
-
|
191
|
+
|
173
192
|
end
|
174
193
|
|
175
194
|
end
|