Class: IgApi::User
- Inherits:
-
Object
- Object
- IgApi::User
- Defined in:
- lib/ig_api/user.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#data ⇒ Object
Returns the value of attribute data.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#session ⇒ Object
Returns the value of attribute session.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #account ⇒ Object
- #api ⇒ Object
- #device_id ⇒ Object
- #dpi ⇒ Object
- #feed ⇒ Object
- #followers(limit = Float::INFINITY, data = {}) ⇒ Object
- #info ⇒ Object
-
#initialize(params = {}) ⇒ User
constructor
A new instance of User.
- #inject_variables(params) ⇒ Object
- #md5 ⇒ Object
- #md5int ⇒ Object
- #relationship ⇒ Object
- #release ⇒ string
- #resolution ⇒ Object
- #search_for_user(username) ⇒ Object
- #search_for_user_graphql(username) ⇒ Object
- #thread ⇒ Object
- #user_followers_graphql(limit = Float::INFINITY, data = {}) ⇒ Object
- #useragent ⇒ Object
- #useragent_hash ⇒ Object
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 |
# File 'lib/ig_api/user.rb', line 9 def initialize(params = {}) @account = nil @feed = nil 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
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/ig_api/user.rb', line 7 def config @config end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/ig_api/user.rb', line 7 def data @data end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
6 7 8 |
# File 'lib/ig_api/user.rb', line 6 def language @language end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/ig_api/user.rb', line 6 def password @password end |
#session ⇒ Object
Returns the value of attribute session.
7 8 9 |
# File 'lib/ig_api/user.rb', line 7 def session @session end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/ig_api/user.rb', line 7 def username @username end |
Instance Method Details
#account ⇒ Object
56 57 58 59 60 |
# File 'lib/ig_api/user.rb', line 56 def account @account = IgApi::Account.new if @account.nil? @account end |
#api ⇒ Object
82 83 84 |
# File 'lib/ig_api/user.rb', line 82 def api (18 + (md5int % 5)).to_s end |
#device_id ⇒ Object
124 125 126 |
# File 'lib/ig_api/user.rb', line 124 def device_id 'android-' + md5[0..15] end |
#dpi ⇒ Object
91 92 93 |
# File 'lib/ig_api/user.rb', line 91 def dpi %w[801 577 576 538 515 424 401 373][md5int % 8] end |
#feed ⇒ Object
62 63 64 65 66 |
# File 'lib/ig_api/user.rb', line 62 def feed @feed = IgApi::Feed.new if @feed.nil? @feed.using(self) end |
#followers(limit = Float::INFINITY, data = {}) ⇒ Object
40 41 42 |
# File 'lib/ig_api/user.rb', line 40 def followers(limit = Float::INFINITY, data = {}) IgApi::Feed.user_followers(self, data, limit) end |
#info ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/ig_api/user.rb', line 100 def info line = Device.devices[md5int % Device.devices.count] { manufacturer: line[0], device: line[1], model: line[2] } end |
#inject_variables(params) ⇒ Object
28 29 30 |
# File 'lib/ig_api/user.rb', line 28 def inject_variables(params) params.each { |key, value| instance_variable_set(:"@#{key}", value) } end |
#md5 ⇒ Object
74 75 76 |
# File 'lib/ig_api/user.rb', line 74 def md5 Digest::MD5.hexdigest @username end |
#md5int ⇒ Object
78 79 80 |
# File 'lib/ig_api/user.rb', line 78 def md5int (md5.to_i(32) / 10e32).round end |
#relationship ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ig_api/user.rb', line 48 def relationship unless instance_variable_defined? :@relationship @relationship = Relationship.new self end @relationship end |
#release ⇒ string
87 88 89 |
# File 'lib/ig_api/user.rb', line 87 def release %w[4.0.4 4.3.1 4.4.4 5.1.1 6.0.1][md5int % 5] end |
#resolution ⇒ Object
95 96 97 98 |
# File 'lib/ig_api/user.rb', line 95 def resolution %w[3840x2160 1440x2560 2560x1440 1440x2560 2560x1440 1080x1920 1080x1920 1080x1920][md5int % 8] end |
#search_for_user(username) ⇒ Object
32 33 34 |
# File 'lib/ig_api/user.rb', line 32 def search_for_user(username) account.search_for_user(self, username) end |
#search_for_user_graphql(username) ⇒ Object
36 37 38 |
# File 'lib/ig_api/user.rb', line 36 def search_for_user_graphql(username) account.search_for_graphql(self, username) end |
#thread ⇒ Object
68 69 70 71 72 |
# File 'lib/ig_api/user.rb', line 68 def thread @thread = IgApi::Thread.new unless defined? @thread @thread.using self end |
#user_followers_graphql(limit = Float::INFINITY, data = {}) ⇒ Object
44 45 46 |
# File 'lib/ig_api/user.rb', line 44 def user_followers_graphql(limit = Float::INFINITY, data = {}) IgApi::Feed.user_followers_graphql(self, data, limit) end |
#useragent ⇒ Object
120 121 122 |
# File 'lib/ig_api/user.rb', line 120 def useragent format('Instagram %s Android(%s)', useragent_hash[:version], useragent_hash[:agent].rstrip) end |
#useragent_hash ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ig_api/user.rb', line 109 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 |