Class: IgApi::Account
- Inherits:
-
Object
- Object
- IgApi::Account
- Defined in:
- lib/ig_api/account.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #initialized ⇒ Object
- #login(username, password, config = IgApi::Configuration.new) ⇒ Object
- #search_for_user(user, username) ⇒ Object
- #using(session) ⇒ Object
Class Method Details
.search_for_user_graphql(user, username) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ig_api/account.rb', line 65 def self.search_for_user_graphql(user, username) endpoint = "https://www.instagram.com/#{username}/?__a=1" result = IgApi::API.http( url: endpoint, method: 'GET', user: user ) response = JSON.parse result.body, symbolize_names: true return nil unless response[:user].any? { profile_id: response[:user][:id], external_url: response[:user][:external_url], followers: response[:user][:followed_by][:count], following: response[:user][:follows][:count], full_name: response[:user][:full_name], avatar_url: response[:user][:profile_pic_url], avatar_url_hd: response[:user][:profile_pic_url_hd], username: response[:user][:username], biography: response[:user][:biography], verified: response[:user][:is_verified], medias_count: response[:user][:media][:count], is_private: response[:user][:is_private] } end |
Instance Method Details
#api ⇒ Object
7 8 9 10 11 |
# File 'lib/ig_api/account.rb', line 7 def api @api = IgApi::Http.new if @api.nil? @api end |
#initialized ⇒ Object
3 4 5 |
# File 'lib/ig_api/account.rb', line 3 def initialized @api = nil end |
#login(username, password, config = IgApi::Configuration.new) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ig_api/account.rb', line 25 def login(username, password, config = IgApi::Configuration.new) user = User.new username: username, password: password request = api.post( Constants::URL + 'accounts/login/', format( 'ig_sig_key_version=4&signed_body=%s', IgApi::Http.generate_signature( device_id: user.device_id, login_attempt_user: 0, password: user.password, username: user.username, _csrftoken: 'missing', _uuid: IgApi::Http.generate_uuid ) ) ).with(ua: user.useragent).exec json_body = JSON.parse request.body logged_in_user = json_body['logged_in_user'] user.data = { id: logged_in_user['pk'], full_name: logged_in_user['full_name'], is_private: logged_in_user['is_private'], profile_pic_url: logged_in_user['profile_pic_url'], profile_pic_id: logged_in_user['profile_pic_id'], is_verified: logged_in_user['is_verified'], is_business: logged_in_user['is_business'] } = [] = request.get_fields('set-cookie') .each do || .push(.split('; ')[0]) end = .join('; ') user.config = config user.session = user end |
#search_for_user(user, username) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ig_api/account.rb', line 90 def search_for_user(user, username) rank_token = IgApi::Http.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0] endpoint = 'https://i.instagram.com/api/v1/users/search/' param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token) result = api.get(endpoint + param) .with(session: user.session, ua: user.useragent).exec json_result = JSON.parse result.body if json_result['num_results'] > 0 user_result = json_result['users'][0] user_object = IgApi::User.new username: username user_object.data = { id: user_result['pk'], full_name: user_result['full_name'], is_private: user_result['is_prive'], profile_pic_url: user_result['profile_pic_url'], profile_pic_id: user_result['profile_pic_id'], is_verified: user_result['is_verified'], is_business: user_result['is_business'] } user_object.session = user.session user_object end end |
#using(session) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ig_api/account.rb', line 13 def using(session) user = User.new session: session # response = api.get(Constants::URL + 'accounts/current_user/?edit=true') # .with(ua: user.useragent, session: user.session).exec # # response.body # user end |