Skip to content

Commit

Permalink
More work on groups.
Browse files Browse the repository at this point in the history
Tidied up Manifest
  • Loading branch information
Chris Taggart committed May 12, 2008
1 parent 12a6397 commit 2bd476f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
2 changes: 1 addition & 1 deletion History.txt
@@ -1,6 +1,6 @@
== 1.0.5 2008-05-12

* 1 major enhancement:
* 1 major change:
* Updated and refactored Flickr::Group class and Flickr#groups method to work with current Flickr API. Flickr#groups now searches for given group, rather than groups.getActiveList (which no longer exists as Flickr API call)
* Minor enhancements:
* Tweaked internals so new client instance isn't created each time new object (e.g. photo, user) is created
Expand Down
16 changes: 0 additions & 16 deletions Manifest.txt
@@ -1,27 +1,11 @@
History.txt
LICENSE
License.txt
Manifest.txt
PostInstall.txt
README
README.txt
Rakefile
TODO
lib/flickr.rb
script/console
script/destroy
script/generate
script/txt2html
setup.rb
spec/flickr_spec.rb
spec/spec_helper.rb
tasks/deployment.rake
tasks/environment.rake
tasks/website.rake
test/test_flickr.rb
test/test_helper.rb
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
website/template.html.erb
11 changes: 7 additions & 4 deletions lib/flickr.rb
Expand Up @@ -283,7 +283,10 @@ def url

# Implements flickr.people.getPublicGroups
def groups
@client.people_getPublicGroups('user_id'=>@id)['groups']['group'].collect { |group| Group.new(group['nsid'], @api_key) }
@client.people_getPublicGroups('user_id'=>@id)['groups']['group'].collect { |group| Group.new( "id" => group['nsid'],
"name" => group['name'],
"eighteenplus" => group['eighteenplus'],
"client" => @client) }
end

# Implements flickr.people.getPublicPhotos. Options hash allows you to add
Expand Down Expand Up @@ -582,7 +585,7 @@ def uri_for_photo_from_self(size=nil)
# flickr.groups.pools.getPhotos
# flickr.groups.pools.remove
class Group
attr_reader :id, :client, :name, :members, :online, :privacy, :chatid, :chatcount, :url
attr_reader :id, :client, :description, :name, :eighteenplus, :members, :online, :privacy, :url#, :chatid, :chatcount

def initialize(id_or_params_hash=nil, api_key=nil)
if id_or_params_hash.is_a?(Hash)
Expand All @@ -602,8 +605,8 @@ def getInfo
@members = info['members']
@online = info['online']
@privacy = info['privacy']
@chatid = info['chatid']
@chatcount = info['chatcount']
# @chatid = info['chatid']
# @chatcount = info['chatcount']
@url = @client.urls_getGroup('group_id'=>@id)['group']['url']
self
end
Expand Down
74 changes: 40 additions & 34 deletions test/test_flickr.rb
Expand Up @@ -231,7 +231,7 @@ def test_should_instantiate_groups_from_search_response
assert_kind_of Flickr::Group, group = groups.first
assert_equal "group1", group.id
assert_equal "Group One", group.name
assert_equal "0", group.instance_variable_get(:@eighteenplus)
assert_equal "0", group.eighteenplus
assert_equal f, group.client
end

Expand Down Expand Up @@ -269,11 +269,7 @@ def test_should_instantiate_groups_from_search_response
# ##### Flickr::User tests
#
def test_should_instantiate_user
user = Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User',
'foo' => 'bar',
'auth_token' => 'foobar789'})
user = new_user
assert_equal 'foo123', user.id
assert_equal 'some_user', user.username
assert_equal 'bar', user.instance_variable_get(:@foo) # should collect all other params up and store as instance variables
Expand All @@ -296,48 +292,41 @@ def test_should_instantiate_new_user_with_old_api
def test_should_instantiate_new_client_when_instantiating_user_if_no_client_passed_in_params
f = flickr_client
Flickr.expects(:new).returns(f)
user = Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User',
'auth_token' => 'foobar789',
'shared_secret' => 'some_secret',
'api_key' => 'an_api_key' })
user = new_user( 'api_key' => 'an_api_key' )
assert_equal f, user.client
end

def test_should_not_instantiate_new_client_when_instantiating_user_if_client_passed_in_params
f = flickr_client
Flickr.expects(:new).never
user = Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User',
'client' => f })
user = new_user( 'client' => f )
assert_equal f, user.client
end

def test_should_not_instantiate_new_client_if_existing_client_passed
f = flickr_client
def test_should_not_instantiate_client_if_no_api_key_passed
Flickr.expects(:new).never
user = Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User',
'api_key' => 'an_api_key',
'client' => f })
assert_equal f, user.client
user = new_user
assert_nil user.client
end

def test_should_not_instantiate_client_if_no_api_key_passed
user = Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User'})
assert_nil user.client
def test_should_get_users_public_groups
f = flickr_client
f.expects(:request).with("people.getPublicGroups", anything).returns(dummy_groups_response)
new_user( 'client' => f ).groups
end

def test_should_not_instantiate_new_client_when_instantiating_user_if_existing_client_passed_to_user_as_param
def test_should_instantiate_users_public_groups
f = flickr_client
Flickr.expects(:new).never
user = Flickr::User.new('client' => f)
assert_equal f, user.client
f.stubs(:request).returns(dummy_groups_response)
user = new_user( 'client' => f )

groups = user.groups
assert_equal 2, groups.size
assert_kind_of Flickr::Group, group = groups.first
assert_equal "group1", group.id
assert_equal "Group One", group.name
assert_equal "0", group.eighteenplus
assert_equal f, group.client
end

# def test_getInfo
Expand Down Expand Up @@ -631,9 +620,10 @@ def test_should_instantiate_group_from_id_and_api_key

# new api for instantiating groups
def test_should_instantiate_group_from_params_hash
group = Flickr::Group.new("id" => "group1", "name" => "Group One", "foo" => "bar")
group = Flickr::Group.new("id" => "group1", "name" => "Group One", "eighteenplus" => "1", "foo" => "bar")
assert_equal "group1", group.id
assert_equal "Group One", group.name
assert_equal "1", group.eighteenplus
assert_equal "bar", group.instance_variable_get(:@foo)
end

Expand All @@ -644,6 +634,14 @@ def test_should_use_flickr_client_passed_in_params_hash_when_instantiating_group
assert_equal f, group.client
end

def test_should_provide_id_name_eighteenplus_description_members_online_privacy_reader_methods_for_group
g = Flickr::Group.new
%w(id name eighteenplus description members online privacy).each do |m|
g.instance_variable_set("@#{m}", "foo_#{m}")
assert_equal "foo_#{m}", g.send(m)
end
end

# def test_should_initialize_photo_from_id
# photo = Flickr::Photo.new("foo123")
# assert_equal "foo123", photo.id
Expand Down Expand Up @@ -719,6 +717,14 @@ def authenticated_flickr_client
f
end

def new_user(options={})
Flickr::User.new({ 'id' => 'foo123',
'username' => 'some_user',
'name' => 'Some User',
'foo' => 'bar',
'auth_token' => 'foobar789'}.merge(options))

end
def new_photo(options={})
Flickr::Photo.new("1418878",
"foo123",
Expand Down

0 comments on commit 2bd476f

Please sign in to comment.