reagent-fleakr 0.1.1 → 0.1.2
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 +10 -0
- data/lib/fleakr.rb +8 -1
- data/lib/fleakr/error.rb +3 -5
- data/lib/fleakr/group.rb +17 -0
- data/lib/fleakr/object.rb +30 -0
- data/lib/fleakr/photo.rb +4 -8
- data/lib/fleakr/response.rb +1 -4
- data/lib/fleakr/set.rb +6 -7
- data/lib/fleakr/user.rb +11 -14
- data/lib/fleakr/version.rb +1 -1
- data/test/fixtures/people.findByEmail.xml +6 -0
- data/test/fixtures/people.getPublicGroups.xml +7 -0
- data/test/fleakr/error_test.rb +3 -1
- data/test/fleakr/group_test.rb +44 -0
- data/test/fleakr/set_test.rb +1 -1
- data/test/fleakr/user_test.rb +43 -15
- data/test/test_helper.rb +2 -0
- metadata +7 -2
data/README.markdown
CHANGED
@@ -36,6 +36,16 @@ And that user's associated sets:
|
|
36
36
|
=> [#<Fleakr::Set:0x671358 @title="The Decapitator", @description="">,
|
37
37
|
#<Fleakr::Set:0x66d898 @title="londonpaper hijack", ...
|
38
38
|
|
39
|
+
Or that user's groups:
|
40
|
+
|
41
|
+
>> user.groups
|
42
|
+
=> [#<Fleakr::Group:0x11f2330 ...,
|
43
|
+
#<Fleakr::Group:0x11f2308 ...
|
44
|
+
>> user.groups.first.name
|
45
|
+
=> "Rural Decay"
|
46
|
+
>> user.groups.first.id
|
47
|
+
=> "14581414@N00"
|
48
|
+
|
39
49
|
You can also grab photos for a particular set:
|
40
50
|
|
41
51
|
>> user.sets.first
|
data/lib/fleakr.rb
CHANGED
@@ -5,4 +5,11 @@ require 'cgi'
|
|
5
5
|
require 'net/http'
|
6
6
|
require 'hpricot'
|
7
7
|
|
8
|
-
|
8
|
+
require 'fleakr/object'
|
9
|
+
require 'fleakr/photo'
|
10
|
+
require 'fleakr/request'
|
11
|
+
require 'fleakr/response'
|
12
|
+
require 'fleakr/error'
|
13
|
+
require 'fleakr/set'
|
14
|
+
require 'fleakr/user'
|
15
|
+
require 'fleakr/group'
|
data/lib/fleakr/error.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module Fleakr
|
2
2
|
class Error
|
3
3
|
|
4
|
-
|
4
|
+
include Fleakr::Object
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
self.message = message
|
9
|
-
end
|
6
|
+
flickr_attribute :code, :from => 'rsp/err', :attribute => 'code'
|
7
|
+
flickr_attribute :message, :from => 'rsp/err', :attribute => 'msg'
|
10
8
|
|
11
9
|
end
|
12
10
|
end
|
data/lib/fleakr/group.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fleakr
|
2
|
+
class Group
|
3
|
+
|
4
|
+
include Fleakr::Object
|
5
|
+
|
6
|
+
flickr_attribute :id, :attribute => 'nsid'
|
7
|
+
flickr_attribute :name, :attribute => 'name'
|
8
|
+
|
9
|
+
def self.find_all_by_user_id(user_id)
|
10
|
+
response = Request.with_response!('people.getPublicGroups', :user_id => user_id)
|
11
|
+
(response.body/'rsp/groups/group').map do |flickr_group|
|
12
|
+
Group.new(flickr_group)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fleakr
|
2
|
+
module Object
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def flickr_attribute(name, options = {})
|
6
|
+
class_eval <<-CODE
|
7
|
+
def #{name}
|
8
|
+
if @#{name}.nil?
|
9
|
+
node = @response.at('#{options[:from]}')
|
10
|
+
@#{name} = #{options[:attribute].nil?} ? node.inner_text : node['#{options[:attribute]}']
|
11
|
+
end
|
12
|
+
@#{name}
|
13
|
+
end
|
14
|
+
CODE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
def initialize(response)
|
20
|
+
@response = response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.included(other)
|
25
|
+
other.send(:extend, Fleakr::Object::ClassMethods)
|
26
|
+
other.send(:include, Fleakr::Object::InstanceMethods)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/fleakr/photo.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fleakr
|
2
2
|
class Photo
|
3
|
+
|
4
|
+
include Fleakr::Object
|
5
|
+
|
6
|
+
flickr_attribute :title, :attribute => 'title'
|
3
7
|
|
4
8
|
def self.find_all_by_photoset_id(photoset_id)
|
5
9
|
response = Request.with_response!('photosets.getPhotos', :photoset_id => photoset_id)
|
@@ -8,13 +12,5 @@ module Fleakr
|
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
11
|
-
def initialize(photo_body)
|
12
|
-
@response_body = photo_body
|
13
|
-
end
|
14
|
-
|
15
|
-
def title
|
16
|
-
(@response_body).attributes['title']
|
17
|
-
end
|
18
|
-
|
19
15
|
end
|
20
16
|
end
|
data/lib/fleakr/response.rb
CHANGED
data/lib/fleakr/set.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
module Fleakr
|
2
2
|
class Set
|
3
|
+
|
4
|
+
include Fleakr::Object
|
3
5
|
|
4
|
-
|
6
|
+
flickr_attribute :id, :attribute => 'id'
|
7
|
+
flickr_attribute :title, :from => 'title'
|
8
|
+
flickr_attribute :description, :from => 'description'
|
5
9
|
|
6
10
|
def self.find_all_by_user_id(user_id)
|
7
11
|
response = Request.with_response!('photosets.getList', :user_id => user_id)
|
8
12
|
|
9
13
|
(response.body/'rsp/photosets/photoset').map do |flickr_set|
|
10
|
-
|
11
|
-
set.id = (flickr_set).attributes['id']
|
12
|
-
set.title = (flickr_set/'title').inner_text
|
13
|
-
set.description = (flickr_set/'description').inner_text
|
14
|
-
set
|
14
|
+
Set.new(flickr_set)
|
15
15
|
end
|
16
|
-
|
17
16
|
end
|
18
17
|
|
19
18
|
def photos
|
data/lib/fleakr/user.rb
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
module Fleakr
|
2
2
|
class User
|
3
3
|
|
4
|
-
|
4
|
+
include Fleakr::Object
|
5
|
+
|
6
|
+
flickr_attribute :id, :from => 'rsp/user', :attribute => 'nsid'
|
7
|
+
flickr_attribute :username, :from => 'rsp/user/username'
|
5
8
|
|
6
9
|
def self.find_by_username(username)
|
7
10
|
response = Request.with_response!('people.findByUsername', :username => username)
|
8
11
|
User.new(response.body)
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(response_body)
|
15
|
-
@response_body = (response_body/'rsp')
|
16
|
-
end
|
17
|
-
|
18
|
-
def id
|
19
|
-
(@response_body/'user').attr('id')
|
20
|
-
end
|
21
|
-
|
22
|
-
def username
|
23
|
-
(@response_body/'user/username').inner_text
|
14
|
+
def self.find_by_email(email)
|
15
|
+
response = Request.with_response!('people.findByEmail', :find_email => email)
|
16
|
+
User.new(response.body)
|
24
17
|
end
|
25
18
|
|
26
19
|
def sets
|
27
20
|
@set ||= Set.find_all_by_user_id(self.id)
|
28
21
|
end
|
29
22
|
|
23
|
+
def groups
|
24
|
+
@groups ||= Group.find_all_by_user_id(self.id)
|
25
|
+
end
|
26
|
+
|
30
27
|
end
|
31
28
|
end
|
data/lib/fleakr/version.rb
CHANGED
data/test/fleakr/error_test.rb
CHANGED
@@ -6,7 +6,9 @@ module Fleakr
|
|
6
6
|
describe "An instance of the Error class" do
|
7
7
|
|
8
8
|
it "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
|
+
|
11
|
+
error = Error.new(Hpricot.XML(response_xml))
|
10
12
|
|
11
13
|
error.code.should == '1'
|
12
14
|
error.message.should == 'User not found'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
module Fleakr
|
4
|
+
class GroupTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
describe "The Group class" do
|
7
|
+
|
8
|
+
it "should be able to find all groups by user ID" do
|
9
|
+
user_id = 'ABC123'
|
10
|
+
group_1, group_2 = [stub(), stub()]
|
11
|
+
|
12
|
+
response = mock_request_cycle :for => 'people.getPublicGroups', :with => {:user_id => user_id}
|
13
|
+
|
14
|
+
group_1_doc, group_2_doc = (response.body/'rsp/groups/group').map {|doc| doc }
|
15
|
+
|
16
|
+
Group.expects(:new).with(group_1_doc).returns(group_1)
|
17
|
+
Group.expects(:new).with(group_2_doc).returns(group_2)
|
18
|
+
|
19
|
+
Group.find_all_by_user_id(user_id).should == [group_1, group_2]
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "An instance of the Group class" do
|
25
|
+
context "when initializing from an Hpricot document" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
doc = (Hpricot.XML(read_fixture('people.getPublicGroups'))/'rsp/groups/group').first
|
29
|
+
@group = Group.new(doc)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a value for :id" do
|
33
|
+
@group.id.should == '13378274@N00'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a value for :name" do
|
37
|
+
@group.name.should == 'Group #1'
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/test/fleakr/set_test.rb
CHANGED
data/test/fleakr/user_test.rb
CHANGED
@@ -4,41 +4,69 @@ module Fleakr
|
|
4
4
|
class UserTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
describe "The User class" do
|
7
|
-
|
7
|
+
|
8
8
|
it "should be able to find a user by his username" do
|
9
|
-
|
9
|
+
user = stub()
|
10
|
+
response = mock_request_cycle :for => 'people.findByUsername', :with => {:username => 'frootpantz'}
|
10
11
|
|
11
|
-
|
12
|
+
User.expects(:new).with(response.body).returns(user)
|
13
|
+
User.find_by_username('frootpantz').should == user
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to find a user by his email" do
|
17
|
+
user = stub()
|
18
|
+
response = mock_request_cycle :for => 'people.findByEmail', :with => {:find_email => 'frootpantz@example.com'}
|
12
19
|
|
13
|
-
|
14
|
-
|
20
|
+
User.expects(:new).with(response.body).returns(user)
|
21
|
+
User.find_by_email('frootpantz@example.com').should == user
|
15
22
|
end
|
16
23
|
|
17
24
|
end
|
18
|
-
|
25
|
+
|
19
26
|
describe "An instance of User" do
|
20
|
-
|
27
|
+
|
21
28
|
before do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
response_body = Hpricot.XML(read_fixture('people.findByUsername'))
|
30
|
+
@user = User.new(response_body)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have a value for :id" do
|
34
|
+
@user.id.should == '31066442@N69'
|
26
35
|
end
|
27
36
|
|
28
|
-
it "should
|
37
|
+
it "should have a value for :username" do
|
38
|
+
@user.username.should == 'frootpantz'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to retrieve the user's associated sets" do
|
29
42
|
sets = [stub()]
|
30
|
-
|
43
|
+
@user.stubs(:id).with().returns('1')
|
44
|
+
|
45
|
+
Set.expects(:find_all_by_user_id).with('1').returns(sets)
|
31
46
|
|
32
47
|
@user.sets.should == sets
|
33
48
|
end
|
34
49
|
|
35
50
|
it "should memoize the results returned for this user's sets" do
|
36
51
|
Set.expects(:find_all_by_user_id).once.returns([])
|
37
|
-
|
38
52
|
2.times { @user.sets }
|
39
53
|
end
|
40
54
|
|
55
|
+
it "should be able to retrieve the user's associated groups" do
|
56
|
+
groups = [stub()]
|
57
|
+
@user.stubs(:id).with().returns('1')
|
58
|
+
|
59
|
+
Group.expects(:find_all_by_user_id).with('1').returns(groups)
|
60
|
+
|
61
|
+
@user.groups.should == groups
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should memoize the results returned for this user's group" do
|
65
|
+
Group.expects(:find_all_by_user_id).once.returns([])
|
66
|
+
2.times { @user.groups }
|
67
|
+
end
|
68
|
+
|
41
69
|
end
|
42
|
-
|
70
|
+
|
43
71
|
end
|
44
72
|
end
|
data/test/test_helper.rb
CHANGED
@@ -17,6 +17,8 @@ class Test::Unit::TestCase
|
|
17
17
|
def mock_request_cycle(options)
|
18
18
|
response = stub(:body => Hpricot.XML(read_fixture(options[:for])))
|
19
19
|
Fleakr::Request.expects(:with_response!).with(options[:for], options[:with]).returns(response)
|
20
|
+
|
21
|
+
response
|
20
22
|
end
|
21
23
|
|
22
24
|
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.1.
|
4
|
+
version: 0.1.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: 2008-11-
|
12
|
+
date: 2008-11-30 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,8 @@ files:
|
|
34
34
|
- Rakefile
|
35
35
|
- lib/fleakr
|
36
36
|
- lib/fleakr/error.rb
|
37
|
+
- lib/fleakr/group.rb
|
38
|
+
- lib/fleakr/object.rb
|
37
39
|
- lib/fleakr/photo.rb
|
38
40
|
- lib/fleakr/request.rb
|
39
41
|
- lib/fleakr/response.rb
|
@@ -42,11 +44,14 @@ files:
|
|
42
44
|
- lib/fleakr/version.rb
|
43
45
|
- lib/fleakr.rb
|
44
46
|
- test/fixtures
|
47
|
+
- test/fixtures/people.findByEmail.xml
|
45
48
|
- test/fixtures/people.findByUsername.xml
|
49
|
+
- test/fixtures/people.getPublicGroups.xml
|
46
50
|
- test/fixtures/photosets.getList.xml
|
47
51
|
- test/fixtures/photosets.getPhotos.xml
|
48
52
|
- test/fleakr
|
49
53
|
- test/fleakr/error_test.rb
|
54
|
+
- test/fleakr/group_test.rb
|
50
55
|
- test/fleakr/photo_test.rb
|
51
56
|
- test/fleakr/request_test.rb
|
52
57
|
- test/fleakr/response_test.rb
|