simple-flickr 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/simple-flickr.rb +1 -0
- data/lib/simple-flickr/group.rb +29 -0
- data/lib/simple-flickr/person.rb +5 -0
- data/lib/simple-flickr/photo.rb +6 -1
- data/lib/simple-flickr/proxy.rb +1 -1
- data/spec/client_spec.rb +2 -2
- data/spec/group_spec.rb +35 -0
- data/spec/person_spec.rb +10 -0
- data/spec/photo_spec.rb +21 -1
- data/spec/proxy_spec.rb +5 -6
- metadata +24 -9
data/Rakefile
CHANGED
data/lib/simple-flickr.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Flickr
|
2
|
+
|
3
|
+
# Represents a Flickr Group
|
4
|
+
#
|
5
|
+
# You can find the Flickr::Group by the NSID
|
6
|
+
class Group
|
7
|
+
include Proxy
|
8
|
+
|
9
|
+
def initialize( xml, client ) # :nodoc:
|
10
|
+
super( xml, client )
|
11
|
+
|
12
|
+
@attributes['id'] = xml['nsid'] || xml['id']
|
13
|
+
@attributes['name'] ||= xml.search('name').text
|
14
|
+
@attributes['description'] ||= xml.search('description').text
|
15
|
+
@attributes['members'] = xml.search('members').text.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_by_id( nsid, client )
|
19
|
+
return nil unless nsid.is_a? String
|
20
|
+
xml = client.request( 'groups.getInfo', :group_id => nsid )
|
21
|
+
|
22
|
+
new( xml.at('group'), client )
|
23
|
+
end
|
24
|
+
|
25
|
+
def photos( options = {} )
|
26
|
+
Photo.api_query( 'photos.search', @client, :group_id => id )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/simple-flickr/person.rb
CHANGED
@@ -32,6 +32,11 @@ module Flickr
|
|
32
32
|
Photo.api_query( 'people.getPublicPhotos', @client, options.merge(:user_id => id) )
|
33
33
|
end
|
34
34
|
|
35
|
+
def groups
|
36
|
+
xml = @client.request( 'people.getPublicGroups', :user_id => id )
|
37
|
+
return xml.search('group').collect { |g| Flickr::Group.new(g, @client) }
|
38
|
+
end
|
39
|
+
|
35
40
|
# Return the persons photosets.
|
36
41
|
#
|
37
42
|
# === Returns
|
data/lib/simple-flickr/photo.rb
CHANGED
@@ -17,8 +17,13 @@ module Flickr
|
|
17
17
|
super( xml, client )
|
18
18
|
@attributes['title'] ||= xml.search('title').text
|
19
19
|
@attributes['description'] = xml.search('description').text
|
20
|
-
@attributes['uploaded_at'] = Time.at((@attributes.delete('dateuploaded') or @attributes.delete('dateupload')).to_i)
|
20
|
+
@attributes['uploaded_at'] = Time.at((@attributes.delete('dateuploaded') or @attributes.delete('dateupload')).to_i).utc
|
21
21
|
@attributes['owner'] ||= xml.at('owner').attributes['nsid'] if xml.at('owner')
|
22
|
+
@attributes['taken_at'] = begin
|
23
|
+
Time.parse("#{@attributes.delete('datetaken')} UTC") if @attributes.include?('datetaken')
|
24
|
+
rescue ArgumentError
|
25
|
+
nil
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
# Get the person associated with this photo
|
data/lib/simple-flickr/proxy.rb
CHANGED
@@ -38,7 +38,7 @@ module Flickr
|
|
38
38
|
|
39
39
|
# This maps method calls to attributes.
|
40
40
|
def method_missing( method, *args ) # :nodoc:
|
41
|
-
return @attributes[method.to_s] if @attributes
|
41
|
+
return @attributes[method.to_s] if @attributes.include?(method.to_s)
|
42
42
|
super
|
43
43
|
end
|
44
44
|
|
data/spec/client_spec.rb
CHANGED
@@ -14,8 +14,8 @@ describe Flickr::Client do
|
|
14
14
|
@flickr.should_receive( :open ).with( Flickr::Client::REST_ENDPOINT + '?api_key=my-api-key&method=flickr.favorites.getList&per_page=4&user_id=123456789N00' ).and_return( VALID_FLICKR_RESPONSE )
|
15
15
|
@flickr.request( 'favorites.getList', :user_id => '123456789N00', :per_page => 4 )
|
16
16
|
end
|
17
|
-
|
18
|
-
[Errno::ETIMEDOUT,Timeout::Error
|
17
|
+
|
18
|
+
[Errno::ETIMEDOUT, Timeout::Error, OpenURI::HTTPError.new(nil,nil), Errno::ECONNRESET, SocketError, Errno::ECONNREFUSED].each do |e|
|
19
19
|
it "should raise an appropriate error if open-uri raises #{e}" do
|
20
20
|
@flickr.should_receive( :open ).and_raise( e )
|
21
21
|
proc { @flickr.request( 'test.echo' ) }.should raise_error( Flickr::RequestError )
|
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Flickr::Group do
|
4
|
+
before( :each ) do
|
5
|
+
@client = mock( 'Flickr::Client' )
|
6
|
+
@xml = Hpricot.parse( '<group id="34427465497@N01" iconserver="1" lang="en-us" ispoolmoderated="0"><name>GNEverybody</name><description>The group for GNE players</description><members>69</members><privacy>3</privacy><throttle count="10" mode="month" remaining="3"/></group>' )
|
7
|
+
@group = Flickr::Group.new( @xml.at('group'), @client )
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should include proxy' do
|
11
|
+
Flickr::Group.included_modules.include?( Flickr::Proxy ).should == true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should use the passed in client' do
|
15
|
+
@group.instance_variable_get( :'@client' ).should == @client
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return photos in the group' do
|
19
|
+
photos = mock('photos')
|
20
|
+
Flickr::Photo.should_receive( :api_query ).with( 'photos.search', @client, :group_id => '34427465497@N01' ).and_return( photos )
|
21
|
+
@group.photos.should == photos
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'it should find the group by the id' do
|
25
|
+
@client.should_receive( :request ).with( 'groups.getInfo', :group_id => '34427465497@N01' ).and_return( @xml )
|
26
|
+
group = Flickr::Group.find_by_id( '34427465497@N01', @client )
|
27
|
+
group.id.should == '34427465497@N01'
|
28
|
+
group.name.should == 'GNEverybody'
|
29
|
+
group.should be_instance_of( Flickr::Group )
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return nil if something invalid is passed in (non string)' do
|
33
|
+
Flickr::Group.find_by_id(nil, @client).should == nil
|
34
|
+
end
|
35
|
+
end
|
data/spec/person_spec.rb
CHANGED
@@ -82,6 +82,16 @@ describe Flickr::Person do
|
|
82
82
|
Flickr::Photo.should_receive( :api_query ).with( 'people.getPublicPhotos', @client, :user_id => '12037949754@N01', :per_page => 2 ).and_return( photos )
|
83
83
|
@person.photos( :per_page => 2).should == photos
|
84
84
|
end
|
85
|
+
|
86
|
+
it 'should return the users public groups' do
|
87
|
+
group_xml = Hpricot.parse( '<rsp stat="ok"><group nsid="34427469792@N01" name="FlickrCentral" admin="0" eighteenplus="0" /></rsp>' )
|
88
|
+
@client.should_receive( :request ).with( 'people.getPublicGroups', :user_id => '12037949754@N01' ).and_return( group_xml )
|
89
|
+
groups = @person.groups
|
90
|
+
groups[0].should be_kind_of(Flickr::Group)
|
91
|
+
groups[0].id.should == '34427469792@N01'
|
92
|
+
groups[0].name.should == 'FlickrCentral'
|
93
|
+
end
|
94
|
+
|
85
95
|
|
86
96
|
it 'should return the users favorites' do
|
87
97
|
photos = mock( 'photos' )
|
data/spec/photo_spec.rb
CHANGED
@@ -59,6 +59,26 @@ describe Flickr::Photo do
|
|
59
59
|
|
60
60
|
@client.should_receive( :request ).with( 'person.listPhotos', :foo => 'bar' ).and_return( photosets_xml )
|
61
61
|
Flickr::Photos.should_receive( :new ).with( photosets_xml.at('photoset'), @client )
|
62
|
-
Flickr::Photo.api_query( 'person.listPhotos', @client, :foo => 'bar')
|
62
|
+
Flickr::Photo.api_query( 'person.listPhotos', @client, :foo => 'bar')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should parse dates' do
|
66
|
+
xml = Hpricot.parse( '<photos page="2" pages="89" perpage="10" total="881"><photo id="2636" owner="47058503995@N01" farm="1" secret="a123456" server="2" title="test_04" ispublic="1" isfriend="0" isfamily="0" datetaken="2006-04-15 00:00:00" dateupload="1191939237" /></photos>' )
|
67
|
+
|
68
|
+
photo = Flickr::Photo.new( xml.at('photo'), @client )
|
69
|
+
|
70
|
+
photo.taken_at.should == Time.parse("2006-04-15 00:00:00 UTC")
|
71
|
+
photo.taken_at.should be_utc
|
72
|
+
|
73
|
+
photo.uploaded_at.should == Time.parse("2007-10-09 14:13:57 UTC")
|
74
|
+
photo.uploaded_at.should be_utc
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should ignore parsing errors on date taken' do
|
78
|
+
xml = Hpricot.parse( '<photos page="2" pages="89" perpage="10" total="881"><photo id="2636" owner="47058503995@N01" farm="1" secret="a123456" server="2" title="test_04" ispublic="1" isfriend="0" isfamily="0" datetaken="2006-04-00 00:00:00" dateupload="1191939237" /></photos>' )
|
79
|
+
|
80
|
+
photo = Flickr::Photo.new( xml.at('photo'), @client )
|
81
|
+
|
82
|
+
photo.taken_at.should be_nil
|
63
83
|
end
|
64
84
|
end
|
data/spec/proxy_spec.rb
CHANGED
@@ -5,13 +5,12 @@ class Flickr::ProxyTest
|
|
5
5
|
end
|
6
6
|
|
7
7
|
describe Flickr::ProxyTest do
|
8
|
+
before( :each ) do
|
9
|
+
@client = mock( 'Flickr::Client' )
|
10
|
+
@xml = Hpricot.parse( '<doc><proxytest id="2636" var1="test" foo="bar" /></doc>' ).at( 'proxytest' )
|
11
|
+
end
|
8
12
|
|
9
13
|
describe 'when dealing with attributes' do
|
10
|
-
before( :each ) do
|
11
|
-
@client = mock( 'Flickr::Client' )
|
12
|
-
@xml = Hpricot.parse( '<doc><proxytest id="2636" var1="test" foo="bar" /></doc>' ).at( 'proxytest' )
|
13
|
-
end
|
14
|
-
|
15
14
|
it 'should set the attributes' do
|
16
15
|
proxy = Flickr::ProxyTest.new( @xml, @client )
|
17
16
|
proxy.id.should == "2636"
|
@@ -45,4 +44,4 @@ describe Flickr::ProxyTest do
|
|
45
44
|
Flickr::ProxyTest.api_query( 'proxytest.getList', @client ).should == [test1,test2]
|
46
45
|
end
|
47
46
|
end
|
48
|
-
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-flickr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jerrett Taylor
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-06-14 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: hpricot
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 8
|
30
|
+
- 0
|
23
31
|
version: 0.8.0
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
description: A wrapper for Flickrs REST API.
|
26
35
|
email: jerrett@gmail.com
|
27
36
|
executables: []
|
@@ -34,6 +43,7 @@ files:
|
|
34
43
|
- README
|
35
44
|
- Rakefile
|
36
45
|
- spec/client_spec.rb
|
46
|
+
- spec/group_spec.rb
|
37
47
|
- spec/person_spec.rb
|
38
48
|
- spec/photo_set_spec.rb
|
39
49
|
- spec/photo_spec.rb
|
@@ -42,6 +52,7 @@ files:
|
|
42
52
|
- spec/spec.opts
|
43
53
|
- spec/spec_helper.rb
|
44
54
|
- lib/simple-flickr/client.rb
|
55
|
+
- lib/simple-flickr/group.rb
|
45
56
|
- lib/simple-flickr/person.rb
|
46
57
|
- lib/simple-flickr/photo.rb
|
47
58
|
- lib/simple-flickr/photo_set.rb
|
@@ -61,18 +72,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
72
|
requirements:
|
62
73
|
- - ">="
|
63
74
|
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 8
|
78
|
+
- 6
|
64
79
|
version: 1.8.6
|
65
|
-
version:
|
66
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
81
|
requirements:
|
68
82
|
- - ">="
|
69
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
70
86
|
version: "0"
|
71
|
-
version:
|
72
87
|
requirements: []
|
73
88
|
|
74
89
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.3.
|
90
|
+
rubygems_version: 1.3.6
|
76
91
|
signing_key:
|
77
92
|
specification_version: 3
|
78
93
|
summary: A wrapper for Flickrs REST API
|