Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert list.rb, list_members.rb, and list_subscribers.rb to new Twitter API #154

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
131 changes: 78 additions & 53 deletions lib/twitter/client/list.rb
Expand Up @@ -7,47 +7,55 @@ module List
# Creates a new list for the authenticated user
#
# @note Accounts are limited to 20 lists.
# @overload list_create(screen_name, name, options={})
# @param screen_name [String] A Twitter screen name.
# @param name [String] The name for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @return [Hashie::Mash] The created list.
# @example Create a list named "presidents"
# Twitter.list_create("sferik", "presidents")
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @param name [String] The name for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @return [Hashie::Mash] The created list.
# @see http://dev.twitter.com/doc/post/:user/lists
def list_create(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = args.pop
screen_name = args.pop || get_screen_name
response = post("#{screen_name}/lists", options.merge(:name => name))
# @example Create a list named "presidents"
# Twitter.list_create("presidents")
def list_create(name, options={})
response = post("lists/create", options.merge(:name => name))
format.to_s.downcase == 'xml' ? response['list'] : response
end

# Updates the specified list
#
# @overload list_update(screen_name, name, options={})
# @param screen_name [String] A Twitter screen name.
# @param name [String] The name for the list.
# @overload list_update(list, options={})
# @param list [Integer, String] The list_id or slug for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @example Update the "presidents" list to have the description "Presidents of the United States of America"
# Twitter.list_update("presidents", :description => "Presidents of the United States of America")
# Twitter.list_update(8863586, :description => "Presidents of the United States of America")
# @overload list_update(user, list, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @example Update the "presidents" list to have the description "Presidents of the United States of America"
# Twitter.list_update("sferik", "presidents", :description => "Presidents of the United States of America")
# Twitter.list_update(7505382, "presidents", :description => "Presidents of the United States of America")
# Twitter.list_update("sferik", 8863586, :description => "Presidents of the United States of America")
# Twitter.list_update(7505382, 8863586, :description => "Presidents of the United States of America")
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @return [Hashie::Mash] The created list.
# @see http://dev.twitter.com/doc/post/:user/lists/:id
def list_update(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = args.pop
screen_name = args.pop || get_screen_name
response = put("#{screen_name}/lists/#{name}", options)
list = args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
response = post("lists/update", options)
format.to_s.downcase == 'xml' ? response['list'] : response
end

Expand All @@ -67,70 +75,78 @@ def list_update(*args)
# @return [Hashie::Mash]
# @example List @sferik's lists
# Twitter.lists("sferik")
# @see http://dev.twitter.com/doc/get/statuses/friends
# Twitter.lists(7505382)
# @see http://dev.twitter.com/doc/get/:user/lists
# @format :json, :xml
# @authenticated true
# @rate_limited true
def lists(*args)
options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})
screen_name = args.first
if screen_name
response = get("#{screen_name}/lists", options)
else
response = get('lists', options)
end
user = args.first
merge_user_into_options!(user, options) if user
response = get("lists", options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you removed the ability to not pass in a user, both from the documentation and from the code itself. This interface needs to be maintained.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Sun, Apr 10, 2011 at 2:21 AM, sferik
reply@reply.github.com
wrote:

       # @Format :json, :xml
       # @authenticated true
       # @rate_limited true
       def lists(*args)
         options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})

  •        screen_name = args.first
  •        if screen_name
  •          response = get("#{screen_name}/lists", options)
  •        else
  •          response = get('lists', options)
  •        end
  •        user = args.first
  •        merge_user_into_options!(user, options) if user
  •        response = get("lists", options)

It looks like you removed the ability to not pass in a user, both from the documentation and from the code itself. This interface needs to be maintained.

Are you talking about for the lists method? I don't see what I broke
there. It still works with or without a username (just tried it to
make sure again). This line:

merge_user_into_options!(user, options) if user

passes in the user if specified, and if it's not specified, Twitter
just returns the lists for the authenticated user (which is how it
worked before).

And the documentation still shows the no-user-as-param option:

  # List the lists of the specified user
  #
  # @note Private lists will be included if the authenticated user

is the same as the user whose lists are being returned.
# @overload lists(options={})
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into
pages. Provide values as returned in the response objects's
next_cursor and previous_cursor attributes to page back and forth in
the list.
# @return [Hashie::Mash]
# @example List the authenticated user's lists
# Twitter.lists

