insta 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da70366ba8d65dcdc2083d3409fa0b8e30c5f819dc4f6f6a934ba0cbb52ef618
4
- data.tar.gz: cbe39575d60c95d609c4cb58ef364f5a1bb6e402ccbce97c1be9b9f9638fe91a
3
+ metadata.gz: bec08114e1b9f41bfef7edcbd86c95e32675740d16d0f3c0fad3d7fb532776c8
4
+ data.tar.gz: 9293e4e4e2e629f49cd1a3c864ad797a2406b6bad6fa0f12d4595f373159cca5
5
5
  SHA512:
6
- metadata.gz: e17ccdb7aa662006c666abff601d10034ce68172efb9635bc71098f4b4dc97e80782b04d3d3df312e9a3f16efb175597fcfc55c5301a4c808ed59b74d1676174
7
- data.tar.gz: 8e7bb62ac211ec5c79395c5ef0af06dddc8d7640de439942d1538ce91dd6ae1f2dd58ba3348b7aad7c373e32c692f3d13218d8840d07e928ea46a37b67816b65
6
+ metadata.gz: 7f962c4334dec673890eac92448a1f80f426ce3d0ddd1837482ee41f4d740c7561beb44982bdc726e5cab9b2e3e46d34d3381490a4286c25a242bfc7528debc7
7
+ data.tar.gz: 9ccc419917e4d8ac676ea8f6b0df85695909f11825773a4845d54ae7395226b920f9b587d9fb3cd22a5d2f589648f59cf6f40bde93d642c0d2ad97ea6a5066b7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insta (0.2.1)
4
+ insta (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Renan Garcia']
10
10
  spec.email = ['email@renangarcia.me']
11
11
 
12
- spec.summary = 'Welcome to Insta gem! This Gem is hard fork from vicoerv/instagram-private-api and the implement from huttarichard/instagram-private-api'
12
+ spec.summary = 'Welcome to Insta(pre-alpha) gem! This Gem is hard fork from vicoerv/instagram-private-api and the implement from huttarichard/instagram-private-api'
13
13
  spec.description = spec.summary
14
14
  spec.homepage = 'http://renangarcia.me'
15
15
  spec.license = 'MIT'
@@ -7,3 +7,4 @@ require 'insta/api'
7
7
  require 'insta/constants'
8
8
  require 'insta/device'
9
9
  require 'insta/user'
10
+ require 'insta/proxy_manager'
@@ -38,8 +38,14 @@ module Insta
38
38
 
39
39
  def self.http_desktop(args)
40
40
  args[:url] = URI.parse(args[:url])
41
- proxy = args.dig(:proxys)&.sample || {}
42
- http = Net::HTTP.new(args[:url].host, args[:url].port, proxy.dig(:host), proxy.dig(:port))
41
+ proxy = args[:proxy]
42
+
43
+ if proxy
44
+ http = Net::HTTP::Proxy(proxy.dig(:host), proxy.dig(:port), proxy.dig(:username), proxy.dig(:password)).new(args[:url].host, args[:url].port)
45
+ else
46
+ http = Net::HTTP.new(args[:url].host, args[:url].port)
47
+ end
48
+
43
49
  http.use_ssl = true
44
50
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
45
51
  request = nil
@@ -59,8 +65,14 @@ module Insta
59
65
 
60
66
  def self.http(args)
61
67
  args[:url] = URI.parse(args[:url])
62
- proxy = args[:proxys].sample
63
- http = Net::HTTP.new(args[:url].host, args[:url].port, proxy.dig(:host), proxy.dig(:port))
68
+ proxy = args[:proxy]
69
+
70
+ if proxy
71
+ http = Net::HTTP::Proxy(proxy.dig(:host), proxy.dig(:port), proxy.dig(:username), proxy.dig(:password)).new(args[:url].host, args[:url].port)
72
+ else
73
+ http = Net::HTTP.new(args[:url].host, args[:url].port)
74
+ end
75
+
64
76
  http.use_ssl = true
65
77
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
78
  request = nil
@@ -4,12 +4,14 @@ module Insta
4
4
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
5
5
  rank_token = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
6
6
  endpoint = "https://i.instagram.com/api/v1/feed/user/#{user_id}/"
7
+ proxys = ProxyManager.new data[:proxys] unless data[:proxys].nil?
7
8
  param = "?rank_token=#{rank_token}" +
8
9
  (!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
9
10
  result = Insta::API.http(
10
11
  url: endpoint + param,
11
12
  method: 'GET',
12
- user: user
13
+ user: user,
14
+ proxy: proxys&.next
13
15
  )
14
16
 
15
17
  JSON.parse result.body
@@ -18,10 +20,12 @@ module Insta
18
20
  def self.user_media_graphql(user, data)
19
21
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
20
22
  endpoint = "https://www.instagram.com/graphql/query/?query_id=17880160963012870&id=#{user_id}&first=80&after="
23
+ proxys = ProxyManager.new data[:proxys] unless data[:proxys].nil?
21
24
  result = Insta::API.http(
22
25
  url: endpoint,
23
26
  method: 'GET',
24
- user: user
27
+ user: user,
28
+ proxy: proxys&.next
25
29
  )
26
30
 
27
31
  JSON.parse result.body
@@ -31,9 +35,10 @@ module Insta
31
35
  has_next_page = true
32
36
  followers = []
33
37
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
38
+ proxys = ProxyManager.new data[:proxys] unless data[:proxys].nil?
34
39
  data[:rank_token] = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
35
40
  while has_next_page && limit > followers.size
36
- response = user_followers_next_page(user, user_id, data)
41
+ response = user_followers_next_page(user, user_id, data, proxys)
37
42
  has_next_page = !response['next_max_id'].nil?
38
43
  data[:max_id] = response['next_max_id']
39
44
  followers += response['users']
@@ -45,8 +50,9 @@ module Insta
45
50
  has_next_page = true
46
51
  followers = []
47
52
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
53
+ proxys = ProxyManager.new data[:proxys] unless data[:proxys].nil?
48
54
  while has_next_page && limit > followers.size
49
- response = user_followers_graphql_next_page(user, user_id, data)
55
+ response = user_followers_graphql_next_page(user, user_id, data, proxys)
50
56
  has_next_page = response['data']['user']['edge_followed_by']['page_info']['has_next_page']
51
57
  data[:end_cursor] = response['data']['user']['edge_followed_by']['page_info']['end_cursor']
52
58
  followers += response['data']['user']['edge_followed_by']['edges']
@@ -54,25 +60,27 @@ module Insta
54
60
  limit.infinite? ? followers : followers[0...limit]
55
61
  end
56
62
 
57
- def self.user_followers_graphql_next_page(user, user_id, data)
63
+ def self.user_followers_graphql_next_page(user, user_id, data, proxys)
58
64
  endpoint = "https://www.instagram.com/graphql/query/?query_id=17851374694183129&id=#{user_id}&first=5000"
59
65
  param = (!data[:end_cursor].nil? ? "&after=#{data[:end_cursor]}" : '')
60
66
  result = Insta::API.http(
61
67
  url: endpoint + param,
62
68
  method: 'GET',
63
- user: user
69
+ user: user,
70
+ proxy: proxys&.next
64
71
  )
65
72
  JSON.parse result.body
66
73
  end
67
74
 
68
- def self.user_followers_next_page(user, user_id, data)
75
+ def self.user_followers_next_page(user, user_id, data, proxys)
69
76
  endpoint = "https://i.instagram.com/api/v1/friendships/#{user_id}/followers/"
70
77
  param = "?rank_token=#{data[:rank_token]}" +
71
78
  (!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
72
79
  result = Insta::API.http(
73
80
  url: endpoint + param,
74
81
  method: 'GET',
75
- user: user
82
+ user: user,
83
+ proxy: proxys&.next
76
84
  )
77
85
  JSON.parse result.body
78
86
  end
@@ -0,0 +1,21 @@
1
+ require 'securerandom'
2
+
3
+ class ProxyManager
4
+ attr_reader :proxys
5
+ attr_writer :proxys
6
+
7
+ def initialize(proxys = [])
8
+ proxys.each do |proxy|
9
+ proxy[:id] = SecureRandom.uuid
10
+ proxy[:last_use] = nil
11
+ end
12
+ @proxys = proxys
13
+ end
14
+
15
+ def next
16
+ return nil if @proxys.nil?
17
+ next_proxy = @proxys.sort_by { |proxy| proxy[:last_use] }.first
18
+ next_proxy[:last_use] = Time.now
19
+ next_proxy
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Insta
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renan Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Welcome to Insta gem! This Gem is hard fork from vicoerv/instagram-private-api
55
+ description: Welcome to Insta(pre-alpha) gem! This Gem is hard fork from vicoerv/instagram-private-api
56
56
  and the implement from huttarichard/instagram-private-api
57
57
  email:
58
58
  - email@renangarcia.me
@@ -81,6 +81,7 @@ files:
81
81
  - lib/insta/constants.rb
82
82
  - lib/insta/device.rb
83
83
  - lib/insta/feed.rb
84
+ - lib/insta/proxy_manager.rb
84
85
  - lib/insta/user.rb
85
86
  - lib/insta/version.rb
86
87
  homepage: http://renangarcia.me
@@ -107,6 +108,6 @@ rubyforge_project:
107
108
  rubygems_version: 2.7.3
108
109
  signing_key:
109
110
  specification_version: 4
110
- summary: Welcome to Insta gem! This Gem is hard fork from vicoerv/instagram-private-api
111
+ summary: Welcome to Insta(pre-alpha) gem! This Gem is hard fork from vicoerv/instagram-private-api
111
112
  and the implement from huttarichard/instagram-private-api
112
113
  test_files: []