Class: Hikerapi::Media

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Media

Returns a new instance of Media.



9
10
11
# File 'lib/hikerapi/media.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/media.rb', line 7

def client
  @client
end

Instance Method Details

#by_code(code_or_url, options = {}) ⇒ Object

Fetch media details by shortcode

Parameters:



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

def by_code(code_or_url, options = {})
  code = extract_shortcode(code_or_url)
  client.get('/v1/media/by/code', { code: code }.merge(options))
end

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

Fetch media details by ID

Parameters:

  • media_id (String, Integer)

    Media ID



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

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

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

Fetch media details by URL

Parameters:

  • url (String)

    Post/reel URL



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

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

#comments(media_id_or_code_or_url, options = {}, &block) ⇒ Object

Fetch comments iterator for a media post or reel

Parameters:

  • media_id_or_code_or_url (String, Integer)

    Media ID, shortcode, or post URL

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

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



35
36
37
38
39
40
41
42
# File 'lib/hikerapi/media.rb', line 35

def comments(media_id_or_code_or_url, options = {}, &block)
  iterator = ChunkIterator.new(options) do |cursor|
    opts = options.dup
    opts[:max_id] = cursor if cursor && !cursor.to_s.empty?
    comments_chunk(media_id_or_code_or_url, opts)
  end
  block_given? ? iterator.each(&block) : iterator
end

#comments_chunk(media_id_or_code_or_url, options = {}) ⇒ Object

Fetch a single chunk of comments for a media post or reel

Parameters:

  • media_id_or_code_or_url (String, Integer)

    Media ID, shortcode, or post URL

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

    Additional options



47
48
49
50
# File 'lib/hikerapi/media.rb', line 47

def comments_chunk(media_id_or_code_or_url, options = {})
  params = build_media_param(media_id_or_code_or_url).merge(options)
  client.get('/v1/media/comments/chunk', params)
end