It's the first one.

But it's late, and I may just be missing it entirely.

format.to_s.downcase == 'xml' ? response['lists_list'] : response
end

# Show the specified list
#
# @overload list(screen_name, id, options={})
# @param screen_name [String] A Twitter screen name.
# @param id [Integer, String] The id or slug of the list.
# @overload list(user, list, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug of the list.
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash] The specified list.
# @example Show @sferik's "presidents" list
# Twitter.list("sferik", "presidents")
# Twitter.list("sferik", 8863586)
# Twitter.list(7505382, "presidents")
# Twitter.list(7505382, 8863586)
# @note Private lists will only be shown if the authenticated user owns the specified list.
# @format :json, :xml
# @authenticated true
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/lists/:id
def list(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
id = args.pop
screen_name = args.pop || get_screen_name
response = get("#{screen_name}/lists/#{id}", options)
list = args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
response = get("lists/show", options)
format.to_s.downcase == 'xml' ? response['list'] : response
end

# Deletes the specified list
#
# @overload list_delete(screen_name, id, options={})
# @param screen_name [String] A Twitter screen name.
# @param id [Integer, String] The id or slug of the list.
# @overload list_delete(user, list, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug of the list.
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash] The deleted list.
# @example Delete @sferik's "presidents" list
# Twitter.list_delete("sferik", "presidents")
# Twitter.list_delete("sferik", 8863586)
# Twitter.list_delete(7505382, "presidents")
# Twitter.list_delete(7505382, 8863586)
# @note Must be owned by the authenticated user.
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @see http://dev.twitter.com/doc/delete/:user/lists/:id
def list_delete(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
id = args.pop
screen_name = args.pop || get_screeen_name
response = delete("#{screen_name}/lists/#{id}", options)
list = args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
response = delete("lists/destroy", options)
format.to_s.downcase == 'xml' ? response['list'] : response
end

# Show tweet timeline for members of the specified list
#
# @overload list_timeline(screen_name, name, options={})
# @param screen_name [String] A Twitter screen name.
# @param id [Integer, String] The id or slug of the list.
# @overload list_timeline(user, list, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug of the list.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
Expand All @@ -140,55 +156,64 @@ def list_delete(*args)
# @return [Array]
# @example Show tweet timeline for members of @sferik's "presidents" list
# Twitter.list_timeline("sferik", "presidents")
# Twitter.list_timeline("sferik", 8863586)
# Twitter.list_timeline(7505382, "presidents")
# Twitter.list_timeline(7505382, 8863586)
# @format :json, :xml
# @authenticated false
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/lists/:id/statuses
def list_timeline(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = args.pop
screen_name = args.pop || get_screen_name
response = get("#{screen_name}/lists/#{name}/statuses", options)
list = args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
response = get("lists/statuses", options)
format.to_s.downcase == 'xml' ? response['statuses'] : response
end

# List the lists the specified user has been added to
#
# @overload memberships(screen_name, options={})
# @param screen_name [String] A Twitter screen name.
# @overload memberships(user, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array]
# @example List the lists that @sferik has been added to
# Twitter.memberships("sferik")
# Twitter.memberships(7505382)
# @format :json, :xml
# @authenticated true
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/lists/memberships
def memberships(*args)
options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})
screen_name = args.pop || get_screen_name
response = get("#{screen_name}/lists/memberships", options)
user = args.pop || get_screen_name
merge_user_into_options!(user, options)
response = get("lists/memberships", options)
format.to_s.downcase == 'xml' ? response['lists_list'] : response
end

# List the lists the specified user follows
#
# @overload subscriptions(screen_name, options={})
# @param screen_name [String] A Twitter screen name.
# @overload subscriptions(user, options={})
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array]
# @example List the lists that @sferik follows
# Twitter.subscriptions("sferik")
# Twitter.subscriptions(7505382)
# @format :json, :xml
# @authenticated true
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/lists/subscriptions
def subscriptions(*args)
options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})
screen_name = args.pop || get_screen_name
response = get("#{screen_name}/lists/subscriptions", options)
user = args.pop || get_screen_name
merge_user_into_options!(user, options)
response = get("lists/subscriptions", options)
format.to_s.downcase == 'xml' ? response['lists_list'] : response
end
end
Expand Down