Class: X::Trend
- Inherits:
-
Object
- Object
- X::Trend
- Includes:
- Serialization, ValueEquality, ValueMarshalling
- Defined in:
- x-objects/lib/x/objects/trend.rb
Overview
A topic trending in a place, as the trends of the place report it
A trend has no identifier, and the API offers no lookup of one, so trends are read a place at a time, a place named by its Yahoo! Where On Earth identifier (WOEID), such as 1 for the whole world.
Constant Summary collapse
- FIELDS =
Every trend field
A minor release may add to it the fields the API adds, so that the trends of a place ask for them too.
%w[trend_name tweet_count].freeze
Instance Attribute Summary collapse
-
#attrs ⇒ Hash{String => Object}
readonly
The raw attributes of the trend.
Class Method Summary collapse
-
.at(woeid, client:, **params) ⇒ Array<Trend>
The topics trending in a place.
Instance Method Summary collapse
-
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Deconstruct the trend into what its readers read, so it matches a hash pattern.
-
#initialize(attrs) ⇒ Trend
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 ⇒ Integer?
(also: #tweet_count)
The number of posts about the trend.
Constructor Details
#initialize(attrs) ⇒ Trend
Initialize a trend from the attributes the API reported
81 82 83 84 |
# File 'x-objects/lib/x/objects/trend.rb', line 81 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
35 36 37 |
# File 'x-objects/lib/x/objects/trend.rb', line 35 def attrs @attrs end |
Class Method Details
.at(woeid, client:, **params) ⇒ Array<Trend>
The topics trending in a place
The endpoint takes app-only authentication, or OAuth 2.0 as a user, so a client that signs with OAuth 1.0a reads the trends with a copy that authenticates as the app.
51 52 53 54 55 |
# File 'x-objects/lib/x/objects/trend.rb', line 51 def self.at(woeid, client:, **params) path = "trends/by/woeid/#{woeid_of(woeid)}" body = Utils.app_client(client).get(Utils.path(path, {"trend.fields" => FIELDS, "max_trends" => MAX_TRENDS}.merge(params)), **Utils::JSON_CLASSES) Shape.objects("#{self}.at", body.to_h["data"]).map { |attrs| new(attrs) }.freeze end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Deconstruct the trend into what its readers read, so it matches a hash pattern
A pattern that asks for every key gets name and post_count, and one can ask for the number of posts as tweet_count too, as it can of a user.
119 |
# File 'x-objects/lib/x/objects/trend.rb', line 119 def deconstruct_keys(keys) = Utils.deconstruct(self, keys, %i[name post_count], %i[tweet_count]) |
#name ⇒ String?
The name of the trend, such as a hashtag or a phrase
92 |
# File 'x-objects/lib/x/objects/trend.rb', line 92 def name = attrs["trend_name"] |
#post_count ⇒ Integer? Also known as: tweet_count
The number of posts about the trend
It is read from post_count, or from tweet_count, the name the API gives it before it names tweets posts there, as the post count of a user is.
104 |
# File 'x-objects/lib/x/objects/trend.rb', line 104 def post_count = Utils.read("#{self.class}#post_count", attrs["post_count"] || attrs["tweet_count"]) { |value| Shape.integer(value) } |