insta 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/insta.gemspec +36 -0
- data/lib/.DS_Store +0 -0
- data/lib/insta/account.rb +90 -0
- data/lib/insta/api.rb +66 -0
- data/lib/insta/configuration.rb +5 -0
- data/lib/insta/conguration.rb +5 -0
- data/lib/insta/constants.rb +20 -0
- data/lib/insta/device.rb +11852 -0
- data/lib/insta/feed.rb +68 -0
- data/lib/insta/user.rb +99 -0
- data/lib/insta/version.rb +3 -0
- data/lib/insta.rb +10 -0
- metadata +113 -0
data/lib/insta/feed.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Insta
|
2
|
+
module Feed
|
3
|
+
def self.user_media(user, data)
|
4
|
+
user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
|
5
|
+
rank_token = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
|
6
|
+
endpoint = "https://i.instagram.com/api/v1/feed/user/#{user_id}/"
|
7
|
+
param = "?rank_token=#{rank_token}" +
|
8
|
+
(!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
|
9
|
+
result = Insta::API.http(
|
10
|
+
url: endpoint + param,
|
11
|
+
method: 'GET',
|
12
|
+
user: user
|
13
|
+
)
|
14
|
+
|
15
|
+
JSON.parse result.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.user_followers(user, data, limit)
|
19
|
+
has_next_page = true
|
20
|
+
followers = []
|
21
|
+
user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
|
22
|
+
data[:rank_token] = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
|
23
|
+
while has_next_page && limit > followers.size
|
24
|
+
response = user_followers_next_page(user, user_id, data)
|
25
|
+
has_next_page = !response['next_max_id'].nil?
|
26
|
+
data[:max_id] = response['next_max_id']
|
27
|
+
followers += response['users']
|
28
|
+
end
|
29
|
+
limit.infinite? ? followers : followers[0...limit]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.user_followers_graphql(user, data, limit)
|
33
|
+
has_next_page = true
|
34
|
+
followers = []
|
35
|
+
user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
|
36
|
+
while has_next_page && limit > followers.size
|
37
|
+
response = user_followers_graphql_next_page(user, user_id, data)
|
38
|
+
has_next_page = response['data']['user']['edge_followed_by']['page_info']['has_next_page']
|
39
|
+
data[:end_cursor] = response['data']['user']['edge_followed_by']['page_info']['end_cursor']
|
40
|
+
followers += response['data']['user']['edge_followed_by']['edges']
|
41
|
+
end
|
42
|
+
limit.infinite? ? followers : followers[0...limit]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.user_followers_graphql_next_page(user, user_id, data)
|
46
|
+
endpoint = "https://www.instagram.com/graphql/query/?query_id=17851374694183129&id=#{user_id}&first=5000"
|
47
|
+
param = (!data[:end_cursor].nil? ? "&after=#{data[:end_cursor]}" : '')
|
48
|
+
result = Insta::API.http(
|
49
|
+
url: endpoint + param,
|
50
|
+
method: 'GET',
|
51
|
+
user: user
|
52
|
+
)
|
53
|
+
JSON.parse result.body
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.user_followers_next_page(user, user_id, data)
|
57
|
+
endpoint = "https://i.instagram.com/api/v1/friendships/#{user_id}/followers/"
|
58
|
+
param = "?rank_token=#{data[:rank_token]}" +
|
59
|
+
(!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
|
60
|
+
result = Insta::API.http(
|
61
|
+
url: endpoint + param,
|
62
|
+
method: 'GET',
|
63
|
+
user: user
|
64
|
+
)
|
65
|
+
JSON.parse result.body
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/insta/user.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'Insta/Device'
|
3
|
+
require 'Insta/CONSTANTS'
|
4
|
+
|
5
|
+
module Insta
|
6
|
+
class User
|
7
|
+
attr_reader :username
|
8
|
+
attr_reader :password
|
9
|
+
attr_reader :language
|
10
|
+
attr_reader :data
|
11
|
+
attr_writer :data
|
12
|
+
attr_reader :session
|
13
|
+
attr_writer :session
|
14
|
+
attr_reader :config
|
15
|
+
attr_writer :config
|
16
|
+
|
17
|
+
def initialize(username, password, session = nil, data = nil, config = nil)
|
18
|
+
@username = username
|
19
|
+
@password = password
|
20
|
+
@language = 'en_US'
|
21
|
+
@session = session
|
22
|
+
@data = data
|
23
|
+
@config = config
|
24
|
+
end
|
25
|
+
|
26
|
+
def search_for_user (username)
|
27
|
+
Insta::Account.search_for_user(self, username)
|
28
|
+
end
|
29
|
+
|
30
|
+
def search_for_user_graphql (username)
|
31
|
+
Insta::Account.search_for_graphql(self, username)
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_media(data = {})
|
35
|
+
Insta::Feed.user_media(self, data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_followers(limit = Float::INFINITY, data = {})
|
39
|
+
Insta::Feed.user_followers(self, data, limit)
|
40
|
+
end
|
41
|
+
|
42
|
+
def user_followers_graphql(limit = Float::INFINITY, data = {})
|
43
|
+
Insta::Feed.user_followers_graphql(self, data, limit)
|
44
|
+
end
|
45
|
+
|
46
|
+
def md5
|
47
|
+
Digest::MD5.hexdigest @username
|
48
|
+
end
|
49
|
+
|
50
|
+
def md5int
|
51
|
+
(md5.to_i(32) / 10e32).round
|
52
|
+
end
|
53
|
+
|
54
|
+
def api
|
55
|
+
(18 + (md5int % 5)).to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [string]
|
59
|
+
def release
|
60
|
+
%w[4.0.4 4.3.1 4.4.4 5.1.1 6.0.1][md5int % 5]
|
61
|
+
end
|
62
|
+
|
63
|
+
def dpi
|
64
|
+
%w[801 577 576 538 515 424 401 373][md5int % 8]
|
65
|
+
end
|
66
|
+
|
67
|
+
def resolution
|
68
|
+
%w[3840x2160 1440x2560 2560x1440 1440x2560
|
69
|
+
2560x1440 1080x1920 1080x1920 1080x1920][md5int % 8]
|
70
|
+
end
|
71
|
+
|
72
|
+
def info
|
73
|
+
line = Device.devices[md5int % Device.devices.count]
|
74
|
+
{
|
75
|
+
manufacturer: line[0],
|
76
|
+
device: line[1],
|
77
|
+
model: line[2]
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def useragent_hash
|
82
|
+
agent = [api + '/' + release, dpi + 'dpi',
|
83
|
+
resolution, info[:manufacturer], info[:model], info[:device], @language]
|
84
|
+
|
85
|
+
{
|
86
|
+
agent: agent.join('; '),
|
87
|
+
version: CONSTANTS::PRIVATE_KEY[:APP_VERSION]
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def useragent
|
92
|
+
format('Instagram %s Android(%s)', useragent_hash[:version], useragent_hash[:agent].rstrip)
|
93
|
+
end
|
94
|
+
|
95
|
+
def device_id
|
96
|
+
'android-' + md5[0..15]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/insta.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: insta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Renan Garcia
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Welcome to Insta gem! This Gem is hard fork from vicoerv/instagram-private-api
|
56
|
+
and the implement from huttarichard/instagram-private-api
|
57
|
+
email:
|
58
|
+
- email@renangarcia.me
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".DS_Store"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- insta.gemspec
|
76
|
+
- lib/.DS_Store
|
77
|
+
- lib/insta.rb
|
78
|
+
- lib/insta/account.rb
|
79
|
+
- lib/insta/api.rb
|
80
|
+
- lib/insta/configuration.rb
|
81
|
+
- lib/insta/conguration.rb
|
82
|
+
- lib/insta/constants.rb
|
83
|
+
- lib/insta/device.rb
|
84
|
+
- lib/insta/feed.rb
|
85
|
+
- lib/insta/user.rb
|
86
|
+
- lib/insta/version.rb
|
87
|
+
homepage: http://renangarcia.me
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
allowed_push_host: https://rubygems.org
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.7.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Welcome to Insta gem! This Gem is hard fork from vicoerv/instagram-private-api
|
112
|
+
and the implement from huttarichard/instagram-private-api
|
113
|
+
test_files: []
|