Class: BadPigeon::TimelineEntry
- Inherits:
-
Object
- Object
- BadPigeon::TimelineEntry
- Includes:
- Assertions
- Defined in:
- lib/bad_pigeon/elements/timeline_entry.rb
Overview
Represents an “entry” which is a part of a timeline response. An entry in most cases is a wrapper for either one tweet or a group of connected tweets (e.g. a parent and a reply).
Tweets can be extracted from an entry using (#items) method, which returns an array of tweets as instances of TimelineTweet class.
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #all_tweets ⇒ Object
- #component ⇒ Object
-
#initialize(json) ⇒ TimelineEntry
constructor
A new instance of TimelineEntry.
- #item_from_content(item_content) ⇒ Object
- #items ⇒ Object
- #type ⇒ Object
Methods included from Assertions
Constructor Details
#initialize(json) ⇒ TimelineEntry
Returns a new instance of TimelineEntry.
23 24 25 26 27 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 23 def initialize(json) @json = json assert { json['entryType'] == json['__typename'] } end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
21 22 23 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 21 def json @json end |
Instance Method Details
#all_tweets ⇒ Object
37 38 39 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 37 def all_tweets items.map(&:tweet).compact end |
#component ⇒ Object
33 34 35 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 33 def component @json['clientEventInfo'] && @json['clientEventInfo']['component'] end |
#item_from_content(item_content) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 55 def item_from_content(item_content) case item_content['itemType'] when 'TimelineTweet' TimelineTweet.new(item_content) when 'TimelineUser' nil else assert("Unknown itemContent type: #{item_content['itemType']}") nil end end |
#items ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 41 def items case self.type when Type::ITEM [item_from_content(@json['itemContent'])].compact when Type::MODULE @json['items'].map { |i| item_from_content(i['item']['itemContent']) }.compact when Type::CURSOR [] else assert("Unknown entry type: #{type}") [] end end |
#type ⇒ Object
29 30 31 |
# File 'lib/bad_pigeon/elements/timeline_entry.rb', line 29 def type @json['entryType'] end |