Class: IgApi::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ User

Returns a new instance of User.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ig_api/user.rb', line 9

def initialize(params = {})
  @account = nil
  @feed = nil
  @api = IgApi::Http.singleton

  if params.key? :session
    @username = params[:session].scan(/ds_user=(.*?);/)[0][0]

    id = params[:session].scan(/ds_user_id=(\d+)/)[0][0]

    if data.nil?
      @data = { id: id }
    else
      @data[:id] = id
    end
  end

  inject_variables(params)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/ig_api/user.rb', line 7

def config
  @config
end

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/ig_api/user.rb', line 7

def data
  @data
end

#languageObject (readonly)

Returns the value of attribute language.



6
7
8
# File 'lib/ig_api/user.rb', line 6

def language
  @language
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/ig_api/user.rb', line 6

def password
  @password
end

#sessionObject

Returns the value of attribute session.



7
8
9
# File 'lib/ig_api/user.rb', line 7

def session
  @session
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/ig_api/user.rb', line 7

def username
  @username
end

Instance Method Details

#accountObject



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

def 
  @account = IgApi::Account.new if @account.nil?

  @account
end

#apiObject



91
92
93
# File 'lib/ig_api/user.rb', line 91

def api
  (18 + (md5int % 5)).to_s
end

#device_idObject



133
134
135
# File 'lib/ig_api/user.rb', line 133

def device_id
  'android-' + md5[0..15]
end

#dpiObject



100
101
102
# File 'lib/ig_api/user.rb', line 100

def dpi
  %w[801 577 576 538 515 424 401 373][md5int % 8]
end

#feedObject



71
72
73
74
75
# File 'lib/ig_api/user.rb', line 71

def feed
  @feed = IgApi::Feed.new if @feed.nil?

  @feed.using(self)
end

#followers(limit = Float::INFINITY, data = {}) ⇒ Object



49
50
51
# File 'lib/ig_api/user.rb', line 49

def followers(limit = Float::INFINITY, data = {})
  IgApi::Feed.user_followers(self, data, limit)
end

#infoObject



109
110
111
112
113
114
115
116
# File 'lib/ig_api/user.rb', line 109

def info
  line = Device.devices[md5int % Device.devices.count]
  {
    manufacturer: line[0],
    device: line[1],
    model: line[2]
  }
end

#info_by_name(username) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ig_api/user.rb', line 37

def info_by_name(username)
  response = @api.get(Constants::URL + "users/#{username}/usernameinfo/")
                 .with(ua: useragent, session: session)
                 .exec

  JSON.parse response.body
end

#inject_variables(params) ⇒ Object



29
30
31
# File 'lib/ig_api/user.rb', line 29

def inject_variables(params)
  params.each { |key, value| instance_variable_set(:"@#{key}", value) }
end

#md5Object



83
84
85
# File 'lib/ig_api/user.rb', line 83

def md5
  Digest::MD5.hexdigest @username
end

#md5intObject



87
88
89
# File 'lib/ig_api/user.rb', line 87

def md5int
  (md5.to_i(32) / 10e32).round
end

#relationshipObject



57
58
59
60
61
62
63
# File 'lib/ig_api/user.rb', line 57

def relationship
  unless instance_variable_defined? :@relationship
    @relationship = Relationship.new self
  end

  @relationship
end

#releasestring

Returns:

  • (string)


96
97
98
# File 'lib/ig_api/user.rb', line 96

def release
  %w[4.0.4 4.3.1 4.4.4 5.1.1 6.0.1][md5int % 5]
end

#resolutionObject



104
105
106
107
# File 'lib/ig_api/user.rb', line 104

def resolution
  %w[3840x2160 1440x2560 2560x1440 1440x2560
     2560x1440 1080x1920 1080x1920 1080x1920][md5int % 8]
end

#search_for_user(username) ⇒ Object



33
34
35
# File 'lib/ig_api/user.rb', line 33

def search_for_user(username)
  .search_for_user(self, username)
end

#search_for_user_graphql(username) ⇒ Object



45
46
47
# File 'lib/ig_api/user.rb', line 45

def search_for_user_graphql(username)
  .search_for_graphql(self, username)
end

#threadObject



77
78
79
80
81
# File 'lib/ig_api/user.rb', line 77

def thread
  @thread = IgApi::Thread.new unless defined? @thread

  @thread.using self
end

#user_followers_graphql(limit = Float::INFINITY, data = {}) ⇒ Object



53
54
55
# File 'lib/ig_api/user.rb', line 53

def user_followers_graphql(limit = Float::INFINITY, data = {})
  IgApi::Feed.user_followers_graphql(self, data, limit)
end

#useragentObject



129
130
131
# File 'lib/ig_api/user.rb', line 129

def useragent
  format('Instagram %s Android(%s)', useragent_hash[:version], useragent_hash[:agent].rstrip)
end

#useragent_hashObject



118
119
120
121
122
123
124
125
126
127
# File 'lib/ig_api/user.rb', line 118

def useragent_hash
  agent = [api + '/' + release, dpi + 'dpi',
           resolution, info[:manufacturer],
           info[:model], info[:device], @language]

  {
    agent: agent.join('; '),
    version: Constants::PRIVATE_KEY[:APP_VERSION]
  }
end