Hikerapi

A zero-dependency Ruby client for HikerAPI - an Instagram Data API for developers. It uses only Ruby standard library (Net::HTTP, JSON, URI, Zlib).

Installation

Add this line to your application's Gemfile:

gem 'hikerapi', path: '../hikerapi' # Or git/gem repository reference

And then execute:

$ bundle install

Configuration

You can provide your HikerAPI key via an environment variable:

export HIKER_API_KEY='your_access_key_here'

Or via a Rails initializer or configuration block:

require 'hikerapi'

Hikerapi.configure do |config|
  config.api_key = 'your_access_key_here'
  # config.api_base_url = 'https://api.hikerapi.com' # default
end

client = Hikerapi::Client.new

Or pass it when initializing the client:

client = Hikerapi::Client.new(api_key: 'your_access_key_here')

Usage

User Information

client = Hikerapi::Client.new

# Get user info by username
user = client.user.by_username('nike')
puts user['pk'] # User ID
puts user['biography']
puts user['external_url']

# Get user info by ID
user = client.user.by_id('1234567')

# Get user info by profile URL
user = client.user.by_url('https://www.instagram.com/nike/')

User Medias (Posts) & Cursor Iteration

# Get user posts iterator (by user_id)
iterator = client.user.medias('787132')

# Get only the first chunk [ items, end_cursor ]:
items, end_cursor = client.user.medias('787132').each_chunk.first
# or:
items, end_cursor = client.user.medias_chunk('787132')

# Iterate chunk-by-chunk with end_cursor:
client.user.medias('787132').each_chunk do |chunk, end_cursor|
  puts "Fetched #{chunk.size} posts. Next cursor: #{end_cursor}"
end

# Iterate item-by-item across all chunks automatically:
client.user.medias('787132').each do |post|
  puts post['code']
end

# Standard Enumerable methods work directly:
recent_5 = client.user.medias('787132').take(5)

# Fetch user clips / reels
reels = client.user.clips('nike')
# or using shortcut:
reels = client.reels('nike')

Media Details & Comments

# Fetch comments for a post or reel (by shortcode, media ID, or URL)
comments = client.media.comments('DalGZj5uimd')
# or using shortcut:
comments = client.comments('https://www.instagram.com/p/DalGZj5uimd/')

# Fetch single media details by shortcode
media = client.media.by_code('DalGZj5uimd')

License

The gem is available as open source under the terms of the MIT License.