reagent-fleakr 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/lib/fleakr/group.rb +1 -4
- data/lib/fleakr/object.rb +37 -0
- data/lib/fleakr/photo.rb +2 -9
- data/lib/fleakr/search.rb +0 -2
- data/lib/fleakr/set.rb +3 -8
- data/lib/fleakr/user.rb +5 -27
- data/lib/fleakr/version.rb +1 -1
- data/lib/fleakr.rb +1 -0
- data/test/fleakr/set_test.rb +2 -20
- data/test/fleakr/user_test.rb +3 -44
- data/test/test_helper.rb +29 -1
- metadata +11 -2
data/Rakefile
CHANGED
data/lib/fleakr/group.rb
CHANGED
@@ -6,10 +6,7 @@ module Fleakr
|
|
6
6
|
flickr_attribute :id, :attribute => 'nsid'
|
7
7
|
flickr_attribute :name, :attribute => 'name'
|
8
8
|
|
9
|
-
|
10
|
-
response = Request.with_response!('people.getPublicGroups', :user_id => user_id)
|
11
|
-
(response.body/'rsp/groups/group').map {|g| Group.new(g) }
|
12
|
-
end
|
9
|
+
find_all :by_user_id, :call => 'people.getPublicGroups', :path => 'groups/group'
|
13
10
|
|
14
11
|
end
|
15
12
|
end
|
data/lib/fleakr/object.rb
CHANGED
@@ -12,6 +12,43 @@ module Fleakr
|
|
12
12
|
class_eval "attr_reader :#{name}"
|
13
13
|
end
|
14
14
|
|
15
|
+
def has_many(*attributes)
|
16
|
+
options = attributes.extract_options!
|
17
|
+
class_name = self.name
|
18
|
+
|
19
|
+
attributes.each do |attribute|
|
20
|
+
target = attribute.to_s.classify
|
21
|
+
finder_attribute = options[:using].nil? ? "#{class_name.demodulize.underscore}_id": options[:using]
|
22
|
+
class_eval <<-CODE
|
23
|
+
def #{attribute}
|
24
|
+
@#{attribute} ||= #{target}.send("find_all_by_#{finder_attribute}".to_sym, self.id)
|
25
|
+
end
|
26
|
+
CODE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_all(condition, options)
|
31
|
+
attribute = options[:using].nil? ? condition.to_s.sub(/^by_/, '') : options[:using]
|
32
|
+
|
33
|
+
class_eval <<-CODE
|
34
|
+
def self.find_all_#{condition}(value)
|
35
|
+
response = Request.with_response!('#{options[:call]}', :#{attribute} => value)
|
36
|
+
(response.body/'rsp/#{options[:path]}').map {|e| #{self.name}.new(e) }
|
37
|
+
end
|
38
|
+
CODE
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_one(condition, options)
|
42
|
+
attribute = options[:using].nil? ? condition.to_s.sub(/^by_/, '') : options[:using]
|
43
|
+
|
44
|
+
class_eval <<-CODE
|
45
|
+
def self.find_#{condition}(value)
|
46
|
+
response = Request.with_response!('#{options[:call]}', :#{attribute} => value)
|
47
|
+
#{self.name}.new(response.body)
|
48
|
+
end
|
49
|
+
CODE
|
50
|
+
end
|
51
|
+
|
15
52
|
end
|
16
53
|
|
17
54
|
module InstanceMethods
|
data/lib/fleakr/photo.rb
CHANGED
@@ -9,15 +9,8 @@ module Fleakr
|
|
9
9
|
flickr_attribute :server_id, :attribute => 'server'
|
10
10
|
flickr_attribute :secret, :attribute => 'secret'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
(response.body/'rsp/photoset/photo').map {|p| Photo.new(p) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.find_all_by_user_id(user_id)
|
18
|
-
response = Request.with_response!('people.getPublicPhotos', :user_id => user_id)
|
19
|
-
(response.body/'rsp/photos/photo').map {|p| Photo.new(p) }
|
20
|
-
end
|
12
|
+
find_all :by_photoset_id, :call => 'photosets.getPhotos', :path => 'photoset/photo'
|
13
|
+
find_all :by_user_id, :call => 'people.getPublicPhotos', :path => 'photos/photo'
|
21
14
|
|
22
15
|
def base_url
|
23
16
|
"http://farm#{self.farm_id}.static.flickr.com/#{self.server_id}/#{self.id}_#{self.secret}"
|
data/lib/fleakr/search.rb
CHANGED
data/lib/fleakr/set.rb
CHANGED
@@ -2,19 +2,14 @@ module Fleakr
|
|
2
2
|
class Set
|
3
3
|
|
4
4
|
include Fleakr::Object
|
5
|
+
|
6
|
+
has_many :photos, :using => :photoset_id
|
5
7
|
|
6
8
|
flickr_attribute :id, :attribute => 'id'
|
7
9
|
flickr_attribute :title
|
8
10
|
flickr_attribute :description
|
9
11
|
|
10
|
-
|
11
|
-
response = Request.with_response!('photosets.getList', :user_id => user_id)
|
12
|
-
(response.body/'rsp/photosets/photoset').map {|s| Set.new(s) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def photos
|
16
|
-
@photos ||= Photo.find_all_by_photoset_id(self.id)
|
17
|
-
end
|
12
|
+
find_all :by_user_id, :call => 'photosets.getList', :path => 'photosets/photoset'
|
18
13
|
|
19
14
|
def save_to(path, size)
|
20
15
|
target = "#{path}/#{self.title}"
|
data/lib/fleakr/user.rb
CHANGED
@@ -10,21 +10,11 @@ module Fleakr
|
|
10
10
|
flickr_attribute :photos_count, :xpath => 'rsp/person/photos/count'
|
11
11
|
flickr_attribute :icon_server, :xpath => 'rsp/person', :attribute => 'iconserver'
|
12
12
|
flickr_attribute :icon_farm, :xpath => 'rsp/person', :attribute => 'iconfarm'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def self.find_by_username(username)
|
20
|
-
response = Request.with_response!('people.findByUsername', :username => username)
|
21
|
-
User.new(response.body)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.find_by_email(email)
|
25
|
-
response = Request.with_response!('people.findByEmail', :find_email => email)
|
26
|
-
User.new(response.body)
|
27
|
-
end
|
13
|
+
|
14
|
+
has_many :sets, :groups, :photos
|
15
|
+
|
16
|
+
find_one :by_username, :call => 'people.findByUsername'
|
17
|
+
find_one :by_email, :using => :find_email, :call => 'people.findByEmail'
|
28
18
|
|
29
19
|
def load_info
|
30
20
|
response = Request.with_response!('people.getInfo', :user_id => self.id)
|
@@ -39,17 +29,5 @@ module Fleakr
|
|
39
29
|
end
|
40
30
|
end
|
41
31
|
|
42
|
-
def sets
|
43
|
-
@set ||= Set.find_all_by_user_id(self.id)
|
44
|
-
end
|
45
|
-
|
46
|
-
def groups
|
47
|
-
@groups ||= Group.find_all_by_user_id(self.id)
|
48
|
-
end
|
49
|
-
|
50
|
-
def photos
|
51
|
-
@photos ||= Photo.find_all_by_user_id(self.id)
|
52
|
-
end
|
53
|
-
|
54
32
|
end
|
55
33
|
end
|
data/lib/fleakr/version.rb
CHANGED
data/lib/fleakr.rb
CHANGED
data/test/fleakr/set_test.rb
CHANGED
@@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
3
3
|
module Fleakr
|
4
4
|
class SetTest < Test::Unit::TestCase
|
5
5
|
|
6
|
+
should_have_many :photos, :using => 'photoset_id'
|
7
|
+
|
6
8
|
describe "The Set class" do
|
7
9
|
|
8
10
|
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
|
@@ -22,26 +24,6 @@ module Fleakr
|
|
22
24
|
|
23
25
|
end
|
24
26
|
|
25
|
-
context "when accessing its list of photos" do
|
26
|
-
before do
|
27
|
-
@set = Set.new
|
28
|
-
@set.stubs(:id).with().returns('1')
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should retrieve a list of photos" do
|
32
|
-
photos = [stub()]
|
33
|
-
|
34
|
-
Photo.expects(:find_all_by_photoset_id).with('1').returns(photos)
|
35
|
-
|
36
|
-
@set.photos.should == photos
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should memoize the list of photos retrieved" do
|
40
|
-
Photo.expects(:find_all_by_photoset_id).once.returns([])
|
41
|
-
2.times { @set.photos }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
27
|
context "when saving the set" do
|
46
28
|
before do
|
47
29
|
@tmp_dir = create_temp_directory
|
data/test/fleakr/user_test.rb
CHANGED
@@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
3
3
|
module Fleakr
|
4
4
|
class UserTest < Test::Unit::TestCase
|
5
5
|
|
6
|
+
should_have_many :photos, :groups, :sets
|
7
|
+
|
6
8
|
describe "The User class" do
|
7
9
|
|
8
10
|
should_find_one :user, :by => :username, :call => 'people.findByUsername', :path => 'rsp/user'
|
@@ -28,50 +30,7 @@ module Fleakr
|
|
28
30
|
|
29
31
|
context "in general" do
|
30
32
|
|
31
|
-
before
|
32
|
-
@user = User.new
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should be able to retrieve the user's associated sets" do
|
36
|
-
sets = [stub()]
|
37
|
-
@user.stubs(:id).with().returns('1')
|
38
|
-
|
39
|
-
Set.expects(:find_all_by_user_id).with('1').returns(sets)
|
40
|
-
|
41
|
-
@user.sets.should == sets
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should memoize the results returned for this user's sets" do
|
45
|
-
Set.expects(:find_all_by_user_id).once.returns([])
|
46
|
-
2.times { @user.sets }
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be able to retrieve the user's associated groups" do
|
50
|
-
groups = [stub()]
|
51
|
-
@user.stubs(:id).with().returns('1')
|
52
|
-
|
53
|
-
Group.expects(:find_all_by_user_id).with('1').returns(groups)
|
54
|
-
|
55
|
-
@user.groups.should == groups
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should memoize the results returned for this user's group" do
|
59
|
-
Group.expects(:find_all_by_user_id).once.returns([])
|
60
|
-
2.times { @user.groups }
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should be able to retrieve the user's photos" do
|
64
|
-
photos = [stub()]
|
65
|
-
@user.stubs(:id).with().returns('1')
|
66
|
-
|
67
|
-
Photo.expects(:find_all_by_user_id).with('1').returns(photos)
|
68
|
-
@user.photos.should == photos
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should memoize the results returned for this user's photos" do
|
72
|
-
Photo.expects(:find_all_by_user_id).once.returns([])
|
73
|
-
2.times { @user.photos }
|
74
|
-
end
|
33
|
+
before { @user = User.new }
|
75
34
|
|
76
35
|
it "should be able to retrieve additional information about the current user" do
|
77
36
|
response = mock_request_cycle :for => 'people.getInfo', :with => {:user_id => @user.id}
|
data/test/test_helper.rb
CHANGED
@@ -4,7 +4,6 @@ require 'rubygems'
|
|
4
4
|
require 'matchy'
|
5
5
|
require 'context'
|
6
6
|
require 'mocha'
|
7
|
-
require 'activesupport'
|
8
7
|
|
9
8
|
require File.dirname(__FILE__) + '/../lib/fleakr'
|
10
9
|
|
@@ -16,6 +15,35 @@ class Test::Unit::TestCase
|
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
18
|
+
def self.should_have_many(*attributes)
|
19
|
+
class_name = self.name.demodulize.sub(/Test$/, '')
|
20
|
+
this_klass = "Fleakr::#{class_name}".constantize
|
21
|
+
|
22
|
+
options = attributes.extract_options!
|
23
|
+
finder_attribute = options[:using].nil? ? "#{class_name.downcase}_id" : options[:using]
|
24
|
+
|
25
|
+
attributes.each do |attribute|
|
26
|
+
target_klass = "Fleakr::#{attribute.to_s.singularize.classify}".constantize
|
27
|
+
|
28
|
+
it "should be able to retrieve the #{class_name.downcase}'s #{attribute}" do
|
29
|
+
results = [stub()]
|
30
|
+
object = this_klass.new
|
31
|
+
object.stubs(:id).with().returns('1')
|
32
|
+
|
33
|
+
target_klass.expects("find_all_by_#{finder_attribute}".to_sym).with('1').returns(results)
|
34
|
+
object.send(attribute).should == results
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should memoize the results for the #{class_name.downcase}'s #{attribute}" do
|
38
|
+
object = this_klass.new
|
39
|
+
|
40
|
+
target_klass.expects("find_all_by_#{finder_attribute}".to_sym).once.returns([])
|
41
|
+
2.times { object.send(attribute) }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
19
47
|
def self.should_find_one(thing, options)
|
20
48
|
class_name = thing.to_s.singularize.camelcase
|
21
49
|
klass = "Fleakr::#{class_name}".constantize
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reagent-fleakr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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: 2008-12-
|
12
|
+
date: 2008-12-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +21,15 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.6.0
|
23
23
|
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: activesupport
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.2.0
|
32
|
+
version:
|
24
33
|
description:
|
25
34
|
email: reaganpr@gmail.com
|
26
35
|
executables: []
|