Class: X::Space
- Extended by:
- BatchFinders, Resources::BatchFinders
- Defined in:
- x-resources/lib/x/resources/space.rb
Overview
A live audio space
The space endpoints, but for buyers, take app-only authentication or OAuth 2.0 user context, not OAuth 1.0a, so a client that signs with OAuth 1.0a reads spaces with a copy that authenticates as the app, while the spaces and posts it reads hold the client, so that they act as the user.
Constant Summary collapse
- FIELDS =
Every public space 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[created_at ended_at id is_ticketed lang participant_count scheduled_start started_at state subscriber_count title updated_at].freeze
- EXPANSIONS =
Every expansion available on space endpoints
A minor release may add to it the expansions 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 expansions of its own.
%w[creator_id host_ids invited_user_ids speaker_ids topic_ids].freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Time?
readonly
The time when the space was created.
-
#creator_id ⇒ Integer?
readonly
The identifier of the creator.
-
#ended_at ⇒ Time?
readonly
The time when the space ended.
-
#host_ids ⇒ Array<Integer>
readonly
The identifiers of the hosts.
-
#invited_user_ids ⇒ Array<Integer>
readonly
The identifiers of the invited users.
-
#lang ⇒ String?
readonly
The BCP 47 language tag.
-
#participant_count ⇒ Integer?
readonly
The number of participants.
-
#scheduled_start ⇒ Time?
readonly
The scheduled start time.
-
#speaker_ids ⇒ Array<Integer>
readonly
The identifiers of the speakers.
-
#started_at ⇒ Time?
readonly
The time when the space started.
-
#state ⇒ String?
readonly
The state: live, scheduled, or ended.
-
#subscriber_count ⇒ Integer?
readonly
The number of subscribers.
-
#ticketed ⇒ Boolean?
readonly
Whether the space requires a ticket, the is_ticketed field.
-
#title ⇒ String?
readonly
The title.
-
#topic_ids ⇒ Array<Integer>
readonly
The identifiers of the topics.
-
#updated_at ⇒ Time?
readonly
The time when the space was last updated.
Class Method Summary collapse
-
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every space field and expansion.
-
.find(id, client:, **params) {|problem| ... } ⇒ Resource?
extended
from Resources::Finders
Look up a resource by identifier.
-
.find!(id, client:, **params) ⇒ Resource
extended
from Resources::Finders
Look up a resource by identifier, which must exist.
-
.find_all(ids, client:, concurrency: DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Resource>
extended
from Resources::BatchFinders
Look up many resources by identifier, in parallel batches.
-
.find_all_by_creator(users, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>
Look up the live and scheduled spaces many users created, in parallel batches.
-
.hydrate_all(resources, client:, concurrency: DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Resource>
extended
from Resources::BatchFinders
Replace the resources that are not hydrated with the full resources.
-
.search(query, client:, **params) ⇒ Cursor
Search spaces by their titles.
Instance Method Summary collapse
-
#buyers(**params) ⇒ Cursor
The users who bought a ticket to this space.
-
#creator ⇒ User?
The creator, resolved from the includes or as a stub holding only its identifier.
-
#hosts ⇒ Array<User>
The hosts, resolved from the includes or as stubs holding only their identifiers.
-
#invited_users ⇒ Array<User>
The invited users, from the includes or as stubs holding only their identifiers.
-
#posts(**params) ⇒ Cursor
(also: #tweets)
The posts shared in this space.
-
#speakers ⇒ Array<User>
The speakers, from the includes or as stubs holding only their identifiers.
-
#ticketed? ⇒ Boolean
Check whether the space requires a ticket.
-
#topics ⇒ Array<Topic>
The topics, from the includes or as stubs holding only their identifiers.
Constructor Details
This class inherits a constructor from X::Resource
Instance Attribute Details
#created_at ⇒ Time? (readonly)
The time when the space was created
161 |
# File 'x-resources/lib/x/resources/space.rb', line 161 attribute :created_at, :time |
#creator_id ⇒ Integer? (readonly)
The identifier of the creator
232 |
# File 'x-resources/lib/x/resources/space.rb', line 232 attribute :creator_id, :integer |
#ended_at ⇒ Time? (readonly)
The time when the space ended
177 |
# File 'x-resources/lib/x/resources/space.rb', line 177 attribute :ended_at, :time |
#host_ids ⇒ Array<Integer> (readonly)
The identifiers of the hosts
240 |
# File 'x-resources/lib/x/resources/space.rb', line 240 attribute :host_ids, :integers |
#invited_user_ids ⇒ Array<Integer> (readonly)
The identifiers of the invited users
256 |
# File 'x-resources/lib/x/resources/space.rb', line 256 attribute :invited_user_ids, :integers |
#lang ⇒ String? (readonly)
The BCP 47 language tag
153 |
# File 'x-resources/lib/x/resources/space.rb', line 153 attribute :lang |
#participant_count ⇒ Integer? (readonly)
The number of participants
216 |
# File 'x-resources/lib/x/resources/space.rb', line 216 attribute :participant_count, :integer |
#scheduled_start ⇒ Time? (readonly)
The scheduled start time
185 |
# File 'x-resources/lib/x/resources/space.rb', line 185 attribute :scheduled_start, :time |
#speaker_ids ⇒ Array<Integer> (readonly)
The identifiers of the speakers
248 |
# File 'x-resources/lib/x/resources/space.rb', line 248 attribute :speaker_ids, :integers |
#started_at ⇒ Time? (readonly)
The time when the space started
169 |
# File 'x-resources/lib/x/resources/space.rb', line 169 attribute :started_at, :time |
#state ⇒ String? (readonly)
The state: live, scheduled, or ended
145 |
# File 'x-resources/lib/x/resources/space.rb', line 145 attribute :state |
#subscriber_count ⇒ Integer? (readonly)
The number of subscribers
224 |
# File 'x-resources/lib/x/resources/space.rb', line 224 attribute :subscriber_count, :integer |
#ticketed ⇒ Boolean? (readonly)
Whether the space requires a ticket, the is_ticketed field
201 |
# File 'x-resources/lib/x/resources/space.rb', line 201 attribute :ticketed, :boolean, key: %w[is_ticketed] |
#title ⇒ String? (readonly)
The title
137 |
# File 'x-resources/lib/x/resources/space.rb', line 137 attribute :title |
#topic_ids ⇒ Array<Integer> (readonly)
The identifiers of the topics
264 |
# File 'x-resources/lib/x/resources/space.rb', line 264 attribute :topic_ids, :integers |
#updated_at ⇒ Time? (readonly)
The time when the space was last updated
193 |
# File 'x-resources/lib/x/resources/space.rb', line 193 attribute :updated_at, :time |
Class Method Details
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every space field and expansion
89 90 91 |
# File 'x-resources/lib/x/resources/space.rb', line 89 def default_params {"space.fields" => FIELDS, "user.fields" => User::FIELDS, "topic.fields" => Topic::FIELDS, "expansions" => EXPANSIONS} end |
.find(id, client:, **params) {|problem| ... } ⇒ Resource? Originally defined in module Resources::Finders
Look up a resource by identifier
.find!(id, client:, **params) ⇒ Resource Originally defined in module Resources::Finders
Look up a resource by identifier, which must exist
The error it raises names the identifier looked up, whether the identifier or a resource was given. Its cause is the X::NotFound of a lookup the API answered with a 404 that reports the resource as not found.
.find_all(ids, client:, concurrency: DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Resource> Originally defined in module Resources::BatchFinders
Look up many resources by identifier, in parallel batches
The resources come back in the order of the identifiers they were asked for by, whatever order the batches were answered in, one for each identifier that was found, so an identifier asked for twice comes back twice, as hydrate_all keeps a resource it is given twice. Each identifier is asked for once, however often it is given.
.find_all_by_creator(users, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>
Look up the live and scheduled spaces many users created, in parallel batches
The API returns the spaces of up to 100 users at a time, in one response without pages, so the users are looked up that many at a time.
125 126 127 128 129 |
# File 'x-resources/lib/x/resources/space.rb', line 125 def self.find_all_by_creator(users, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &) ids = users.map { |user| Utils.id_of(user, User) } spaces = lookup_in_batches("spaces/by/creator_ids", :user_ids, ids, client:, concurrency:, **params, &) #: Array[Space] spaces.freeze end |
.hydrate_all(resources, client:, concurrency: DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Resource> Originally defined in module Resources::BatchFinders
Replace the resources that are not hydrated with the full resources
A resource that hydrate would look up is looked up, which is a stub and also a resource a response included without every field, so what comes back is hydrated throughout. A resource that was not found is dropped, as is nil, which a reference to no resource reads as, such as the author of a post whose response named none, and a hydrated resource is kept as it is, so resources that are all hydrated need no lookup. What was found is stored in each original, so hydrating one of them afterwards costs no request, unless params override a default field or expansion parameter: what such a lookup found is not the full resource, so it is returned without being stored, and hydrating an original fetches the full resource. A resource that holds what hydrate returns, because hydrate or an earlier hydrate_all stored it, is replaced with that, and looked up again by no request, since the API bills each resource a lookup returns.
.search(query, client:, **params) ⇒ Cursor
Search spaces by their titles
The API returns the matching spaces in one response, of up to 100 spaces.
104 105 106 |
# File 'x-resources/lib/x/resources/space.rb', line 104 def search(query, client:, **params) Cursor.__send__(:build, self, "spaces/search", client:, params: {query:, max_results: MAX_RESULTS}.merge(params), app_only: true) end |
Instance Method Details
#buyers(**params) ⇒ Cursor
The users who bought a ticket to this space
The authenticated user must have created the space. The endpoint takes only OAuth 2.0 user context, which the object layer cannot route around, so a client that signs with OAuth 1.0a, or authenticates as the app, is refused.
327 |
# File 'x-resources/lib/x/resources/space.rb', line 327 def buyers(**params) = cursor(User, "spaces/#{id}/buyers", max_results: MAX_RESULTS, **params) |
#creator ⇒ User?
The creator, resolved from the includes or as a stub holding only its identifier
272 |
# File 'x-resources/lib/x/resources/space.rb', line 272 reference :creator, :User, key: %w[creator_id] |
#hosts ⇒ Array<User>
The hosts, resolved from the includes or as stubs holding only their identifiers
280 |
# File 'x-resources/lib/x/resources/space.rb', line 280 references :hosts, :User, key: %w[host_ids] |
#invited_users ⇒ Array<User>
The invited users, from the includes or as stubs holding only their identifiers
296 |
# File 'x-resources/lib/x/resources/space.rb', line 296 references :invited_users, :User, key: %w[invited_user_ids] |
#posts(**params) ⇒ Cursor Also known as: tweets
The posts shared in this space
313 314 315 |
# File 'x-resources/lib/x/resources/space.rb', line 313 def posts(**params) cursor(Post, "spaces/#{id}/tweets", max_results: MAX_RESULTS, app_only: true, **params) end |
#speakers ⇒ Array<User>
The speakers, from the includes or as stubs holding only their identifiers
288 |
# File 'x-resources/lib/x/resources/space.rb', line 288 references :speakers, :User, key: %w[speaker_ids] |
#ticketed? ⇒ Boolean
Check whether the space requires a ticket
|
|
# File 'x-resources/lib/x/resources/space.rb', line 203
|
#topics ⇒ Array<Topic>
The topics, from the includes or as stubs holding only their identifiers
304 |
# File 'x-resources/lib/x/resources/space.rb', line 304 references :topics, :Topic, key: %w[topic_ids] |