Class: IgApi::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_api/feed.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeed

Returns a new instance of Feed.



3
4
5
# File 'lib/ig_api/feed.rb', line 3

def initialize
  @api = Http.singleton
end

Class Method Details

.user_followers(user, data, limit) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ig_api/feed.rb', line 39

def self.user_followers(user, data, limit)
  has_next_page = true
  followers = []
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
  data[:rank_token] = IgApi::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
  while has_next_page && limit > followers.size
    response = user_followers_next_page(user, user_id, data)
    has_next_page = !response['next_max_id'].nil?
    data[:max_id] = response['next_max_id']
    followers += response['users']
  end
  limit.infinite? ? followers : followers[0...limit]
end

.user_followers_next_page(user, user_id, data) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ig_api/feed.rb', line 53

def self.user_followers_next_page(user, user_id, data)
  endpoint = "https://i.instagram.com/api/v1/friendships/#{user_id}/followers/"
  param = "?rank_token=#{data[:rank_token]}" +
          (!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
  result = IgApi::API.http(
    url: endpoint + param,
    method: 'GET',
    user: user
  )
  JSON.parse result.body
end

Instance Method Details

#story(ids) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ig_api/feed.rb', line 16

def story(ids)
  signature = IgApi::Http.generate_signature(
    user_ids: ids.map(&:to_s)
  )
  response = @api.post(Constants::URL + 'feed/reels_media/',
                       "ig_sig_key_version=4&signed_body=#{signature}")
                 .with(session: @user[:session], ua: @user[:ua])
                 .exec

  response.body
end

#timeline_mediaObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/ig_api/feed.rb', line 28

def timeline_media
  user_id = @user[:id]

  rank_token = IgApi::Http.generate_rank_token @user[:id]
  endpoint = "https://i.instagram.com/api/v1/feed/user/#{user_id}/"
  result = @api.get(endpoint + "?rank_token=#{rank_token}")
               .with(session: @user[:session], ua: @user[:ua]).exec

  JSON.parse result.body
end

#using(user) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/ig_api/feed.rb', line 7

def using user
  @user = {
    id: user.data[:id],
    session: user.session,
    ua: user.useragent
  }
  self
end