Class: Hikerapi::User
- Inherits:
-
Object
- Object
- Hikerapi::User
- Defined in:
- lib/hikerapi/user.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#about(user_id, options = {}) ⇒ Object
Fetch user about info.
-
#by_id(user_id, options = {}) ⇒ Object
Fetch user info by ID.
-
#by_url(url, options = {}) ⇒ Object
Fetch user info by URL.
-
#by_username(username_or_url, options = {}) ⇒ Object
Fetch user info by username.
-
#clips(user_id, options = {}, &block) ⇒ Object
Fetch user clips / reels iterator.
-
#clips_chunk(user_id, options = {}) ⇒ Object
Fetch single chunk of user clips / reels.
-
#initialize(client) ⇒ User
constructor
A new instance of User.
-
#medias(user_id, options = {}, &block) ⇒ Object
Fetch user posts (medias) iterator.
-
#medias_chunk(user_id, options = {}) ⇒ Object
Fetch a single chunk of user medias with cursor.
Constructor Details
#initialize(client) ⇒ User
Returns a new instance of User.
9 10 11 |
# File 'lib/hikerapi/user.rb', line 9 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/hikerapi/user.rb', line 7 def client @client end |
Instance Method Details
#about(user_id, options = {}) ⇒ Object
Fetch user about info
73 74 75 |
# File 'lib/hikerapi/user.rb', line 73 def about(user_id, = {}) client.get('/v1/user/about', { user_id: user_id }.merge()) end |
#by_id(user_id, options = {}) ⇒ Object
Fetch user info by ID
22 23 24 |
# File 'lib/hikerapi/user.rb', line 22 def by_id(user_id, = {}) client.get('/v1/user/by/id', { user_id: user_id }.merge()) end |
#by_url(url, options = {}) ⇒ Object
Fetch user info by URL
28 29 30 |
# File 'lib/hikerapi/user.rb', line 28 def by_url(url, = {}) client.get('/v1/user/by/url', { url: url }.merge()) end |
#by_username(username_or_url, options = {}) ⇒ Object
Fetch user info by username
15 16 17 18 |
# File 'lib/hikerapi/user.rb', line 15 def by_username(username_or_url, = {}) username = extract_username(username_or_url) client.get('/v1/user/by/username', { username: username }.merge()) end |
#clips(user_id, options = {}, &block) ⇒ Object
Fetch user clips / reels iterator
53 54 55 56 57 58 59 60 |
# File 'lib/hikerapi/user.rb', line 53 def clips(user_id, = {}, &block) iterator = ChunkIterator.new() do |cursor| opts = .dup opts[:end_cursor] = cursor if cursor && !cursor.to_s.empty? clips_chunk(user_id, opts) end block_given? ? iterator.each(&block) : iterator end |
#clips_chunk(user_id, options = {}) ⇒ Object
Fetch single chunk of user clips / reels
65 66 67 68 69 |
# File 'lib/hikerapi/user.rb', line 65 def clips_chunk(user_id, = {}) params = { user_id: user_id.to_s }.merge() params.delete(:end_cursor) if params[:end_cursor].nil? || params[:end_cursor].to_s.empty? client.get('/v1/user/clips/chunk', params) end |
#medias(user_id, options = {}, &block) ⇒ Object
Fetch user posts (medias) iterator
35 36 37 38 |
# File 'lib/hikerapi/user.rb', line 35 def medias(user_id, = {}, &block) iterator = MediaIterator.new(self, user_id, ) block_given? ? iterator.each(&block) : iterator end |
#medias_chunk(user_id, options = {}) ⇒ Object
Fetch a single chunk of user medias with cursor
43 44 45 46 47 |
# File 'lib/hikerapi/user.rb', line 43 def medias_chunk(user_id, = {}) params = { user_id: user_id.to_s }.merge() params.delete(:end_cursor) if params[:end_cursor].nil? || params[:end_cursor].to_s.empty? client.get('/v1/user/medias/chunk', params) end |