Class: Hikerapi::Media
- Inherits:
-
Object
- Object
- Hikerapi::Media
- Defined in:
- lib/hikerapi/media.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#by_code(code_or_url, options = {}) ⇒ Object
Fetch media details by shortcode.
-
#by_id(media_id, options = {}) ⇒ Object
Fetch media details by ID.
-
#by_url(url, options = {}) ⇒ Object
Fetch media details by URL.
-
#comments(media_id_or_code_or_url, options = {}, &block) ⇒ Object
Fetch comments iterator for a media post or reel.
-
#comments_chunk(media_id_or_code_or_url, options = {}) ⇒ Object
Fetch a single chunk of comments for a media post or reel.
-
#initialize(client) ⇒ Media
constructor
A new instance of Media.
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
#client ⇒ Object (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
15 16 17 18 |
# File 'lib/hikerapi/media.rb', line 15 def by_code(code_or_url, = {}) code = extract_shortcode(code_or_url) client.get('/v1/media/by/code', { code: code }.merge()) end |
#by_id(media_id, options = {}) ⇒ Object
Fetch media details by ID
22 23 24 |
# File 'lib/hikerapi/media.rb', line 22 def by_id(media_id, = {}) client.get('/v1/media/by/id', { id: media_id }.merge()) end |
#by_url(url, options = {}) ⇒ Object
Fetch media details by URL
28 29 30 |
# File 'lib/hikerapi/media.rb', line 28 def by_url(url, = {}) client.get('/v1/media/by/url', { url: url }.merge()) end |
#comments(media_id_or_code_or_url, options = {}, &block) ⇒ Object
Fetch comments iterator for a media post or reel
35 36 37 38 39 40 41 42 |
# File 'lib/hikerapi/media.rb', line 35 def comments(media_id_or_code_or_url, = {}, &block) iterator = ChunkIterator.new() do |cursor| opts = .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
47 48 49 50 |
# File 'lib/hikerapi/media.rb', line 47 def comments_chunk(media_id_or_code_or_url, = {}) params = build_media_param(media_id_or_code_or_url).merge() client.get('/v1/media/comments/chunk', params) end |