Class: X::Community

Inherits:
Resource show all
Extended by:
Finders
Defined in:
x-objects/lib/x/objects/community.rb

Overview

A community of users who post to one another

Constant Summary collapse

FIELDS =

Every public community field

A minor release may add to it the fields the API adds, so that a lookup asks for them too; see Resource#hydrated? for what that means for a resource looked up with a list of fields of its own.

%w[access created_at description id join_policy member_count name].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from X::Resource

Instance Attribute Details

#access ⇒ String? (readonly)

Who can see the community's posts, as the API names it

Examples:

Get the access level

community.access

Returns:

  • (String, nil) —

    the access level



104
# File 'x-objects/lib/x/objects/community.rb', line 104

attribute :access

#created_at ⇒ Time? (readonly)

The creation time

Examples:

Get the creation time

community.created_at

Returns:

  • (Time, nil) —

    the creation time



88
# File 'x-objects/lib/x/objects/community.rb', line 88

attribute :created_at, :time

#description ⇒ String? (readonly)

The description

Examples:

Get the description

community.description

Returns:

  • (String, nil) —

    the description



80
# File 'x-objects/lib/x/objects/community.rb', line 80

attribute :description

#join_policy ⇒ String? (readonly)

How users become members, as the API names it

Examples:

Get the join policy

community.join_policy

Returns:

  • (String, nil) —

    the join policy



112
# File 'x-objects/lib/x/objects/community.rb', line 112

attribute :join_policy

#member_count ⇒ Integer? (readonly)

The number of members

Examples:

Get the member count

community.member_count

Returns:

  • (Integer, nil) —

    the member count



96
# File 'x-objects/lib/x/objects/community.rb', line 96

attribute :member_count, :integer

#name ⇒ String? (readonly)

The name

Examples:

Get the name

community.name

Returns:

  • (String, nil) —

    the name



72
# File 'x-objects/lib/x/objects/community.rb', line 72

attribute :name

Class Method Details

.default_params ⇒ Hash{String => Array<String>}

The default query parameters requesting every community field

Examples:

Get the default parameters

X::Community.default_params["community.fields"]

Returns:

  • (Hash{String => Array<String>}) —

    the default query parameters



49
# File 'x-objects/lib/x/objects/community.rb', line 49

def default_params = {"community.fields" => FIELDS}

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

Search communities

Examples:

Print the communities matching a query

X::Community.search("ruby", client: client).each { |community| puts community.name }

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 communities



60
61
62
63
# File 'x-objects/lib/x/objects/community.rb', line 60

def search(query, client:, **params)
  Cursor.__send__(:build, self, "communities/search", client:, params: {query:, max_results: MAX_RESULTS}.merge(params),
    token_param: "next_token", min_results: 10)
end

Instance Method Details

The permalink of the community

Examples:

Get the permalink

community.permalink # => "https://x.com/i/communities/1234567890"

Returns:

  • (String) —

    the x.com address of the community



120
# File 'x-objects/lib/x/objects/community.rb', line 120

def permalink = "https://x.com/i/communities/#{id}"

#uri ⇒ URI::Generic

The permalink of the community as a URI

Examples:

Get the address as a URI

community.uri # => #<URI::HTTPS https://x.com/i/communities/1234567890>

Returns:

  • (URI::Generic) —

    the x.com address of the community



128
# File 'x-objects/lib/x/objects/community.rb', line 128

def uri = URI(permalink)