Module: Twitter::Client::Search

Included in:
Twitter::Client
Defined in:
lib/twitter/client/search.rb

Overview

Defines methods related to Search

Instance Method Summary collapse

Instance Method Details

#images(q, options = {}) ⇒ Array<Twitter::Status>

Note:

Undocumented

Returns recent statuses that contain images related to a query

Examples:

Return recent statuses that contain images related to a query

Twitter.images('twitter')

Parameters:

  • q (String)

    A search term.

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

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



20
21
22
23
24
# File 'lib/twitter/client/search.rb', line 20

def images(q, options={})
  get("/i/search/image_facets.json", options.merge(:q => q), :phoenix => true).map do |status|
    Twitter::Status.new(status)
  end
end

#phoenix_search(q, options = {}) ⇒ Array<Twitter::Status>

Note:

Undocumented

Returns recent statuses related to a query with images and videos embedded

Examples:

Return recent statuses related to twitter with images and videos embedded

Twitter.phoenix_search('twitter')

Parameters:

  • q (String)

    A search term.

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

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

  • :since_id (Integer)

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

Returns:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



86
87
88
89
90
# File 'lib/twitter/client/search.rb', line 86

def phoenix_search(q, options={})
  get("/phoenix_search.phoenix", options.merge(:q => q), :phoenix => true)['statuses'].map do |status|
    Twitter::Status.new(status)
  end
end

#search(q, options = {}) ⇒ Array<Twitter::Status>

Note:

As of April 1st 2010, the Search API provides an option to retrieve "popular tweets" in addition to real-time search results. In an upcoming release, this will become the default and clients that don't want to receive popular tweets in their search results will have to explicitly opt-out. See the result_type parameter below for more information.

Returns tweets that match a specified query.

Examples:

Returns tweets related to twitter

Twitter.search('twitter')

Parameters:

  • q (String)

    A search term.

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

    A customizable set of options.

Options Hash (options):

  • :geocode (String)

    Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.

  • :lang (String)

    Restricts tweets to the given language, given by an ISO 639-1 code.

  • :locale (String)

    Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.

  • :page (Integer)

    The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page).

  • :result_type (String)

    Specifies what type of search results you would prefer to receive. The current default is "mixed."

  • :rpp (Integer)

    The number of tweets to return per page, up to a max of 100.

  • :until (String)

    Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.

  • :since_id (Integer)

    Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

  • :with_twitter_user_id (Boolean, String, Integer)

    When set to either true, t or 1, the from_user_id, from_user_id_str, to_user_id, and to_user_id_str values in the response will map to "official" user IDs which will match those returned by the REST API.

Returns:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



67
68
69
70
71
# File 'lib/twitter/client/search.rb', line 67

def search(q, options={})
  get("/search.json", options.merge(:q => q), :endpoint => search_endpoint)['results'].map do |status|
    Twitter::Status.new(status)
  end
end

#videos(q, options = {}) ⇒ Array<Twitter::Status>

Note:

Undocumented

Returns recent statuses that contain videos related to a query

Examples:

Return recent statuses that contain videos related to a query

Twitter.videos('twitter')

Parameters:

  • q (String)

    A search term.

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

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



38
39
40
41
42
# File 'lib/twitter/client/search.rb', line 38

def videos(q, options={})
  get("/i/search/video_facets.json", options.merge(:q => q), :phoenix => true).map do |status|
    Twitter::Status.new(status)
  end
end