Module: Twitter::API::Favorites

Includes:
Utils
Included in:
Client
Defined in:
lib/twitter/api/favorites.rb

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Instance Method Details

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

Favorites the specified Tweets as the authenticating user

Overloads:

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

    Examples:

    Favorite the Tweet with the ID 25938088801

    Twitter.favorite(25938088801)
    

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

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

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



79
80
81
82
83
84
85
86
87
88
# File 'lib/twitter/api/favorites.rb', line 79

def favorite(*args)
  arguments = Twitter::API::Arguments.new(args)
  arguments.flatten.threaded_map do |id|
    begin
      object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
    rescue Twitter::Error::Forbidden => error
      raise unless error.message == Twitter::Error::AlreadyFavorited::MESSAGE
    end
  end.compact
end

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

Favorites the specified Tweets as the authenticating user and raises an error if one has already been favorited

Overloads:

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

    Examples:

    Favorite the Tweet with the ID 25938088801

    Twitter.favorite(25938088801)
    

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

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

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



109
110
111
112
113
114
115
116
117
118
# File 'lib/twitter/api/favorites.rb', line 109

def favorite!(*args)
  arguments = Twitter::API::Arguments.new(args)
  arguments.flatten.threaded_map do |id|
    begin
      object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
    rescue Twitter::Error::Forbidden => error
      handle_forbidden_error(Twitter::Error::AlreadyFavorited, error)
    end
  end
end

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

Returns favorite Tweets.

Overloads:

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

    Returns the 20 most recent favorite Tweets for the authenticating user

    Examples:

    Return the 20 most recent favorite Tweets for the authenticating user

    Twitter.favorites
    

    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 100.

    • :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

    Examples:

    Return the 20 most recent favorite Tweets for @sferik

    Twitter.favorites('sferik')
    

    Parameters:

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

      A Twitter user ID, screen name, 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 100.

    • :since_id (Integer)

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

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



35
36
37
38
39
40
41
# File 'lib/twitter/api/favorites.rb', line 35

def favorites(*args)
  arguments = Twitter::API::Arguments.new(args)
  if user = arguments.pop
    merge_user!(arguments.options, user)
  end
  objects_from_response(Twitter::Tweet, :get, "/1.1/favorites/list.json", arguments.options)
end

#unfavorite(*ids) ⇒ Array<Twitter::Tweet> #unfavorite(*ids, options) ⇒ Array<Twitter::Tweet> Also known as: favorite_destroy, favourite_destroy, unfavourite

Un-favorites the specified Tweets as the authenticating user

Overloads:

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

    Examples:

    Un-favorite the tweet with the ID 25938088801

    Twitter.unfavorite(25938088801)
    

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

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

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



58
59
60
# File 'lib/twitter/api/favorites.rb', line 58

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