insta 0.2.5 → 0.2.7

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: 6c18a2f951fdf5f6db5abbafe02d3e12dc7e1b5223160289dacc0fa11f8534a3
4
- data.tar.gz: 0a88dff315f50a3ed3a9ef921eb763beabd032190711e577ada9987e4767b523
3
+ metadata.gz: c2d1b5be3b57015671ed6f7ac8188d670c6b145d11105d3384fd5813abfd3735
4
+ data.tar.gz: 3262cd9ea438dd575c362e0081c5d2505cdb01f2d1d37d181576b36a13a33e58
5
5
  SHA512:
6
- metadata.gz: bb25813908172a37955af5a319bfa12ed9883db68d4561dbcb6c6917a2b480509d7707cdd46bfa65ec37d61d9dd22805caf77a442b1134e053ab2487610b43de
7
- data.tar.gz: 04d0a38ab5c2127149405bc3ad49ef9cbc62efeb608ab53f0a787a6eb8e4c5b70d276ff4b5ea2640285ed474406bcc02cce0afab4f236164b11851de52f05cad
6
+ metadata.gz: 27400d75b7681cc19668727b4617fab94b22dc35591b7fea0fe0c0926d588c5a5e47726cc5979a1a61043e8beb8b0c2a25d1a30e4ab2d55d72e9129088c69795
7
+ data.tar.gz: ee8f296dcf6b08acf82338250cdcf4c3a35781805223900d38587e16d786ad9bbd02d508a113e6c3eb85cf87b2922f54d01c6decd00b6659d7b0984995cb8963
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insta (0.2.5)
4
+ insta (0.2.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/insta/account.rb CHANGED
@@ -34,12 +34,14 @@ module Insta
34
34
  user.session = cookies
35
35
  end
36
36
 
37
- def self.search_for_user_graphql(user, username)
37
+ def self.search_for_user_graphql(user, username, data)
38
38
  endpoint = "https://www.instagram.com/#{username}/?__a=1"
39
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
39
40
  result = Insta::API.http(
40
41
  url: endpoint,
41
42
  method: 'GET',
42
- user: user
43
+ user: user,
44
+ proxy: proxies&.next
43
45
  )
44
46
  response = JSON.parse result.body, symbolize_names: true
45
47
  return nil unless response[:user].any?
@@ -59,14 +61,16 @@ module Insta
59
61
  }
60
62
  end
61
63
 
62
- def self.search_for_user(user, username)
64
+ def self.search_for_user(user, username, data)
63
65
  rank_token = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
64
66
  endpoint = 'https://i.instagram.com/api/v1/users/search/'
67
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
65
68
  param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token)
66
69
  result = Insta::API.http(
67
70
  url: endpoint + param,
68
71
  method: 'GET',
69
- user: user
72
+ user: user,
73
+ proxy: proxies&.next
70
74
  )
71
75
 
72
76
  json_result = JSON.parse result.body
data/lib/insta/api.rb CHANGED
@@ -39,7 +39,6 @@ module Insta
39
39
  def self.http(args)
40
40
  args[:url] = URI.parse(args[:url])
41
41
  proxy = args[:proxy]
42
-
43
42
  if proxy
44
43
  http = Net::HTTP::Proxy(proxy.dig(:host), proxy.dig(:port), proxy.dig(:username), proxy.dig(:password)).new(args[:url].host, args[:url].port)
45
44
  else
data/lib/insta/feed.rb CHANGED
@@ -4,14 +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 = Insta::ProxyManager.new data[:proxys] unless data[:proxys].nil?
7
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
8
8
  param = "?rank_token=#{rank_token}" +
