class TikToker::ProfileIterator

Overview

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

Included Modules

Defined in:

tiktoker/iterators/profile_iterator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(sec_uid : String, cursor : String) #

[View source]

Instance Method Detail

def cursor : String #

Returns the current cursor position of the iterator.


[View source]
def 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

[View source]
def 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

[View source]
def 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"

[View source]
def sec_uid : SecUID #

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


[View source]