Module: X::Objects::Lookups::Media

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

Overview

Look up media by media key

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_media(media, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<X::Media>

Look up media by media key, in parallel batches

Examples:

Look up the media of a post

client.find_all_media(post.media)

Look up media by media key

client.find_all_media(%w[3_1880028106020515840 3_1880028106020515841])

Parameters:

  • media (Array<String, X::Media, #media_key>) —

    the media keys, or the media, or what the uploads returned, whose keys are taken

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

    the number of batches looked up at once, which must be at least one; each is a request of up to 100 media keys, so a lower number spends a rate limit more slowly

  • params (Hash) —

    query parameters merged over the default parameters; one that overrides a default field parameter builds media that is not hydrated, so hydrate fetches the rest

Yield Parameters:

  • problem (Problem) —

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

Returns:

  • (Array<X::Media>) —

    the media that was found

Raises:

  • (ArgumentError) —

    if the concurrency is less than one



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

def find_all_media(media, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params, &)
  X::Media.find_all(media, client: self, concurrency:, **params, &)
end

#find_media(media_key, **params) {|problem| ... } ⇒ X::Media?

Look up media by media key

A post refers to its media by media key, and so does what an upload returns, so this reads the photo, video, or animated GIF that was uploaded, with its URL and variants.

Examples:

Look up media by media key

client.find_media("3_1880028106020515840")

Look up media that was uploaded

client.find_media(uploaded)

Parameters:

  • media_key (String, X::Media, #media_key) —

    the media key, such as 3_1880028106020515840, media, or what an upload returned

  • params (Hash) —

    query parameters merged over the default parameters; one that overrides a default field parameter to leave some out builds media that is not hydrated, so hydrate fetches the rest

Yield Parameters:

  • problem (Problem) —

    each problem the API reported

Returns:

  • (X::Media, nil) —

    the media, or nil if it was not found



33
34
35
# File 'x-objects/lib/x/objects/lookups/media.rb', line 33

def find_media(media_key, **params, &)
  X::Media.find(media_key, client: self, **params, &)
end

#find_media!(media_key, **params) ⇒ X::Media

Look up media by media key, raising if it is not found

Examples:

Look up media that must exist

client.find_media!("3_1880028106020515840")

Parameters:

  • media_key (String, X::Media, #media_key) —

    the media key, media, or what an upload returned

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

Raises:



66
67
68
# File 'x-objects/lib/x/objects/lookups/media.rb', line 66

def find_media!(media_key, **params)
  X::Media.find!(media_key, client: self, **params)
end