Skip to content
Browse files

Merge pull request #244 from aamerabbas/list_member_added

Adding action for list_member_added
  • Loading branch information...
2 parents 646e905 + b40c79d commit 3ff5a4d91375115479adfe61422dd10fa20c0baa @sferik committed Mar 13, 2012
Showing with 45 additions and 2 deletions.
  1. +5 −2 lib/twitter/action_factory.rb
  2. +36 −0 lib/twitter/list_member_added.rb
  3. +4 −0 spec/twitter/action_factory_spec.rb
View
7 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
View
36 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
View
4 spec/twitter/action_factory_spec.rb
@@ -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

0 comments on commit 3ff5a4d

Please sign in to comment.
Something went wrong with that request. Please try again.