9
9
  (!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
10
10
  result = Insta::API.http(
11
11
  url: endpoint + param,
12
12
  method: 'GET',
13
13
  user: user,
14
- proxy: proxys&.next
14
+ proxy: proxies&.next
15
15
  )
16
16
 
17
17
  JSON.parse result.body
@@ -20,12 +20,12 @@ module Insta
20
20
  def self.user_media_graphql(user, data)
21
21
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
22
22
  endpoint = "https://www.instagram.com/graphql/query/?query_id=17880160963012870&id=#{user_id}&first=80&after="
23
- proxys = Insta::ProxyManager.new data[:proxys] unless data[:proxys].nil?
23
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
24
24
  result = Insta::API.http(
25
25
  url: endpoint,
26
26
  method: 'GET',
27
27
  user: user,
28
- proxy: proxys&.next,
28
+ proxy: proxies&.next,
29
29
  desktop: true
30
30
  )
31
31
 
@@ -36,10 +36,10 @@ module Insta
36
36
  has_next_page = true
37
37
  followers = []
38
38
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
39
- proxys = Insta::ProxyManager.new data[:proxys] unless data[:proxys].nil?
39
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
40
40
  data[:rank_token] = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
41
41
  while has_next_page && limit > followers.size
42
- response = user_followers_next_page(user, user_id, data, proxys)
42
+ response = user_followers_next_page(user, user_id, data, proxies)
43
43
  has_next_page = !response['next_max_id'].nil?
44
44
  data[:max_id] = response['next_max_id']
45
45
  followers += response['users']
@@ -51,9 +51,9 @@ module Insta
51
51
  has_next_page = true
52
52
  followers = []
53
53
  user_id = (!data[:id].nil? ? data[:id] : user.data[:id])
54
- proxys = Insta::ProxyManager.new data[:proxys] unless data[:proxys].nil?
54
+ proxies = Insta::ProxyManager.new data[:proxies] unless data[:proxies].nil?
55
55
  while has_next_page && limit > followers.size
56
- response = user_followers_graphql_next_page(user, user_id, data, proxys)
56
+ response = user_followers_graphql_next_page(user, user_id, data, proxies)
57
57
  has_next_page = response['data']['user']['edge_followed_by']['page_info']['has_next_page']
58
58
  data[:end_cursor] = response['data']['user']['edge_followed_by']['page_info']['end_cursor']
59
59
  followers += response['data']['user']['edge_followed_by']['edges']
@@ -61,19 +61,19 @@ module Insta
61
61
  limit.infinite? ? followers : followers[0...limit]
62
62
  end
63
63
 
64
- def self.user_followers_graphql_next_page(user, user_id, data, proxys)
64
+ def self.user_followers_graphql_next_page(user, user_id, data, proxies)
65
65
  endpoint = "https://www.instagram.com/graphql/query/?query_id=17851374694183129&id=#{user_id}&first=5000"
66
66
  param = (!data[:end_cursor].nil? ? "&after=#{data[:end_cursor]}" : '')
67
67
  result = Insta::API.http(
68
68
  url: endpoint + param,
69
69
  method: 'GET',
70
70
  user: user,
71
- proxy: proxys&.next
71
+ proxy: proxies&.next
72
72
  )
73
73
  JSON.parse result.body
74
74
  end
75
75
 
76
- def self.user_followers_next_page(user, user_id, data, proxys)
76
+ def self.user_followers_next_page(user, user_id, data, proxies)
77
77
  endpoint = "https://i.instagram.com/api/v1/friendships/#{user_id}/followers/"
78
78
  param = "?rank_token=#{data[:rank_token]}" +
79
79
  (!data[:max_id].nil? ? '&max_id=' + data[:max_id] : '')
@@ -81,7 +81,7 @@ module Insta
81
81
  url: endpoint + param,
82
82
  method: 'GET',
83
83
  user: user,
84
- proxy: proxys&.next
84
+ proxy: proxies&.next
85
85
  )
86
86
  JSON.parse result.body
87
87
  end
@@ -2,20 +2,20 @@ require 'securerandom'
2
2
 
3
3
  module Insta
4
4
  class ProxyManager
5
- attr_reader :proxys
6
- attr_writer :proxys
5
+ attr_reader :proxies
6
+ attr_writer :proxies
7
7
 
8
- def initialize(proxys = [])
9
- proxys.each do |proxy|
8
+ def initialize(proxies = [])
9
+ proxies.each do |proxy|
10
10
  proxy[:id] = SecureRandom.uuid
11
11
  proxy[:last_use] = nil
12
12
  end
13
- @proxys = proxys
13
+ @proxies = proxies
14
14
  end
15
15
 
16
16
  def next
17
- return nil if @proxys.nil? || @proxys.empty?
18
- next_proxy = @proxys.sort_by { |proxy| proxy[:last_use] }.first
17
+ return nil if @proxies.nil? || @proxies.empty?
18
+ next_proxy = @proxies.sort_by { |proxy| proxy[:last_use] }.first
19
19
  next_proxy[:last_use] = Time.now
20
20
  next_proxy
21
21
  end
data/lib/insta/user.rb CHANGED
@@ -23,12 +23,12 @@ module Insta
23
23
  @config = config
24
24
  end
25
25
 
26
- def search_for_user (username)
27
- Insta::Account.search_for_user(self, username)
26
+ def search_for_user (username, data = {})
27
+ Insta::Account.search_for_user(self, username, data)
28
28
  end
29
29
 
30
- def search_for_user_graphql (username)
31
- Insta::Account.search_for_graphql(self, username)
30
+ def search_for_user_graphql (username, data = {})
31
+ Insta::Account.search_for_user_graphql(self, username, data)
32
32
  end
33
33
 
34
34
  def user_media(data = {})
data/lib/insta/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Insta
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.7'.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.5
4
+ version: 0.2.7
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-19 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler