reagent-fleakr 0.2.1 → 0.3.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.markdown → README.rdoc} +53 -26
- data/Rakefile +3 -3
- data/lib/fleakr/api/request.rb +58 -0
- data/lib/fleakr/api/response.rb +35 -0
- data/lib/fleakr/objects/contact.rb +31 -0
- data/lib/fleakr/objects/error.rb +22 -0
- data/lib/fleakr/objects/group.rb +26 -0
- data/lib/fleakr/objects/image.rb +51 -0
- data/lib/fleakr/objects/photo.rb +55 -0
- data/lib/fleakr/objects/search.rb +33 -0
- data/lib/fleakr/objects/set.rb +45 -0
- data/lib/fleakr/objects/user.rb +106 -0
- data/lib/fleakr/support/attribute.rb +28 -0
- data/lib/fleakr/support/object.rb +88 -0
- data/lib/fleakr/version.rb +3 -3
- data/lib/fleakr.rb +66 -11
- data/test/fixtures/contacts.getPublicList.xml +7 -0
- data/test/fixtures/groups.pools.getPhotos.xml +7 -0
- data/test/fixtures/people.getInfo.xml +1 -1
- data/test/fixtures/photos.getSizes.xml +10 -0
- data/test/test_helper.rb +21 -6
- data/test/unit/fleakr/api/request_test.rb +93 -0
- data/test/{fleakr → unit/fleakr/api}/response_test.rb +2 -2
- data/test/unit/fleakr/objects/contact_test.rb +58 -0
- data/test/{fleakr → unit/fleakr/objects}/error_test.rb +2 -2
- data/test/{fleakr → unit/fleakr/objects}/group_test.rb +6 -2
- data/test/unit/fleakr/objects/image_test.rb +76 -0
- data/test/unit/fleakr/objects/photo_test.rb +101 -0
- data/test/{fleakr → unit/fleakr/objects}/search_test.rb +21 -16
- data/test/{fleakr → unit/fleakr/objects}/set_test.rb +17 -12
- data/test/{fleakr → unit/fleakr/objects}/user_test.rb +44 -3
- data/test/{fleakr → unit/fleakr/support}/attribute_test.rb +2 -2
- data/test/{fleakr → unit/fleakr/support}/object_test.rb +3 -3
- data/test/unit/fleakr_test.rb +44 -0
- metadata +43 -29
- data/lib/fleakr/attribute.rb +0 -26
- data/lib/fleakr/error.rb +0 -10
- data/lib/fleakr/group.rb +0 -12
- data/lib/fleakr/image.rb +0 -35
- data/lib/fleakr/object.rb +0 -75
- data/lib/fleakr/photo.rb +0 -26
- data/lib/fleakr/request.rb +0 -45
- data/lib/fleakr/response.rb +0 -21
- data/lib/fleakr/search.rb +0 -31
- data/lib/fleakr/set.rb +0 -22
- data/lib/fleakr/user.rb +0 -33
- data/test/fleakr/image_test.rb +0 -82
- data/test/fleakr/photo_test.rb +0 -64
- data/test/fleakr/request_test.rb +0 -99
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
2
|
|
3
|
-
module Fleakr
|
3
|
+
module Fleakr::Objects
|
4
4
|
class SetTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
should_have_many :photos, :using => 'photoset_id'
|
@@ -27,6 +27,10 @@ module Fleakr
|
|
27
27
|
context "when saving the set" do
|
28
28
|
before do
|
29
29
|
@tmp_dir = create_temp_directory
|
30
|
+
@set_title = 'set'
|
31
|
+
|
32
|
+
@set = Set.new
|
33
|
+
@set.stubs(:title).with().returns(@set_title)
|
30
34
|
end
|
31
35
|
|
32
36
|
after { FileUtils.rm_rf(@tmp_dir) }
|
@@ -36,26 +40,27 @@ module Fleakr
|
|
36
40
|
image.expects(:save_to).with("#{@tmp_dir}/set")
|
37
41
|
|
38
42
|
photo = stub(:small => image)
|
39
|
-
|
40
|
-
set
|
41
|
-
set.stubs(:title).with().returns('set')
|
42
|
-
set.stubs(:photos).with().returns([photo])
|
43
|
+
|
44
|
+
@set.stubs(:photos).with().returns([photo])
|
43
45
|
|
44
46
|
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set")
|
45
47
|
|
46
|
-
set.save_to(@tmp_dir, :small)
|
48
|
+
@set.save_to(@tmp_dir, :small)
|
47
49
|
end
|
48
50
|
|
49
51
|
it "should not create the directory if it already exists" do
|
50
52
|
FileUtils.mkdir("#{@tmp_dir}/set")
|
51
|
-
|
52
|
-
set
|
53
|
-
set.stubs(:title).with().returns('set')
|
54
|
-
set.stubs(:photos).with().returns([])
|
53
|
+
|
54
|
+
@set.stubs(:photos).with().returns([])
|
55
55
|
|
56
56
|
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set").never
|
57
57
|
|
58
|
-
set.save_to(@tmp_dir, :small)
|
58
|
+
@set.save_to(@tmp_dir, :small)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not raise errors when saving an image size that doesn't exist" do
|
62
|
+
@set.stubs(:photos).with().returns([stub(:large => nil)])
|
63
|
+
lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
|
59
64
|
end
|
60
65
|
|
61
66
|
end
|
@@ -1,9 +1,25 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
2
|
|
3
|
-
module Fleakr
|
3
|
+
module Fleakr::Objects
|
4
4
|
class UserTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
def self.should_autoload_when_accessing(*attributes)
|
7
|
+
options = attributes.extract_options!
|
8
|
+
attributes.each do |accessor_name|
|
9
|
+
it "should load the additional user information when accessing the :#{accessor_name} attribute" do
|
10
|
+
user = User.new
|
11
|
+
user.expects(options[:with]).with()
|
12
|
+
user.send(accessor_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
should_search_by :user_id
|
18
|
+
|
19
|
+
should_have_many :photos, :groups, :sets, :contacts
|
20
|
+
|
21
|
+
should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :with => :load_info
|
22
|
+
should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info
|
7
23
|
|
8
24
|
describe "The User class" do
|
9
25
|
|
@@ -21,11 +37,15 @@ module Fleakr
|
|
21
37
|
|
22
38
|
should_have_a_value_for :id => '31066442@N69'
|
23
39
|
should_have_a_value_for :username => 'frootpantz'
|
40
|
+
should_have_a_value_for :name => 'Sir Froot Pantz'
|
24
41
|
should_have_a_value_for :photos_url => 'http://www.flickr.com/photos/frootpantz/'
|
25
42
|
should_have_a_value_for :profile_url => 'http://www.flickr.com/people/frootpantz/'
|
26
43
|
should_have_a_value_for :photos_count => '3907'
|
27
44
|
should_have_a_value_for :icon_server => '30'
|
28
45
|
should_have_a_value_for :icon_farm => '1'
|
46
|
+
should_have_a_value_for :pro => '1'
|
47
|
+
should_have_a_value_for :admin => '0'
|
48
|
+
|
29
49
|
end
|
30
50
|
|
31
51
|
context "in general" do
|
@@ -56,6 +76,27 @@ module Fleakr
|
|
56
76
|
@user.stubs(:icon_server).with().returns(nil)
|
57
77
|
@user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
|
58
78
|
end
|
79
|
+
|
80
|
+
it "should return a boolean value for :pro?" do
|
81
|
+
@user.stubs(:pro).with().returns('0')
|
82
|
+
@user.pro?.should be(false)
|
83
|
+
|
84
|
+
@user.stubs(:pro).with().returns('1')
|
85
|
+
@user.pro?.should be(true)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return a boolean value for :admin?" do
|
89
|
+
@user.stubs(:admin).with().returns('0')
|
90
|
+
@user.admin?.should be(false)
|
91
|
+
|
92
|
+
@user.stubs(:admin).with().returns('1')
|
93
|
+
@user.admin?.should be(true)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
59
100
|
end
|
60
101
|
end
|
61
102
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
2
|
|
3
3
|
class EmptyObject
|
4
|
-
include Fleakr::Object
|
4
|
+
include Fleakr::Support::Object
|
5
5
|
end
|
6
6
|
|
7
7
|
class FlickrObject
|
8
8
|
|
9
|
-
include Fleakr::Object
|
9
|
+
include Fleakr::Support::Object
|
10
10
|
|
11
11
|
flickr_attribute :name
|
12
12
|
flickr_attribute :description, :xpath => 'desc'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class FleakrTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
describe "The Fleakr module" do
|
6
|
+
|
7
|
+
it "should be able to set an API key" do
|
8
|
+
key = 'f00b4r'
|
9
|
+
Fleakr.api_key = key
|
10
|
+
|
11
|
+
Fleakr.api_key.should == key
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should provide a means to find a user by his username" do
|
15
|
+
user = stub()
|
16
|
+
Fleakr::Objects::User.expects(:find_by_username).with('username').returns(user)
|
17
|
+
Fleakr.user('username').should == user
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fall back to finding a user by email if finding by username fails" do
|
21
|
+
user = stub()
|
22
|
+
email = 'user@host.com'
|
23
|
+
|
24
|
+
Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::Api::Request::ApiError)
|
25
|
+
Fleakr::Objects::User.expects(:find_by_email).with(email).returns(user)
|
26
|
+
|
27
|
+
Fleakr.user(email).should == user
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to perform text searches" do
|
31
|
+
photos = [stub()]
|
32
|
+
|
33
|
+
Fleakr::Objects::Search.expects(:new).with(:text => 'foo').returns(stub(:results => photos))
|
34
|
+
Fleakr.search('foo').should == photos
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be able to perform searches based on tags" do
|
38
|
+
Fleakr::Objects::Search.expects(:new).with(:tags => %w(one two)).returns(stub(:results => []))
|
39
|
+
Fleakr.search(:tags => %w(one two))
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
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.
|
4
|
+
version: 0.3.0
|
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-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,51 +37,65 @@ executables: []
|
|
37
37
|
extensions: []
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
|
-
- README.
|
40
|
+
- README.rdoc
|
41
41
|
files:
|
42
|
-
- README.
|
42
|
+
- README.rdoc
|
43
43
|
- Rakefile
|
44
44
|
- lib/fleakr
|
45
|
-
- lib/fleakr/
|
46
|
-
- lib/fleakr/
|
47
|
-
- lib/fleakr/
|
48
|
-
- lib/fleakr/
|
49
|
-
- lib/fleakr/
|
50
|
-
- lib/fleakr/
|
51
|
-
- lib/fleakr/
|
52
|
-
- lib/fleakr/
|
53
|
-
- lib/fleakr/
|
54
|
-
- lib/fleakr/
|
55
|
-
- lib/fleakr/
|
45
|
+
- lib/fleakr/api
|
46
|
+
- lib/fleakr/api/request.rb
|
47
|
+
- lib/fleakr/api/response.rb
|
48
|
+
- lib/fleakr/objects
|
49
|
+
- lib/fleakr/objects/contact.rb
|
50
|
+
- lib/fleakr/objects/error.rb
|
51
|
+
- lib/fleakr/objects/group.rb
|
52
|
+
- lib/fleakr/objects/image.rb
|
53
|
+
- lib/fleakr/objects/photo.rb
|
54
|
+
- lib/fleakr/objects/search.rb
|
55
|
+
- lib/fleakr/objects/set.rb
|
56
|
+
- lib/fleakr/objects/user.rb
|
57
|
+
- lib/fleakr/support
|
58
|
+
- lib/fleakr/support/attribute.rb
|
59
|
+
- lib/fleakr/support/object.rb
|
56
60
|
- lib/fleakr/version.rb
|
57
61
|
- lib/fleakr.rb
|
58
62
|
- test/fixtures
|
63
|
+
- test/fixtures/contacts.getPublicList.xml
|
64
|
+
- test/fixtures/groups.pools.getPhotos.xml
|
59
65
|
- test/fixtures/people.findByEmail.xml
|
60
66
|
- test/fixtures/people.findByUsername.xml
|
61
67
|
- test/fixtures/people.getInfo.xml
|
62
68
|
- test/fixtures/people.getPublicGroups.xml
|
63
69
|
- test/fixtures/people.getPublicPhotos.xml
|
70
|
+
- test/fixtures/photos.getSizes.xml
|
64
71
|
- test/fixtures/photos.search.xml
|
65
72
|
- test/fixtures/photosets.getList.xml
|
66
73
|
- test/fixtures/photosets.getPhotos.xml
|
67
|
-
- test/fleakr
|
68
|
-
- test/fleakr/attribute_test.rb
|
69
|
-
- test/fleakr/error_test.rb
|
70
|
-
- test/fleakr/group_test.rb
|
71
|
-
- test/fleakr/image_test.rb
|
72
|
-
- test/fleakr/object_test.rb
|
73
|
-
- test/fleakr/photo_test.rb
|
74
|
-
- test/fleakr/request_test.rb
|
75
|
-
- test/fleakr/response_test.rb
|
76
|
-
- test/fleakr/search_test.rb
|
77
|
-
- test/fleakr/set_test.rb
|
78
|
-
- test/fleakr/user_test.rb
|
79
74
|
- test/test_helper.rb
|
75
|
+
- test/unit
|
76
|
+
- test/unit/fleakr
|
77
|
+
- test/unit/fleakr/api
|
78
|
+
- test/unit/fleakr/api/request_test.rb
|
79
|
+
- test/unit/fleakr/api/response_test.rb
|
80
|
+
- test/unit/fleakr/objects
|
81
|
+
- test/unit/fleakr/objects/contact_test.rb
|
82
|
+
- test/unit/fleakr/objects/error_test.rb
|
83
|
+
- test/unit/fleakr/objects/group_test.rb
|
84
|
+
- test/unit/fleakr/objects/image_test.rb
|
85
|
+
- test/unit/fleakr/objects/photo_test.rb
|
86
|
+
- test/unit/fleakr/objects/search_test.rb
|
87
|
+
- test/unit/fleakr/objects/set_test.rb
|
88
|
+
- test/unit/fleakr/objects/user_test.rb
|
89
|
+
- test/unit/fleakr/support
|
90
|
+
- test/unit/fleakr/support/attribute_test.rb
|
91
|
+
- test/unit/fleakr/support/object_test.rb
|
92
|
+
- test/unit/fleakr_test.rb
|
80
93
|
has_rdoc: true
|
81
94
|
homepage: http://sneaq.net
|
82
95
|
post_install_message:
|
83
|
-
rdoc_options:
|
84
|
-
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README.rdoc
|
85
99
|
require_paths:
|
86
100
|
- lib
|
87
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/lib/fleakr/attribute.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Fleakr
|
2
|
-
class Attribute
|
3
|
-
|
4
|
-
attr_reader :name, :xpath, :attribute
|
5
|
-
|
6
|
-
def initialize(name, options = {})
|
7
|
-
@name = name.to_sym
|
8
|
-
@attribute = options[:attribute]
|
9
|
-
|
10
|
-
@xpath = options[:xpath]
|
11
|
-
@xpath ||= @name.to_s unless @attribute
|
12
|
-
end
|
13
|
-
|
14
|
-
def value_from(document)
|
15
|
-
node = document
|
16
|
-
|
17
|
-
begin
|
18
|
-
node = document.at(self.xpath) if self.xpath
|
19
|
-
self.attribute.nil? ? node.inner_text : node[self.attribute]
|
20
|
-
rescue NoMethodError
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
data/lib/fleakr/error.rb
DELETED
data/lib/fleakr/group.rb
DELETED
data/lib/fleakr/image.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Fleakr
|
2
|
-
class Image
|
3
|
-
|
4
|
-
SUFFIXES = {
|
5
|
-
:square => '_s.jpg',
|
6
|
-
:thumbnail => '_t.jpg',
|
7
|
-
:small => '_m.jpg',
|
8
|
-
:medium => '.jpg',
|
9
|
-
:large => '_b.jpg',
|
10
|
-
}.freeze
|
11
|
-
|
12
|
-
def self.suffix_for(size)
|
13
|
-
self::SUFFIXES[size]
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(base_url, size)
|
17
|
-
@base_url = base_url
|
18
|
-
@size = size
|
19
|
-
end
|
20
|
-
|
21
|
-
def url
|
22
|
-
"#{@base_url}#{Image.suffix_for(@size)}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def filename
|
26
|
-
self.url.match(/([^\/]+)$/)[1]
|
27
|
-
end
|
28
|
-
|
29
|
-
def save_to(target)
|
30
|
-
destination = File.directory?(target) ? "#{target}/#{self.filename}" : "#{target}"
|
31
|
-
File.open(destination, 'w') {|f| f << Net::HTTP.get(URI.parse(self.url)) }
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
data/lib/fleakr/object.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module Fleakr
|
2
|
-
module Object
|
3
|
-
|
4
|
-
module ClassMethods
|
5
|
-
|
6
|
-
def attributes
|
7
|
-
@attributes ||= []
|
8
|
-
end
|
9
|
-
|
10
|
-
def flickr_attribute(name, options = {})
|
11
|
-
self.attributes << Attribute.new(name, options)
|
12
|
-
class_eval "attr_reader :#{name}"
|
13
|
-
end
|
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
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
module InstanceMethods
|
55
|
-
|
56
|
-
def initialize(document = nil)
|
57
|
-
self.populate_from(document) unless document.nil?
|
58
|
-
end
|
59
|
-
|
60
|
-
def populate_from(document)
|
61
|
-
self.class.attributes.each do |attribute|
|
62
|
-
value = attribute.value_from(document)
|
63
|
-
instance_variable_set("@#{attribute.name}".to_sym, value) unless value.nil?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.included(other)
|
70
|
-
other.send(:extend, Fleakr::Object::ClassMethods)
|
71
|
-
other.send(:include, Fleakr::Object::InstanceMethods)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|