Skip to content

Commit

Permalink
Merge pull request #244 from aamerabbas/list_member_added
Browse files Browse the repository at this point in the history
Adding action for list_member_added
  • Loading branch information
sferik committed Mar 13, 2012
2 parents 646e905 + b40c79d commit 3ff5a4d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/twitter/action_factory.rb
@@ -1,21 +1,24 @@
require 'twitter/favorite'
require 'twitter/follow'
require 'twitter/list_member_added'
require 'twitter/mention'
require 'twitter/reply'
require 'twitter/retweet'

require 'active_support/core_ext/string/inflections'

module Twitter
class ActionFactory

# Instantiates a new action object
#
# @param attrs [Hash]
# @raise [ArgumentError] Error raised when supplied argument is missing an 'action' key.
# @return [Twitter::Favorite, Twitter::Follow, Twitter::Mention, Twitter::Reply, Twitter::Retweet]
# @return [Twitter::Favorite, Twitter::Follow, Twitter::ListMemberAdded, Twitter::Mention, Twitter::Reply, Twitter::Retweet]
def self.new(action={})
type = action.delete('action')
if type
Twitter.const_get(type.capitalize.to_sym).new(action)
Twitter.const_get(type.camelize.to_sym).new(action)
else
raise ArgumentError, "argument must have an 'action' key"
end
Expand Down
36 changes: 36 additions & 0 deletions lib/twitter/list_member_added.rb
@@ -0,0 +1,36 @@
require 'twitter/action'
require 'twitter/list'
require 'twitter/user'

module Twitter
class ListMemberAdded < Twitter::Action
lazy_attr_reader :target_objects

# A collection of users who added to the list
#
# @return [Array<Twitter::User>]
def sources
@sources = Array(@attrs['sources']).map do |user|
Twitter::User.new(user)
end
end

# A collection of lists that were added to
#
# @return [Array<Twitter::List>]
def target_objects
@target_objects = Array(@attrs['target_objects']).map do |list|
Twitter::List.new(list)
end
end

# A collection of users who were added to the list
#
# @return [Array<Twitter::User>]
def targets
@targets = Array(@attrs['targets']).map do |user|
Twitter::User.new(user)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/twitter/action_factory_spec.rb
Expand Up @@ -11,6 +11,10 @@
action = Twitter::ActionFactory.new('action' => 'follow')
action.should be_a Twitter::Follow
end
it "should generate a ListMemberAdded" do
action = Twitter::ActionFactory.new('action' => 'list_member_added')
action.should be_a Twitter::ListMemberAdded
end
it "should generate a Mention" do
action = Twitter::ActionFactory.new('action' => 'mention')
action.should be_a Twitter::Mention
Expand Down

0 comments on commit 3ff5a4d

Please sign in to comment.