Module: X::Resources::PostSearch

Included in:
Post
Defined in:
x-resources/lib/x/resources/post_search.rb

Overview

The searches of posts, and the posts of the authenticated user that others reposted

Internal to x-resources: the methods it gives Post, such as X::Post.search, are public API, but the module is only how they are shared, and which classes extend or include it can change within 1.x.

Instance Method Summary collapse

Instance Method Details

#reposts_of_me(client:, **params) ⇒ Cursor Also known as: retweets_of_me

The posts of the authenticated user that other users have reposted

The endpoint names no user, so these are always the posts of the user the client authenticates as.

Examples:

Print the reposted posts

X::Post.reposts_of_me(client: client).each { |post| puts post.text }

Parameters:

  • client (Object) —

    the client used to make the requests

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the reposted posts



66
67
68
69
# File 'x-resources/lib/x/resources/post_search.rb', line 66

def reposts_of_me(client:, **params)
  # @type self: singleton(Post)
  Cursor.__send__(:build, self, "users/reposts_of_me", client:, params: {max_results: MAX_RESULTS}.merge(params))
end

#search(query, client:, **params) ⇒ Cursor

Search recent posts

Examples:

Print posts about Ruby

X::Post.search("ruby -is:retweet", client: client).each { |post| puts post.text }

Parameters:

  • query (String) —

    the search query

  • client (Object) —

    the client used to make the requests

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the matching posts



32
33
34
35
# File 'x-resources/lib/x/resources/post_search.rb', line 32

def search(query, client:, **params)
  # @type self: singleton(Post)
  Cursor.__send__(:build, self, "tweets/search/recent", client:, params: {query:, max_results: MAX_RESULTS}.merge(params), min_results: 10)
end

#search_all(query, client:, **params) ⇒ Cursor

Search the full archive of posts

A page holds up to 500 posts, or 100 when the request asks for context annotations, as the default fields do.

Examples:

Print every post about Ruby

X::Post.search_all("ruby -is:retweet", client: client).each { |post| puts post.text }

Page through every post about Ruby 500 at a time, without context annotations

X::Post.search_all("ruby", client: client, "post.fields": %w[created_at text])

Parameters:

  • query (String) —

    the search query

  • client (Object) —

    the client used to make the requests

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the matching posts



50
51
52
53
54
# File 'x-resources/lib/x/resources/post_search.rb', line 50

def search_all(query, client:, **params)
  # @type self: singleton(Post)
  max_results = context_annotations?(params) ? MAX_RESULTS : MAX_ARCHIVE_RESULTS
  Cursor.__send__(:build, self, "tweets/search/all", client:, params: {query:, max_results:}.merge(params), min_results: 10)
end