Class: X::PersonalizedTrend
- Inherits:
-
Object
- Object
- X::PersonalizedTrend
- Includes:
- Serialization, ValueEquality, ValueMarshalling
- Defined in:
- x-objects/lib/x/objects/personalized_trend.rb
Overview
A topic trending for the authenticated user, as the trends X picks for them report it
A personalized trend has no identifier, and the API offers no lookup of one, so the trends are read all at once, for the user the client authenticates as. They are described as they are shown: the number of posts, and how long the topic has trended, are text such as "12.3K posts", rather than numbers.
Constant Summary collapse
- FIELDS =
Every personalized trend field
A minor release may add to it the fields the API adds, so that the trends ask for them too.
%w[category post_count trend_name trending_since].freeze
Instance Attribute Summary collapse
-
#attrs ⇒ Hash{String => Object}
readonly
The raw attributes of the trend.
Class Method Summary collapse
-
.all(client:, **params) ⇒ Array<PersonalizedTrend>
The topics trending for the authenticated user.
Instance Method Summary collapse
-
#category ⇒ String?
The category of the trend.
-
#deconstruct_keys(keys) ⇒ Hash{Symbol => String, nil}
Deconstruct the trend into what its readers read, so it matches a hash pattern.
-
#initialize(attrs) ⇒ PersonalizedTrend
constructor
Initialize a trend from the attributes the API reported.
-
#name ⇒ String?
The name of the trend, such as a hashtag or a phrase.
-
#post_count_text ⇒ String?
The number of posts about the trend, as the text X shows it.
-
#trending_since_text ⇒ String?
How long the topic has trended, as the text X shows it.
Constructor Details
#initialize(attrs) ⇒ PersonalizedTrend
Initialize a trend from the attributes the API reported
63 64 65 66 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 63 def initialize(attrs) @attrs = Utils.deep_freeze(Utils.attributes!(attrs)) freeze end |
Instance Attribute Details
#attrs ⇒ Hash{String => Object} (readonly)
The raw attributes of the trend
36 37 38 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 36 def attrs @attrs end |
Class Method Details
.all(client:, **params) ⇒ Array<PersonalizedTrend>
The topics trending for the authenticated user
The endpoint names no user, so these are always the trends of the user the client authenticates as, and it takes a user's authentication alone, so a client that authenticates as the app is refused.
50 51 52 53 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 50 def self.all(client:, **params) body = client.get(Utils.path(ENDPOINT, {"personalized_trend.fields" => FIELDS}.merge(params)), **Utils::JSON_CLASSES) Shape.objects("#{self}.all", body.to_h["data"]).map { |attrs| new(attrs) }.freeze end |
Instance Method Details
#category ⇒ String?
The category of the trend
82 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 82 def category = attrs["category"] |
#deconstruct_keys(keys) ⇒ Hash{Symbol => String, nil}
Deconstruct the trend into what its readers read, so it matches a hash pattern
113 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 113 def deconstruct_keys(keys) = Utils.deconstruct(self, keys, %i[name category post_count_text trending_since_text]) |
#name ⇒ String?
The name of the trend, such as a hashtag or a phrase
74 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 74 def name = attrs["trend_name"] |
#post_count_text ⇒ String?
The number of posts about the trend, as the text X shows it
It is named for the text it is, apart from the post_count of X::Trend, which is an Integer, so that code that reads both trends never takes one for the other.
93 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 93 def post_count_text = attrs["post_count"] |
#trending_since_text ⇒ String?
How long the topic has trended, as the text X shows it
It is named for the text it is, as post_count_text is, so that it is not taken for a Time, which every other reader of when something happened answers.
104 |
# File 'x-objects/lib/x/objects/personalized_trend.rb', line 104 def trending_since_text = attrs["trending_since"] |