class

TikToker::ProfileIterator

Inherits Iterator / Enumerable / Reference / Object

A ProfileIterator allows iterating a TikTok::UserProfile by page.

For example:

iterator = TikToker::ProfileIterator.new("SecUID", "0")
iterator.next # => Page 1
iterator.next # => Page 2
iterator.next # => Iterator::Stop

Most of the time, what you really want is to iterate through the posts without having to worry about pagination. See #each_post.

iterator = TikToker::ProfileIterator.new("SecUID", "0")
iterator.each_post do |post|
  post # => TikTok::Post
end

Constructors

new(sec_uid : String, cursor : String)
Source

Instance methods

cursor

Returns the current cursor position of the iterator.

Source
each_post

Yields successive posts from the user profile. It iterates through all pages from the current cursor to the oldest post.

iterator = TikToker::ProfileIterator.new(SEC_UID, "0")
iterator.each_post do |post|
  post # => TikTok::Post
end
Source
has_more?

Returns true until the iterator receives a TikTok response indicating that the user profile has been fully iterated over.

iterator = TikToker::ProfileIterator.new(SEC_UID, "0")
iterator.has_more? # => true
iterator.next      # => TikTok::PostCollection
iterator.has_more? # => false
iterator.next      # => Iterator::Stop
Source
next

Fetches the next page from the user profile, and updates the cursor position. Raises TikToker::NoPostsError if TikTok API returns no posts for the given sec_uid.

iterator = TikToker::ProfileIterator.new(SEC_UID, "0")
iterator.cursor # => "0"
iterator.next   # => Array(TikTok::Post)
iterator.cursor # => "1614377227000"
Source
sec_uid

Returns the secUid of the owner of the profile being iterated through.

Source