Class: Hikerapi::User

Inherits:
Object
  • Object
show all
Defined in:
lib/hikerapi/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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

Parameters:

  • user_id (String, Integer)

    User ID



73
74
75
# File 'lib/hikerapi/user.rb', line 73

def about(user_id, options = {})
  client.get('/v1/user/about', { user_id: user_id }.merge(options))
end

#by_id(user_id, options = {}) ⇒ Object

Fetch user info by ID

Parameters:

  • user_id (String, Integer)

    User ID (pk)



22
23
24
# File 'lib/hikerapi/user.rb', line 22

def by_id(user_id, options = {})
  client.get('/v1/user/by/id', { user_id: user_id }.merge(options))
end

#by_url(url, options = {}) ⇒ Object

Fetch user info by URL

Parameters:

  • url (String)

    Instagram profile URL



28
29
30
# File 'lib/hikerapi/user.rb', line 28

def by_url(url, options = {})
  client.get('/v1/user/by/url', { url: url }.merge(options))
end

#by_username(username_or_url, options = {}) ⇒ Object

Fetch user info by username

Parameters:

  • username_or_url (String)

    Username, @handle, or Instagram profile URL



15
16
17
18
# File 'lib/hikerapi/user.rb', line 15

def by_username(username_or_url, options = {})
  username = extract_username(username_or_url)
  client.get('/v1/user/by/username', { username: username }.merge(options))
end

#clips(user_id, options = {}, &block) ⇒ Object

Fetch user clips / reels iterator

Parameters:

  • user_id (String, Integer)

    User ID

  • options (Hash) (defaults to: {})

    Additional options (e.g., end_cursor: '...')



53
54
55
56
57
58
59
60
# File 'lib/hikerapi/user.rb', line 53

def clips(user_id, options = {}, &block)
  iterator = ChunkIterator.new(options) do |cursor|
    opts = options.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

Parameters:

  • user_id (String, Integer)

    User ID

  • options (Hash) (defaults to: {})

    Additional options (e.g., end_cursor: '...')



65
66
67
68
69
# File 'lib/hikerapi/user.rb', line 65

def clips_chunk(user_id, options = {})
  params = { user_id: user_id.to_s }.merge(options)
  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

Parameters:

  • user_id (String, Integer)

    User ID

  • options (Hash) (defaults to: {})

    Additional options (e.g., end_cursor: '...')



35
36
37
38
# File 'lib/hikerapi/user.rb', line 35

def medias(user_id, options = {}, &block)
  iterator = MediaIterator.new(self, user_id, options)
  block_given? ? iterator.each(&block) : iterator
end

#medias_chunk(user_id, options = {}) ⇒ Object

Fetch a single chunk of user medias with cursor

Parameters:

  • user_id (String, Integer)

    User ID

  • options (Hash) (defaults to: {})

    Additional options (e.g., end_cursor: '...')



43
44
45
46
47
# File 'lib/hikerapi/user.rb', line 43

def medias_chunk(user_id, options = {})
  params = { user_id: user_id.to_s }.merge(options)
  params.delete(:end_cursor) if params[:end_cursor].nil? || params[:end_cursor].to_s.empty?
  client.get('/v1/user/medias/chunk', params)
end