fleakr 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +88 -57
- data/Rakefile +28 -9
- data/lib/fleakr.rb +25 -31
- data/lib/fleakr/api/option.rb +34 -34
- data/lib/fleakr/api/parameter_list.rb +23 -23
- data/lib/fleakr/objects.rb +4 -1
- data/lib/fleakr/objects/metadata.rb +35 -0
- data/lib/fleakr/objects/metadata_collection.rb +36 -0
- data/lib/fleakr/objects/photo.rb +15 -11
- data/lib/fleakr/objects/set.rb +17 -13
- data/lib/fleakr/objects/url.rb +83 -0
- data/lib/fleakr/objects/user.rb +8 -0
- data/lib/fleakr/support.rb +3 -1
- data/lib/fleakr/support/attribute.rb +2 -2
- data/lib/fleakr/support/object.rb +44 -29
- data/lib/fleakr/support/url_expander.rb +37 -0
- data/lib/fleakr/support/utility.rb +66 -0
- data/lib/fleakr/version.rb +5 -5
- data/test/fixtures/photos.getExif.xml +362 -0
- data/test/test_helper.rb +44 -47
- data/test/unit/fleakr/api/authentication_request_test.rb +12 -12
- data/test/unit/fleakr/api/file_parameter_test.rb +15 -15
- data/test/unit/fleakr/api/method_request_test.rb +1 -1
- data/test/unit/fleakr/api/option_test.rb +44 -44
- data/test/unit/fleakr/api/parameter_list_test.rb +40 -40
- data/test/unit/fleakr/api/response_test.rb +10 -10
- data/test/unit/fleakr/api/upload_request_test.rb +28 -28
- data/test/unit/fleakr/api/value_parameter_test.rb +10 -10
- data/test/unit/fleakr/core_ext/false_class_test.rb +5 -5
- data/test/unit/fleakr/core_ext/hash_test.rb +9 -9
- data/test/unit/fleakr/core_ext/true_class_test.rb +5 -5
- data/test/unit/fleakr/objects/authentication_token_test.rb +23 -23
- data/test/unit/fleakr/objects/collection_test.rb +23 -23
- data/test/unit/fleakr/objects/comment_test.rb +15 -15
- data/test/unit/fleakr/objects/contact_test.rb +11 -11
- data/test/unit/fleakr/objects/error_test.rb +8 -8
- data/test/unit/fleakr/objects/group_test.rb +13 -13
- data/test/unit/fleakr/objects/image_test.rb +4 -4
- data/test/unit/fleakr/objects/metadata_collection_test.rb +55 -0
- data/test/unit/fleakr/objects/metadata_test.rb +27 -0
- data/test/unit/fleakr/objects/photo_context_test.rb +23 -23
- data/test/unit/fleakr/objects/photo_test.rb +71 -64
- data/test/unit/fleakr/objects/search_test.rb +22 -22
- data/test/unit/fleakr/objects/set_test.rb +62 -40
- data/test/unit/fleakr/objects/tag_test.rb +32 -31
- data/test/unit/fleakr/objects/url_test.rb +185 -0
- data/test/unit/fleakr/objects/user_test.rb +43 -16
- data/test/unit/fleakr/support/attribute_test.rb +15 -15
- data/test/unit/fleakr/support/object_test.rb +77 -33
- data/test/unit/fleakr/support/request_test.rb +12 -12
- data/test/unit/fleakr/support/url_expander_test.rb +44 -0
- data/test/unit/fleakr/support/utility_test.rb +70 -0
- data/test/unit/fleakr_test.rb +48 -41
- metadata +43 -23
@@ -1,12 +1,12 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class CommentTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
context "The Comment class" do
|
7
7
|
|
8
|
-
should_find_all :comments, :by => :photo_id, :call => 'photos.comments.getList', :path => 'rsp/comments/comment'
|
9
|
-
should_find_all :comments, :by => :set_id, :using => :photoset_id, :call => 'photosets.comments.getList', :path => 'rsp/comments/comment'
|
8
|
+
should_find_all :comments, :by => :photo_id, :call => 'photos.comments.getList', :path => 'rsp/comments/comment', :class => Comment
|
9
|
+
should_find_all :comments, :by => :set_id, :using => :photoset_id, :call => 'photosets.comments.getList', :path => 'rsp/comments/comment', :class => Comment
|
10
10
|
|
11
11
|
end
|
12
12
|
|
@@ -22,17 +22,17 @@ module Fleakr::Objects
|
|
22
22
|
should_have_a_value_for :created => '1239217523'
|
23
23
|
should_have_a_value_for :url => 'http://www.flickr.com/photos/frootpantz/3422268412/#comment72157616515348062'
|
24
24
|
should_have_a_value_for :body => 'comment one'
|
25
|
-
|
25
|
+
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
context "in general" do
|
29
|
-
|
29
|
+
|
30
30
|
setup { @comment = Comment.new }
|
31
31
|
|
32
32
|
should "have a value for :created_at" do
|
33
33
|
@comment.expects(:created).with().returns('1239217523')
|
34
34
|
Time.expects(:at).with(1239217523).returns('time')
|
35
|
-
|
35
|
+
|
36
36
|
@comment.created_at.should == 'time'
|
37
37
|
end
|
38
38
|
|
@@ -40,25 +40,25 @@ module Fleakr::Objects
|
|
40
40
|
@comment.expects(:body).with().returns('bod')
|
41
41
|
@comment.to_s.should == 'bod'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
should "be able to find the author of the comment" do
|
45
45
|
author = stub()
|
46
|
-
|
47
|
-
|
46
|
+
|
47
|
+
|
48
48
|
@comment.stubs(:author_id).with().returns('1')
|
49
49
|
User.expects(:find_by_id).with('1').returns(author)
|
50
|
-
|
50
|
+
|
51
51
|
@comment.author.should == author
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
should "memoize the owner information" do
|
55
55
|
@comment.stubs(:author_id).with().returns('1')
|
56
|
-
|
56
|
+
|
57
57
|
User.expects(:find_by_id).with('1').once.returns(stub())
|
58
|
-
|
58
|
+
|
59
59
|
2.times { @comment.author }
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ContactTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
context "The Contact class" do
|
7
|
-
|
7
|
+
|
8
8
|
should "return a list of users for a specified user's contacts" do
|
9
9
|
user_1, user_2 = stub(), stub()
|
10
10
|
|
@@ -19,7 +19,7 @@ module Fleakr::Objects
|
|
19
19
|
|
20
20
|
Contact.find_all_by_user_id('1').should == [user_1, user_2]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
should "return a list of users for an authenticated user" do
|
24
24
|
response = mock_request_cycle :for => 'contacts.getList', :with => {}
|
25
25
|
contact_1, contact_2 = [stub("contact"), stub('contact')]
|
@@ -29,7 +29,7 @@ module Fleakr::Objects
|
|
29
29
|
Contact.stubs(:new).with(contact_2_doc).returns(@contact_2)
|
30
30
|
Contact.find_all.should == [@user_1, @user_2]
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
34
34
|
|
35
35
|
context "An instance of the Contact class" do
|
@@ -44,7 +44,7 @@ module Fleakr::Objects
|
|
44
44
|
should_have_a_value_for :icon_farm => '3'
|
45
45
|
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
context "when populating from an XML document with authenticated user's contacts" do
|
49
49
|
setup do
|
50
50
|
@object = Contact.new(Hpricot.XML(read_fixture('contacts.getList')).at('contacts/contact'))
|
@@ -61,24 +61,24 @@ module Fleakr::Objects
|
|
61
61
|
|
62
62
|
|
63
63
|
context "in general" do
|
64
|
-
|
64
|
+
|
65
65
|
should "be able to convert to a user" do
|
66
66
|
contact = Contact.new
|
67
67
|
user = mock()
|
68
|
-
|
68
|
+
|
69
69
|
User.stubs(:new).returns(user)
|
70
|
-
|
70
|
+
|
71
71
|
[:id, :username, :icon_server, :icon_farm, :name, :location].each do |method|
|
72
72
|
contact.stubs(method).with().returns(method.to_s)
|
73
73
|
user.expects("#{method}=".to_sym).with(method.to_s)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
contact.to_user.should == user
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
end
|
80
80
|
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
end
|
84
84
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ErrorTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
context "An instance of the Error class" do
|
7
|
-
|
7
|
+
|
8
8
|
should "have a code and a message" do
|
9
9
|
response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
|
10
|
-
|
10
|
+
|
11
11
|
error = Error.new(Hpricot.XML(response_xml))
|
12
|
-
|
12
|
+
|
13
13
|
error.code.should == '1'
|
14
14
|
error.message.should == 'User not found'
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
|
20
20
|
end
|
21
21
|
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class GroupTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
should_have_many :photos
|
7
|
-
|
6
|
+
should_have_many :photos, :class => Photo
|
7
|
+
|
8
8
|
should_search_by :group_id
|
9
9
|
|
10
10
|
context "The Group class" do
|
11
|
-
|
12
|
-
should_find_all :groups, :by => :user_id, :call => 'people.getPublicGroups', :path => 'rsp/groups/group'
|
13
|
-
|
11
|
+
|
12
|
+
should_find_all :groups, :by => :user_id, :call => 'people.getPublicGroups', :path => 'rsp/groups/group', :class => Group
|
13
|
+
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
context "An instance of the Group class" do
|
17
17
|
context "when initializing from an Hpricot document" do
|
18
|
-
|
18
|
+
|
19
19
|
setup do
|
20
20
|
doc = Hpricot.XML(read_fixture('people.getPublicGroups')).at('rsp/groups/group')
|
21
21
|
@object = Group.new(doc)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
should_have_a_value_for :id => '13378274@N00'
|
25
25
|
should_have_a_value_for :name => 'Group #1'
|
26
26
|
should_have_a_value_for :adult_flag => '1'
|
27
|
-
|
27
|
+
|
28
28
|
end
|
29
29
|
|
30
30
|
should "know that the group is adult-only" do
|
@@ -32,15 +32,15 @@ module Fleakr::Objects
|
|
32
32
|
group.stubs(:adult_flag).with().returns('1')
|
33
33
|
group.adult?.should be(true)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should "know that the group is not adult-only" do
|
37
37
|
group = Group.new
|
38
38
|
group.stubs(:adult_flag).with().returns('0')
|
39
39
|
group.adult?.should be(false)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ImageTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
context "The Image class" do
|
7
7
|
|
8
|
-
should_find_all :images, :by => :photo_id, :call => 'photos.getSizes', :path => 'sizes/size'
|
8
|
+
should_find_all :images, :by => :photo_id, :call => 'photos.getSizes', :path => 'sizes/size', :class => Image
|
9
9
|
|
10
10
|
end
|
11
11
|
|
@@ -45,7 +45,7 @@ module Fleakr::Objects
|
|
45
45
|
@image = Image.new
|
46
46
|
@image.stubs(:url).with().returns(@url)
|
47
47
|
@image.stubs(:filename).with().returns(@image_filename)
|
48
|
-
|
48
|
+
|
49
49
|
@image_data = 'image_data'
|
50
50
|
Net::HTTP.expects(:get).with(URI.parse(@url)).returns(@image_data)
|
51
51
|
end
|
@@ -67,7 +67,7 @@ module Fleakr::Objects
|
|
67
67
|
@image.save_to(existing_file)
|
68
68
|
File.read(existing_file).should == @image_data
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
should "be able to save the file using a specified prefix" do
|
72
72
|
@image.save_to(@tmp_dir, '001_')
|
73
73
|
File.read("#{@tmp_dir}/001_image.jpg").should == @image_data
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class MetadataCollectionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the MetadataCollection class" do
|
7
|
+
|
8
|
+
should "have a photo" do
|
9
|
+
photo = stub()
|
10
|
+
collection = MetadataCollection.new(photo)
|
11
|
+
|
12
|
+
collection.photo.should == photo
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with a photo" do
|
16
|
+
setup do
|
17
|
+
@photo = stub(:id => '1')
|
18
|
+
@collection = MetadataCollection.new(@photo)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "be able to fetch the metadata" do
|
22
|
+
element = stub(:label => 'Label')
|
23
|
+
Metadata.expects(:find_all_by_photo_id).with(@photo.id).returns([element])
|
24
|
+
|
25
|
+
@collection.data.should == {'Label' => element}
|
26
|
+
end
|
27
|
+
|
28
|
+
should "know the keys for the metadata" do
|
29
|
+
@collection.stubs(:data).with().returns({'One' => nil, 'Two' => nil})
|
30
|
+
@collection.keys.sort.should == ['One', 'Two']
|
31
|
+
end
|
32
|
+
|
33
|
+
should "be able to access an individual value by key" do
|
34
|
+
@collection.stubs(:data).with().returns({'FileSize' => stub(:raw => '3.2 MB')})
|
35
|
+
@collection['FileSize'].should == '3.2 MB'
|
36
|
+
end
|
37
|
+
|
38
|
+
should "be able to iterate over items in the collection" do
|
39
|
+
element_1 = stub()
|
40
|
+
element_2 = stub()
|
41
|
+
|
42
|
+
data = {'One' => element_1, 'Two' => element_2}
|
43
|
+
iterated = {}
|
44
|
+
|
45
|
+
@collection.stubs(:data).with().returns(data)
|
46
|
+
@collection.each {|key, value| iterated[key] = value }
|
47
|
+
|
48
|
+
iterated.should == data
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class MetadataTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Metadata class" do
|
7
|
+
should_find_all :metadata, :class => Metadata, :by => :photo_id, :call => 'photos.getExif', :path => 'rsp/photo/exif'
|
8
|
+
end
|
9
|
+
|
10
|
+
context "An instance of the Metadata class" do
|
11
|
+
|
12
|
+
context "when populating from the photos_getExif XML data" do
|
13
|
+
setup do
|
14
|
+
@object = Metadata.new(Hpricot.XML(read_fixture('photos.getExif')).at('rsp/photo/exif'))
|
15
|
+
end
|
16
|
+
|
17
|
+
should_have_a_value_for :tagspace => 'System'
|
18
|
+
should_have_a_value_for :tag => 'FileName'
|
19
|
+
should_have_a_value_for :label => 'FileName'
|
20
|
+
should_have_a_value_for :raw => 'ORI9141194487814365231.img'
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class PhotoContextTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
context "An instance of the PhotoContext class" do
|
7
|
-
|
7
|
+
|
8
8
|
setup { @context = PhotoContext.new }
|
9
|
-
|
9
|
+
|
10
10
|
context "when populating from the photos_getContext XML data" do
|
11
11
|
setup do
|
12
12
|
@object = PhotoContext.new(Hpricot.XML(read_fixture('photos.getContext')))
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should_have_a_value_for :count => '5584'
|
16
16
|
should_have_a_value_for :next_id => '12343'
|
17
17
|
should_have_a_value_for :previous_id => '12345'
|
18
18
|
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
should "know that there is a previous photo" do
|
22
22
|
@context.expects(:previous_id).with().returns('1')
|
23
23
|
@context.previous?.should be(true)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
should "know that there isn't a previous photo" do
|
27
27
|
@context.expects(:previous_id).with().returns('0')
|
28
28
|
@context.previous?.should be(false)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
should "know that there is a next photo" do
|
32
32
|
@context.expects(:next_id).with().returns('1')
|
33
33
|
@context.next?.should be(true)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should "know that there isn't a next photo" do
|
37
37
|
@context.expects(:next_id).with().returns('0')
|
38
38
|
@context.next?.should be(false)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
should "find the previous photo" do
|
42
42
|
photo = stub()
|
43
|
-
|
43
|
+
|
44
44
|
@context.expects(:previous_id).with().returns('1')
|
45
45
|
@context.expects(:previous?).with().returns(true)
|
46
|
-
|
46
|
+
|
47
47
|
Photo.expects(:find_by_id).with('1').returns(photo)
|
48
|
-
|
48
|
+
|
49
49
|
@context.previous.should == photo
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
should "not try to find the previous photo if it doesn't exist" do
|
53
53
|
@context.expects(:previous?).with().returns(false)
|
54
54
|
Photo.expects(:find_by_id).never
|
55
|
-
|
55
|
+
|
56
56
|
@context.previous.should be(nil)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
should "find the next photo" do
|
60
60
|
photo = stub()
|
61
61
|
@context.expects(:next_id).with().returns('1')
|
62
62
|
@context.expects(:next?).with().returns(true)
|
63
|
-
|
63
|
+
|
64
64
|
Photo.expects(:find_by_id).with('1').returns(photo)
|
65
|
-
|
65
|
+
|
66
66
|
@context.next.should == photo
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
should "not try to find the next photo if it doesn't exist" do
|
70
70
|
@context.expects(:next?).with().returns(false)
|
71
71
|
Photo.expects(:find_by_id).never
|
72
|
-
|
72
|
+
|
73
73
|
@context.next.should be(nil)
|
74
74
|
end
|
75
|
-
|
76
|
-
|
75
|
+
|
76
|
+
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
end
|
80
80
|
end
|