Class: IgApi::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, session = nil, data = nil, config = nil) ⇒ User



16
17
18
19
20
21
22
23
24
25
# File 'lib/IgApi/user.rb', line 16

def initialize(username, password, session = nil, data = nil, config = nil)
  @username = username
  @password = password
  @language = 'en_US'
  @session = session
  @data = data
  @config = config
  @account = nil
  @feed = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



13
14
15
# File 'lib/IgApi/user.rb', line 13

def config
  @config
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/IgApi/user.rb', line 9

def data
  @data
end

#languageObject (readonly)

Returns the value of attribute language.



8
9
10
# File 'lib/IgApi/user.rb', line 8

def language
  @language
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#sessionObject

Returns the value of attribute session.



11
12
13
# File 'lib/IgApi/user.rb', line 11

def session
  @session
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#accountObject



51
52
53
54
55
# File 'lib/IgApi/user.rb', line 51

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

  @account
end

#apiObject



71
72
73
# File 'lib/IgApi/user.rb', line 71

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

#device_idObject



113
114
115
# File 'lib/IgApi/user.rb', line 113

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

#dpiObject



80
81
82
# File 'lib/IgApi/user.rb', line 80

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

#feedObject



57
58
59
60
61
# File 'lib/IgApi/user.rb', line 57

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

  @feed.using(self)
end

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



35
36
37
# File 'lib/IgApi/user.rb', line 35

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

#infoObject



89
90
91
92
93
94
95
96
# File 'lib/IgApi/user.rb', line 89

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

#md5Object



63
64
65
# File 'lib/IgApi/user.rb', line 63

def md5
  Digest::MD5.hexdigest @username
end

#md5intObject



67
68
69
# File 'lib/IgApi/user.rb', line 67

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

#relationshipObject



43
44
45
46
47
48
49
# File 'lib/IgApi/user.rb', line 43

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

  @relationship
end

#releasestring



76
77
78
# File 'lib/IgApi/user.rb', line 76

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

#resolutionObject



84
85
86
87
# File 'lib/IgApi/user.rb', line 84

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

#search_for_user(username) ⇒ Object



27
28
29
# File 'lib/IgApi/user.rb', line 27

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

#search_for_user_graphql(username) ⇒ Object



31
32
33
# File 'lib/IgApi/user.rb', line 31

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

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



39
40
41
# File 'lib/IgApi/user.rb', line 39

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

#useragentObject



109
110
111
# File 'lib/IgApi/user.rb', line 109

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

#useragent_hashObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/IgApi/user.rb', line 98

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