Module: X::Objects::Lookups::Spaces

Included in:
API
Defined in:
x-objects/lib/x/objects/lookups/spaces.rb

Overview

Look up and search spaces, mixed into a client through API

Internal to x-objects: X::Objects::API includes it, and its methods are public API of the client that includes API, but the module is only how they are grouped, and some of them need the methods of another, so include API rather than this module alone.

Instance Method Summary collapse

Instance Method Details

#find_all_spaces(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>

Look up many spaces by identifier, in parallel batches

Examples:

Look up many spaces

client.find_all_spaces(["1DXxyRYNejbKM", "1OwGWzarWnNKQ"]).map(&:title)

Parameters:

  • ids (Array<String, Integer, Space>) —

    the identifiers

  • concurrency (Integer) (defaults to: BatchFinders::DEFAULT_CONCURRENCY) —

    the number of batches looked up at once, which must be at least one

  • params (Hash) —

    query parameters merged over the default parameters

Yield Parameters:

  • problem (Problem) —

    each problem the API reported, such as a resource that was not found

Returns:

  • (Array<Space>) —

    the spaces that were found

Raises:

  • (ArgumentError) —

    if the concurrency is less than one



53
54
55
# File 'x-objects/lib/x/objects/lookups/spaces.rb', line 53

def find_all_spaces(ids, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &)
  Space.find_all(ids, client: self, concurrency:, **params, &)
end

#find_all_spaces_by_creator(users, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Space>

Look up the live and scheduled spaces many users created, in parallel batches

Examples:

Print the live spaces a user created

client.find_all_spaces_by_creator([7505382]).select { |space| space.state.eql?("live") }.map(&:title)

Parameters:

  • users (Array<User, String, Integer>) —

    the users who created the spaces, or their identifiers

  • concurrency (Integer) (defaults to: BatchFinders::DEFAULT_CONCURRENCY) —

    the number of batches looked up at once, which must be at least one

  • params (Hash) —

    query parameters merged over the default parameters

Yield Parameters:

  • problem (Problem) —

    each problem the API reported

Returns:

  • (Array<Space>) —

    the spaces, frozen, empty if the users created none

Raises:

  • (ArgumentError) —

    if a user is not a user or the identifier of one, or the concurrency is less than one, before a request



69
70
71
# File 'x-objects/lib/x/objects/lookups/spaces.rb', line 69

def find_all_spaces_by_creator(users, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &)
  Space.find_all_by_creator(users, client: self, concurrency:, **params, &)
end

#find_space(id, **params) {|problem| ... } ⇒ Space?

Look up a space by identifier

Examples:

Look up a space

client.find_space("1DXxyRYNejbKM").title

Parameters:

  • id (String, Integer, Space) —

    the identifier

  • params (Hash) —

    query parameters merged over the default parameters

Yield Parameters:

  • problem (Problem) —

    each problem the API reported, such as a resource that was not found

Returns:

  • (Space, nil) —

    the space or nil if the space was not found



25
26
27
# File 'x-objects/lib/x/objects/lookups/spaces.rb', line 25

def find_space(id, **params, &)
  Space.find(id, client: self, **params, &)
end

#find_space!(id, **params) ⇒ Space

Look up a space by identifier, which must exist

Examples:

Look up a space

client.find_space!("1DXxyRYNejbKM").title

Parameters:

  • id (String, Integer, Space) —

    the identifier

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

Raises:



38
39
40
# File 'x-objects/lib/x/objects/lookups/spaces.rb', line 38

def find_space!(id, **params)
  Space.find!(id, client: self, **params)
end

#search_spaces(query, **params) ⇒ Cursor

Search spaces by their titles

Examples:

Print the live spaces about Ruby

client.search_spaces("ruby", state: "live").each { |space| puts space.title }

Parameters:

  • query (String) —

    the search query

  • params (Hash) —

    query parameters merged over the default parameters, such as state: live or scheduled

Returns:

  • (Cursor) —

    a cursor over the matching spaces



81
82
83
# File 'x-objects/lib/x/objects/lookups/spaces.rb', line 81

def search_spaces(query, **params)
  Space.search(query, client: self, **params)
end