fleakr 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +32 -5
- data/Rakefile +1 -1
- data/lib/fleakr.rb +34 -6
- data/lib/fleakr/api.rb +1 -0
- data/lib/fleakr/api/method_request.rb +9 -4
- data/lib/fleakr/api/option.rb +175 -0
- data/lib/fleakr/api/parameter_list.rb +7 -6
- data/lib/fleakr/api/upload_request.rb +17 -11
- data/lib/fleakr/core_ext.rb +3 -1
- data/lib/fleakr/core_ext/false_class.rb +7 -0
- data/lib/fleakr/core_ext/true_class.rb +7 -0
- data/lib/fleakr/objects/authentication_token.rb +25 -8
- data/lib/fleakr/objects/photo.rb +21 -6
- data/lib/fleakr/support/object.rb +4 -2
- data/lib/fleakr/version.rb +1 -1
- data/test/fixtures/auth.getToken.xml +8 -0
- data/test/unit/fleakr/api/method_request_test.rb +0 -10
- data/test/unit/fleakr/api/option_test.rb +179 -0
- data/test/unit/fleakr/api/parameter_list_test.rb +33 -18
- data/test/unit/fleakr/api/upload_request_test.rb +21 -9
- data/test/unit/fleakr/core_ext/false_class_test.rb +13 -0
- data/test/unit/fleakr/core_ext/true_class_test.rb +13 -0
- data/test/unit/fleakr/objects/authentication_token_test.rb +16 -2
- data/test/unit/fleakr/objects/photo_test.rb +22 -8
- data/test/unit/fleakr_test.rb +72 -4
- metadata +10 -3
@@ -10,6 +10,17 @@ module Fleakr::Api
|
|
10
10
|
Fleakr.stubs(:shared_secret).with().returns(@secret)
|
11
11
|
end
|
12
12
|
|
13
|
+
it "should have a collection of upload_options" do
|
14
|
+
request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)})
|
15
|
+
|
16
|
+
option_1, option_2 = [stub(:to_hash => {:one => 'value_1'}), stub(:to_hash => {:two => 'value_2'})]
|
17
|
+
|
18
|
+
Option.expects(:for).with(:title, 'foo').returns(option_1)
|
19
|
+
Option.expects(:for).with(:tags, %w(a b)).returns(option_2)
|
20
|
+
|
21
|
+
request.upload_options.should == {:one => 'value_1', :two => 'value_2'}
|
22
|
+
end
|
23
|
+
|
13
24
|
it "should create a file parameter on initialization" do
|
14
25
|
filename = '/path/to/image.jpg'
|
15
26
|
|
@@ -17,17 +28,18 @@ module Fleakr::Api
|
|
17
28
|
FileParameter.expects(:new).with('photo', filename).returns(parameter)
|
18
29
|
|
19
30
|
parameter_list = mock() {|m| m.expects(:<<).with(parameter) }
|
20
|
-
ParameterList.expects(:new).with(
|
31
|
+
ParameterList.expects(:new).with({}).returns(parameter_list)
|
21
32
|
|
22
33
|
UploadRequest.new(filename)
|
23
34
|
end
|
24
35
|
|
25
|
-
it "should allow setting
|
26
|
-
|
36
|
+
it "should allow setting options on initialization" do
|
37
|
+
option = stub {|s| s.stubs(:to_hash).with().returns({:title => 'foo'})}
|
38
|
+
Option.expects(:for).with(:title, 'foo').returns(option)
|
27
39
|
|
28
|
-
ParameterList.expects(:new).with({:
|
40
|
+
ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:<<))
|
29
41
|
|
30
|
-
UploadRequest.new('filename',
|
42
|
+
UploadRequest.new('filename', :create, {:title => 'foo'})
|
31
43
|
end
|
32
44
|
|
33
45
|
context "after initialization" do
|
@@ -40,7 +52,7 @@ module Fleakr::Api
|
|
40
52
|
end
|
41
53
|
|
42
54
|
it "should allow setting the type to :update" do
|
43
|
-
request = UploadRequest.new('file', :
|
55
|
+
request = UploadRequest.new('file', :update)
|
44
56
|
request.type.should == :update
|
45
57
|
end
|
46
58
|
|
@@ -50,7 +62,7 @@ module Fleakr::Api
|
|
50
62
|
end
|
51
63
|
|
52
64
|
it "should know the endpoint_uri for an :update request" do
|
53
|
-
request = UploadRequest.new('filename', :
|
65
|
+
request = UploadRequest.new('filename', :update)
|
54
66
|
request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/')
|
55
67
|
end
|
56
68
|
|
@@ -110,7 +122,7 @@ module Fleakr::Api
|
|
110
122
|
filename = 'filename'
|
111
123
|
response = stub(:error? => false)
|
112
124
|
|
113
|
-
UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
|
125
|
+
UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response))
|
114
126
|
UploadRequest.with_response!(filename).should == response
|
115
127
|
end
|
116
128
|
|
@@ -118,7 +130,7 @@ module Fleakr::Api
|
|
118
130
|
filename = 'filename'
|
119
131
|
response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
|
120
132
|
|
121
|
-
UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
|
133
|
+
UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response))
|
122
134
|
|
123
135
|
lambda do
|
124
136
|
UploadRequest.with_response!(filename)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
class FalseClassTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
describe "An instance of the FalseClass class" do
|
6
|
+
|
7
|
+
it "should have 0 as its integer value" do
|
8
|
+
false.to_i.should == 0
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -9,7 +9,7 @@ module Fleakr::Objects
|
|
9
9
|
token = '123-123-123'
|
10
10
|
auth_token = stub()
|
11
11
|
|
12
|
-
response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :
|
12
|
+
response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :authenticate? => false}
|
13
13
|
|
14
14
|
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
15
15
|
|
@@ -20,12 +20,23 @@ module Fleakr::Objects
|
|
20
20
|
token = 'abc123'
|
21
21
|
auth_token = stub()
|
22
22
|
|
23
|
-
response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :
|
23
|
+
response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :authenticate? => false}
|
24
24
|
|
25
25
|
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
26
26
|
AuthenticationToken.from_auth_token(token).should == auth_token
|
27
27
|
end
|
28
28
|
|
29
|
+
|
30
|
+
it "should be able to create an instance from a frob" do
|
31
|
+
frob = '12345678901234567-abcde89012fg3456-7890123'
|
32
|
+
auth_token = stub()
|
33
|
+
|
34
|
+
response = mock_request_cycle :for => 'auth.getToken', :with => {:frob => frob, :authenticate? => false}
|
35
|
+
|
36
|
+
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
37
|
+
AuthenticationToken.from_frob(frob).should == auth_token
|
38
|
+
end
|
39
|
+
|
29
40
|
end
|
30
41
|
|
31
42
|
describe "An instance of the AuthenticationToken class" do
|
@@ -38,6 +49,9 @@ module Fleakr::Objects
|
|
38
49
|
|
39
50
|
should_have_a_value_for :value => 'abc-123'
|
40
51
|
should_have_a_value_for :permissions => 'delete'
|
52
|
+
should_have_a_value_for :user_id => '31066442@N69'
|
53
|
+
should_have_a_value_for :full_name => 'Sir Froot Pants'
|
54
|
+
should_have_a_value_for :user_name => 'frootpantz'
|
41
55
|
|
42
56
|
end
|
43
57
|
|
@@ -16,7 +16,7 @@ module Fleakr::Objects
|
|
16
16
|
|
17
17
|
should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo'
|
18
18
|
|
19
|
-
|
19
|
+
# TODO: refactor these 2 tests
|
20
20
|
it "should be able to upload a photo and return the new photo information" do
|
21
21
|
filename = '/path/to/mugshot.jpg'
|
22
22
|
photo = stub()
|
@@ -25,11 +25,25 @@ module Fleakr::Objects
|
|
25
25
|
s.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
26
26
|
end
|
27
27
|
|
28
|
-
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename).returns(response)
|
29
|
-
Photo.expects(:find_by_id).with('123'
|
28
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
|
29
|
+
Photo.expects(:find_by_id).with('123').returns(photo)
|
30
30
|
|
31
31
|
Photo.upload(filename).should == photo
|
32
32
|
end
|
33
|
+
|
34
|
+
it "should be able to pass additional options when uploading a new file" do
|
35
|
+
filename = '/path/to/mugshot.jpg'
|
36
|
+
photo = stub()
|
37
|
+
|
38
|
+
response = stub do |s|
|
39
|
+
s.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
40
|
+
end
|
41
|
+
|
42
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
|
43
|
+
Photo.expects(:find_by_id).with('123').returns(photo)
|
44
|
+
|
45
|
+
Photo.upload(filename, :title => 'foo').should == photo
|
46
|
+
end
|
33
47
|
|
34
48
|
end
|
35
49
|
|
@@ -39,9 +53,9 @@ module Fleakr::Objects
|
|
39
53
|
filename = '/path/to/file.jpg'
|
40
54
|
response = stub(:body => 'body')
|
41
55
|
|
42
|
-
params = {:
|
56
|
+
params = {:photo_id => '1'}
|
43
57
|
|
44
|
-
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, params).returns(response)
|
58
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :update, params).returns(response)
|
45
59
|
|
46
60
|
photo = Photo.new
|
47
61
|
photo.stubs(:id).returns('1')
|
@@ -110,17 +124,17 @@ module Fleakr::Objects
|
|
110
124
|
|
111
125
|
it "should have a value for :posted_at" do
|
112
126
|
@photo.expects(:posted).with().returns("#{@time.to_i}")
|
113
|
-
@photo.posted_at.should == @time
|
127
|
+
@photo.posted_at.to_s.should == @time.to_s
|
114
128
|
end
|
115
129
|
|
116
130
|
it "should have a value for :taken_at" do
|
117
131
|
@photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
|
118
|
-
@photo.taken_at.should == @time
|
132
|
+
@photo.taken_at.to_s.should == @time.to_s
|
119
133
|
end
|
120
134
|
|
121
135
|
it "should have a value for :updated_at" do
|
122
136
|
@photo.expects(:updated).with().returns("#{@time.to_i}")
|
123
|
-
@photo.updated_at.should == @time
|
137
|
+
@photo.updated_at.to_s.should == @time.to_s
|
124
138
|
end
|
125
139
|
|
126
140
|
it "should have a collection of images by size" do
|
data/test/unit/fleakr_test.rb
CHANGED
@@ -41,18 +41,63 @@ class FleakrTest < Test::Unit::TestCase
|
|
41
41
|
Fleakr.search(:tags => %w(one two))
|
42
42
|
end
|
43
43
|
|
44
|
+
# TODO: refactor uploading tests?
|
44
45
|
it "should be able to upload a collection of images" do
|
45
46
|
glob = '*.jpg'
|
46
47
|
filenames = %w(one.jpg two.jpg)
|
47
48
|
|
48
49
|
Dir.expects(:[]).with(glob).returns(filenames)
|
49
50
|
|
50
|
-
Fleakr::Objects::Photo.expects(:upload).with('one.jpg')
|
51
|
-
Fleakr::Objects::Photo.expects(:upload).with('two.jpg')
|
51
|
+
Fleakr::Objects::Photo.expects(:upload).with('one.jpg', {})
|
52
|
+
Fleakr::Objects::Photo.expects(:upload).with('two.jpg', {})
|
52
53
|
|
53
54
|
Fleakr.upload(glob)
|
54
55
|
end
|
55
56
|
|
57
|
+
it "should return recently uploaded photos" do
|
58
|
+
filename = '/path/to/image.jpg'
|
59
|
+
new_image = stub()
|
60
|
+
|
61
|
+
Dir.expects(:[]).with(filename).returns([filename])
|
62
|
+
Fleakr::Objects::Photo.expects(:upload).with(filename, {}).returns(new_image)
|
63
|
+
|
64
|
+
Fleakr.upload(filename).should == [new_image]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to pass options for the uploaded files" do
|
68
|
+
filename = '/path/to/image.jpg'
|
69
|
+
new_image = stub()
|
70
|
+
|
71
|
+
Dir.expects(:[]).with(filename).returns([filename])
|
72
|
+
Fleakr::Objects::Photo.expects(:upload).with(filename, :title => 'bop bip').returns(new_image)
|
73
|
+
|
74
|
+
Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to reset the cached token" do
|
78
|
+
@token = stub()
|
79
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
|
80
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
|
81
|
+
Fleakr.token # once
|
82
|
+
Fleakr.reset_token
|
83
|
+
Fleakr.token # twice
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not have a token by default" do
|
87
|
+
Fleakr.expects(:mini_token).with().returns(nil)
|
88
|
+
Fleakr.expects(:auth_token).with().returns(nil)
|
89
|
+
Fleakr.expects(:frob).with().returns(nil)
|
90
|
+
|
91
|
+
Fleakr.token.should be(nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
[:mini_token, :auth_token, :frob].each do |attribute|
|
95
|
+
it "should reset_token when :#{attribute} is set" do
|
96
|
+
Fleakr.expects(:reset_token).with().at_least_once
|
97
|
+
Fleakr.send("#{attribute}=".to_sym, 'value')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
56
101
|
context "when generating an AuthenticationToken from an auth_token string" do
|
57
102
|
|
58
103
|
before do
|
@@ -63,7 +108,30 @@ class FleakrTest < Test::Unit::TestCase
|
|
63
108
|
end
|
64
109
|
|
65
110
|
# Make sure to clear the cache
|
66
|
-
after { Fleakr.
|
111
|
+
after { Fleakr.auth_token = nil }
|
112
|
+
|
113
|
+
it "should return the token" do
|
114
|
+
Fleakr.token.should == @token
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should cache the result" do
|
118
|
+
2.times { Fleakr.token }
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when generating an AuthenticationToken from a frob string" do
|
124
|
+
|
125
|
+
before do
|
126
|
+
@token = stub()
|
127
|
+
|
128
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
|
129
|
+
Fleakr.expects(:frob).with().at_least_once.returns('abc123')
|
130
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Make sure to clear the cache
|
134
|
+
after { Fleakr.frob = nil }
|
67
135
|
|
68
136
|
it "should return the token" do
|
69
137
|
Fleakr.token.should == @token
|
@@ -86,7 +154,7 @@ class FleakrTest < Test::Unit::TestCase
|
|
86
154
|
end
|
87
155
|
|
88
156
|
# Make sure to clear the cache
|
89
|
-
after { Fleakr.
|
157
|
+
after { Fleakr.mini_token = nil }
|
90
158
|
|
91
159
|
it "should return the token" do
|
92
160
|
Fleakr.token.should == @token
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleakr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Reagan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: "2.0"
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: loggable
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/fleakr/api
|
58
58
|
- lib/fleakr/api/file_parameter.rb
|
59
59
|
- lib/fleakr/api/method_request.rb
|
60
|
+
- lib/fleakr/api/option.rb
|
60
61
|
- lib/fleakr/api/parameter.rb
|
61
62
|
- lib/fleakr/api/parameter_list.rb
|
62
63
|
- lib/fleakr/api/response.rb
|
@@ -64,7 +65,9 @@ files:
|
|
64
65
|
- lib/fleakr/api/value_parameter.rb
|
65
66
|
- lib/fleakr/api.rb
|
66
67
|
- lib/fleakr/core_ext
|
68
|
+
- lib/fleakr/core_ext/false_class.rb
|
67
69
|
- lib/fleakr/core_ext/hash.rb
|
70
|
+
- lib/fleakr/core_ext/true_class.rb
|
68
71
|
- lib/fleakr/core_ext.rb
|
69
72
|
- lib/fleakr/objects
|
70
73
|
- lib/fleakr/objects/authentication_token.rb
|
@@ -86,6 +89,7 @@ files:
|
|
86
89
|
- test/fixtures
|
87
90
|
- test/fixtures/auth.checkToken.xml
|
88
91
|
- test/fixtures/auth.getFullToken.xml
|
92
|
+
- test/fixtures/auth.getToken.xml
|
89
93
|
- test/fixtures/contacts.getPublicList.xml
|
90
94
|
- test/fixtures/groups.pools.getPhotos.xml
|
91
95
|
- test/fixtures/people.findByEmail.xml
|
@@ -104,13 +108,16 @@ files:
|
|
104
108
|
- test/unit/fleakr/api
|
105
109
|
- test/unit/fleakr/api/file_parameter_test.rb
|
106
110
|
- test/unit/fleakr/api/method_request_test.rb
|
111
|
+
- test/unit/fleakr/api/option_test.rb
|
107
112
|
- test/unit/fleakr/api/parameter_list_test.rb
|
108
113
|
- test/unit/fleakr/api/parameter_test.rb
|
109
114
|
- test/unit/fleakr/api/response_test.rb
|
110
115
|
- test/unit/fleakr/api/upload_request_test.rb
|
111
116
|
- test/unit/fleakr/api/value_parameter_test.rb
|
112
117
|
- test/unit/fleakr/core_ext
|
118
|
+
- test/unit/fleakr/core_ext/false_class_test.rb
|
113
119
|
- test/unit/fleakr/core_ext/hash_test.rb
|
120
|
+
- test/unit/fleakr/core_ext/true_class_test.rb
|
114
121
|
- test/unit/fleakr/objects
|
115
122
|
- test/unit/fleakr/objects/authentication_token_test.rb
|
116
123
|
- test/unit/fleakr/objects/contact_test.rb
|