Class: X::Media
- Extended by:
- BatchFinders
- Defined in:
- x-objects/lib/x/objects/media.rb
Overview
A photo, video, or animated GIF attached to a post, which its media key identifies
Constant Summary collapse
- FIELDS =
Every public media 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[alt_text duration_ms height media_key preview_image_url public_metrics type url variants width].freeze
Instance Attribute Summary collapse
-
#alt_text ⇒ String?
readonly
The alternative text.
-
#duration_ms ⇒ Integer?
readonly
The duration of a video in milliseconds.
-
#height ⇒ Integer?
readonly
The height in pixels.
-
#media_key ⇒ String
readonly
The media key.
-
#preview_image_url ⇒ String?
readonly
The URL of a video or GIF preview image.
-
#public_metrics ⇒ Hash?
readonly
The public metrics.
-
#type ⇒ String?
readonly
The media type: photo, video, or animated_gif.
-
#url ⇒ String?
readonly
The URL of a photo.
-
#variants ⇒ Array<Hash>
readonly
The video variants with their bit rates, content types, and URLs.
-
#view_count ⇒ Integer?
readonly
The number of views.
-
#width ⇒ Integer?
readonly
The width in pixels.
Class Method Summary collapse
-
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every public field.
-
.find(media, client:, **params) {|problem| ... } ⇒ Media?
Look up media by media key.
-
.find!(media, client:, **params) ⇒ Media
Look up media by media key, which must exist.
-
.find_all(media, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Media>
Look up many media by media key, in parallel batches.
-
.from_id(media, client: nil) ⇒ Media
Refer to media by media key without a request.
Instance Method Summary collapse
-
#id ⇒ String
The identifier of the media, which is its media key.
-
#media_id ⇒ Integer
The numeric identifier of the media, which its media key names.
Constructor Details
This class inherits a constructor from X::Resource
Instance Attribute Details
#alt_text ⇒ String? (readonly)
The alternative text
222 |
# File 'x-objects/lib/x/objects/media.rb', line 222 attribute :alt_text |
#duration_ms ⇒ Integer? (readonly)
The duration of a video in milliseconds
230 |
# File 'x-objects/lib/x/objects/media.rb', line 230 attribute :duration_ms, :integer |
#height ⇒ Integer? (readonly)
The height in pixels
238 |
# File 'x-objects/lib/x/objects/media.rb', line 238 attribute :height, :integer |
#media_key ⇒ String (readonly)
The media key
179 |
# File 'x-objects/lib/x/objects/media.rb', line 179 attribute :media_key |
#preview_image_url ⇒ String? (readonly)
The URL of a video or GIF preview image
214 |
# File 'x-objects/lib/x/objects/media.rb', line 214 attribute :preview_image_url |
#public_metrics ⇒ Hash? (readonly)
The public metrics
262 |
# File 'x-objects/lib/x/objects/media.rb', line 262 attribute :public_metrics, :object |
#type ⇒ String? (readonly)
The media type: photo, video, or animated_gif
198 |
# File 'x-objects/lib/x/objects/media.rb', line 198 attribute :type |
#url ⇒ String? (readonly)
The URL of a photo
206 |
# File 'x-objects/lib/x/objects/media.rb', line 206 attribute :url |
#variants ⇒ Array<Hash> (readonly)
The video variants with their bit rates, content types, and URLs
254 |
# File 'x-objects/lib/x/objects/media.rb', line 254 attribute :variants, :objects |
#view_count ⇒ Integer? (readonly)
The number of views
270 |
# File 'x-objects/lib/x/objects/media.rb', line 270 attribute :view_count, :integer, key: %w[public_metrics view_count] |
#width ⇒ Integer? (readonly)
The width in pixels
246 |
# File 'x-objects/lib/x/objects/media.rb', line 246 attribute :width, :integer |
Class Method Details
.default_params ⇒ Hash{String => Array<String>}
The default query parameters requesting every public field
62 63 64 |
# File 'x-objects/lib/x/objects/media.rb', line 62 def self.default_params {"media.fields" => FIELDS} end |
.find(media, client:, **params) {|problem| ... } ⇒ Media?
Look up media by media key
100 |
# File 'x-objects/lib/x/objects/media.rb', line 100 def self.find(media, client:, **params) = super(key_of(media), client:, **params) #: Media? |
.find!(media, client:, **params) ⇒ Media
Look up media by media key, which must exist
The error it raises names the media key looked up, whether a media key, what an upload returned, or media was given.
115 |
# File 'x-objects/lib/x/objects/media.rb', line 115 def self.find!(media, client:, **params) = super(key_of(media), client:, **params) #: Media |
.find_all(media, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) {|problem| ... } ⇒ Array<Media>
Look up many media by media key, in parallel batches
148 |
# File 'x-objects/lib/x/objects/media.rb', line 148 def self.find_all(media, client:, concurrency: BatchFinders::DEFAULT_CONCURRENCY, **params) = super(media.map { |value| key_of(value) }, client:, concurrency:, **params) #: Array[Media] |
.from_id(media, client: nil) ⇒ Media
Refer to media by media key without a request
125 |
# File 'x-objects/lib/x/objects/media.rb', line 125 def self.from_id(media, client: nil) = super #: Media |
Instance Method Details
#id ⇒ String
The identifier of the media, which is its media key
Media is looked up by its media key, so that is what identifies it here, where the identifier of uploaded media, and the one a post or a direct message attaches media by, is the number media_id reads. Both X::Media and the uploaded media of x-uploader answer media_key and media_id alike.
|
|
# File 'x-objects/lib/x/objects/media.rb', line 161
|
#media_id ⇒ Integer
The numeric identifier of the media, which its media key names
A media key names the identifier after the number of the type of the media and an underscore. It is the identifier an upload returns, and the one a post or a direct message attaches media by.
190 |
# File 'x-objects/lib/x/objects/media.rb', line 190 def media_id = Integer(MediaIds.media_key_id(self), 10) |