Module: Twitter::REST::Favorites

Includes:
Utils, Utils
Included in:
API
Defined in:
lib/twitter/rest/favorites.rb

Overview

Methods for working with favorite tweets

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Instance Method Details

#favorite(*tweets) ⇒ Array<Twitter::Tweet> #favorite(*tweets, options) ⇒ Array<Twitter::Tweet> Also known as: fav, fave

Favorites the specified Tweets as the authenticating user

Examples:

client.favorite(25938088801)

Overloads:

  • #favorite(*tweets) ⇒ Array<Twitter::Tweet>

    Parameters:

  • #favorite(*tweets, options) ⇒ Array<Twitter::Tweet>

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:



107
108
109
110
111
112
113
114
# File 'lib/twitter/rest/favorites.rb', line 107

def favorite(*args)
  arguments = Arguments.new(args)
  pmap(arguments) do |tweet|
    perform_post_with_object("/1.1/favorites/create.json", arguments.options.merge(id: extract_id(tweet)), Tweet)
  rescue Error::AlreadyFavorited, Error::NotFound
    nil
  end.compact
end

#favorite!(*tweets) ⇒ Array<Twitter::Tweet> #favorite!(*tweets, options) ⇒ Array<Twitter::Tweet> Also known as: create_favorite!, fav!, fave!

Favorites the specified Tweets and raises an error if already favorited

Examples:

client.favorite!(25938088801)

Overloads:

  • #favorite!(*tweets) ⇒ Array<Twitter::Tweet>

    Parameters:

  • #favorite!(*tweets, options) ⇒ Array<Twitter::Tweet>

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:



141
142
143
144
145
146
# File 'lib/twitter/rest/favorites.rb', line 141

def favorite!(*args)
  arguments = Arguments.new(args)
  pmap(arguments) do |tweet|
    perform_post_with_object("/1.1/favorites/create.json", arguments.options.merge(id: extract_id(tweet)), Tweet)
  end
end

#favorites(options = {}) ⇒ Array<Twitter::Tweet> #favorites(user, options = {}) ⇒ Array<Twitter::Tweet>

Returns favorite Tweets for the user

Examples:

client.favorites

Overloads:

  • #favorites(options = {}) ⇒ Array<Twitter::Tweet>

    Returns the 20 most recent favorite Tweets for the authenticating user

    Parameters:

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :count (Integer)

      Specifies the number of records to retrieve. Must be less than or equal to 200.

    • :since_id (Integer)

      Returns results with an ID greater than (that is, more recent than) the specified ID.

  • #favorites(user, options = {}) ⇒ Array<Twitter::Tweet>

    Returns the 20 most recent favorite Tweets for the specified user

    Parameters:

    • user (Integer, String, Twitter::User)

      A Twitter user ID, screen name, URI, or object.

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :count (Integer)

      Specifies the number of records to retrieve. Must be less than or equal to 200.

    • :since_id (Integer)

      Returns results with an ID greater than (that is, more recent than) the specified ID.

Returns:

Raises:

See Also:



38
39
40
41
42
# File 'lib/twitter/rest/favorites.rb', line 38

def favorites(*args)
  arguments = Arguments.new(args)
  merge_user!(arguments.options, arguments.pop) if arguments.last
  perform_get_with_objects("/1.1/favorites/list.json", arguments.options, Tweet)
end

#unfavorite(*tweets) ⇒ Array<Twitter::Tweet> #unfavorite(*tweets, options) ⇒ Array<Twitter::Tweet> Also known as: destroy_favorite

Un-favorites the specified Tweets as the authenticating user

Examples:

client.unfavorite(25938088801)

Overloads:

  • #unfavorite(*tweets) ⇒ Array<Twitter::Tweet>

    Parameters:

  • #unfavorite(*tweets, options) ⇒ Array<Twitter::Tweet>

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:



59
60
61
62
63
64
65
66
# File 'lib/twitter/rest/favorites.rb', line 59

def unfavorite(*args)
  arguments = Arguments.new(args)
  pmap(arguments) do |tweet|
    perform_post_with_object("/1.1/favorites/destroy.json", arguments.options.merge(id: extract_id(tweet)), Tweet)
  rescue Error::NotFound
    nil
  end.compact
end

#unfavorite!(*tweets) ⇒ Array<Twitter::Tweet> #unfavorite!(*tweets, options) ⇒ Array<Twitter::Tweet>

Un-favorites the specified Tweets and raises an error if not found

Examples:

client.unfavorite!(25938088801)

Overloads:

  • #unfavorite!(*tweets) ⇒ Array<Twitter::Tweet>

    Parameters:

  • #unfavorite!(*tweets, options) ⇒ Array<Twitter::Tweet>

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:



88
89
90
# File 'lib/twitter/rest/favorites.rb', line 88

def unfavorite!(*args)
  parallel_objects_from_response(Tweet, :post, "/1.1/favorites/destroy.json", args)
end