/
favorites.rb
69 lines (67 loc) · 3.29 KB
/
favorites.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Twitter
class Client
module Favorites
# @overload favorites(options={})
# Returns the 20 most recent favorite statuses for the authenticating user
#
# @param options [Hash] A customizable set of options.
# @option options [Integer] :page Specifies the page of results to retrieve.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
# @return [Array] 20 favorite statuses.
# @example Return the 20 most recent favorite statuses for the authenticating user
# Twitter.favorites
# @overload favorites(user, options={})
# Returns the 20 most recent favorite statuses for the specified user
#
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :page Specifies the page of results to retrieve.
# @return [Array] 20 favorite statuses.
# @example Return the 20 most recent favorite statuses for @sferik
# Twitter.favorites("sferik")
# @format :json, :xml
# @authenticated false
# @rate_limited true
# @see http://dev.twitter.com/doc/get/favorites
def favorites(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
user = args.first
clean_screen_name!(user)
response = get(['favorites', user].compact.join('/'), options)
format.to_s.downcase == 'xml' ? response['statuses'] : response
end
# Favorites the specified status as the authenticating user
#
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @param id [Integer] The numerical ID of the desired status.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
# @return [Hashie::Mash] The favorited status.
# @see http://dev.twitter.com/doc/post/favorites/create/:id
# @example Favorite the status with the ID 25938088801
# Twitter.favorite_create(25938088801)
def favorite_create(id, options={})
response = post("favorites/create/#{id}", options)
format.to_s.downcase == 'xml' ? response['status'] : response
end
# Un-favorites the specified status as the authenticating user
#
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @param id [Integer] The numerical ID of the desired status.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
# @return [Hashie::Mash] The un-favorited status.
# @see http://dev.twitter.com/doc/post/favorites/destroy/:id
# @example Un-favorite the status with the ID 25938088801
# Twitter.favorite_destroy(25938088801)
def favorite_destroy(id, options={})
response = delete("favorites/destroy/#{id}", options)
format.to_s.downcase == 'xml' ? response['status'] : response
end
end
end
end