instagram_user 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.coveralls.yml +2 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +131 -0
- data/.travis.yml +0 -1
- data/README.md +10 -6
- data/Rakefile +2 -3
- data/instagram_user.gemspec +0 -1
- data/lib/instagram_user/client.rb +28 -18
- data/lib/instagram_user/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 41adfc12d263c381d879a09e16bb1b3df9fe76c8a6807d4ad2ab662582a44a52
|
4
|
+
data.tar.gz: 3deeefda2274bab222d58db52e6f09bb5ff6066a3d740edbd4ae5c14e5490551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa049502a33dced88eb7cf08d440f5d1ac20d2f87b49458df213aa6e533ee90a848faa77b80d508994c9e2e5d6eb995c9cec9ee404d425f80c3dae4e67328b85
|
7
|
+
data.tar.gz: 84e400614938325cbbd584de48a89608ccff6d379d383ea3e3b4d2e7c1b9f66a96741e8ec489f949118559e26a1d433df656bd15bfd3bc4ea124fd35fd11c7cc
|
data/.coveralls.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Metrics/AbcSize:
|
4
|
+
Enabled: false
|
5
|
+
# "Missing top-level class documentation comment."を無効
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
# "Prefer single-quoted strings when you don't need string interpolation or special symbols."を無効
|
10
|
+
Style/StringLiterals:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# "Line is too long"を無効
|
14
|
+
Metrics/LineLength:
|
15
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-01-29 23:22:25 +0900 using RuboCop version 0.52.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
|
12
|
+
# Include: **/*.gemspec
|
13
|
+
Gemspec/OrderedDependencies:
|
14
|
+
Exclude:
|
15
|
+
- 'instagram_user.gemspec'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
Layout/EmptyLineAfterMagicComment:
|
20
|
+
Exclude:
|
21
|
+
- 'instagram_user.gemspec'
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
# Configuration parameters: EnforcedStyle.
|
26
|
+
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
|
27
|
+
Layout/EmptyLinesAroundClassBody:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/instagram_user/client.rb'
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Cop supports --auto-correct.
|
33
|
+
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
34
|
+
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
35
|
+
Layout/IndentHash:
|
36
|
+
Exclude:
|
37
|
+
- 'lib/instagram_user/client.rb'
|
38
|
+
|
39
|
+
# Offense count: 1
|
40
|
+
# Cop supports --auto-correct.
|
41
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
42
|
+
# SupportedStyles: space, no_space
|
43
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
44
|
+
Layout/SpaceBeforeBlockBraces:
|
45
|
+
Exclude:
|
46
|
+
- 'lib/instagram_user/client.rb'
|
47
|
+
|
48
|
+
# Offense count: 1
|
49
|
+
# Cop supports --auto-correct.
|
50
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
51
|
+
# SupportedStyles: space, no_space
|
52
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
53
|
+
Layout/SpaceInsideBlockBraces:
|
54
|
+
Exclude:
|
55
|
+
- 'Gemfile'
|
56
|
+
|
57
|
+
# Offense count: 3
|
58
|
+
# Cop supports --auto-correct.
|
59
|
+
# Configuration parameters: EnforcedStyle.
|
60
|
+
# SupportedStyles: final_newline, final_blank_line
|
61
|
+
Layout/TrailingBlankLines:
|
62
|
+
Exclude:
|
63
|
+
- 'Rakefile'
|
64
|
+
- 'lib/instagram_user/client.rb'
|
65
|
+
- 'spec/instagram_user_spec.rb'
|
66
|
+
|
67
|
+
# Offense count: 1
|
68
|
+
Metrics/CyclomaticComplexity:
|
69
|
+
Max: 9
|
70
|
+
|
71
|
+
# Offense count: 1
|
72
|
+
# Configuration parameters: CountComments.
|
73
|
+
Metrics/MethodLength:
|
74
|
+
Max: 15
|
75
|
+
|
76
|
+
# Offense count: 1
|
77
|
+
Metrics/PerceivedComplexity:
|
78
|
+
Max: 9
|
79
|
+
|
80
|
+
# Offense count: 2
|
81
|
+
# Cop supports --auto-correct.
|
82
|
+
Style/Encoding:
|
83
|
+
Exclude:
|
84
|
+
- 'instagram_user.gemspec'
|
85
|
+
- 'lib/instagram_user/client.rb'
|
86
|
+
|
87
|
+
# Offense count: 2
|
88
|
+
# Configuration parameters: .
|
89
|
+
# SupportedStyles: annotated, template, unannotated
|
90
|
+
Style/FormatStringToken:
|
91
|
+
EnforcedStyle: unannotated
|
92
|
+
|
93
|
+
# Offense count: 2
|
94
|
+
# Cop supports --auto-correct.
|
95
|
+
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
96
|
+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
97
|
+
Style/HashSyntax:
|
98
|
+
Exclude:
|
99
|
+
- 'Rakefile'
|
100
|
+
|
101
|
+
# Offense count: 2
|
102
|
+
# Cop supports --auto-correct.
|
103
|
+
# Configuration parameters: PreferredDelimiters.
|
104
|
+
Style/PercentLiteralDelimiters:
|
105
|
+
Exclude:
|
106
|
+
- 'instagram_user.gemspec'
|
107
|
+
|
108
|
+
# Offense count: 1
|
109
|
+
# Cop supports --auto-correct.
|
110
|
+
Style/RedundantFreeze:
|
111
|
+
Exclude:
|
112
|
+
- 'lib/instagram_user/client.rb'
|
113
|
+
|
114
|
+
# Offense count: 2
|
115
|
+
# Cop supports --auto-correct.
|
116
|
+
Style/UnneededPercentQ:
|
117
|
+
Exclude:
|
118
|
+
- 'instagram_user.gemspec'
|
119
|
+
|
120
|
+
# Offense count: 1
|
121
|
+
# Cop supports --auto-correct.
|
122
|
+
# Configuration parameters: MinSize, WordRegex.
|
123
|
+
# SupportedStyles: percent, brackets
|
124
|
+
Style/WordArray:
|
125
|
+
EnforcedStyle: brackets
|
126
|
+
|
127
|
+
# Offense count: 10
|
128
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
129
|
+
# URISchemes: http, https
|
130
|
+
Metrics/LineLength:
|
131
|
+
Max: 157
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# InstagramUser
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/instagram_user.svg?style=flat)](http://badge.fury.io/rb/instagram_user)
|
4
|
-
[![Build Status](https://img.shields.io/travis/
|
5
|
-
[![Coverage Status](https://img.shields.io/coveralls/
|
6
|
-
[![Code Climate](https://img.shields.io/codeclimate/github/
|
7
|
-
|
4
|
+
[![Build Status](https://img.shields.io/travis/YuzuruS/instagram_user.svg?style=flat)](https://travis-ci.org/YuzuruS/instagram_user)
|
5
|
+
[![Coverage Status](https://img.shields.io/coveralls/YuzuruS/instagram_user.svg?style=flat)](https://coveralls.io/r/YuzuruS/instagram_user?branch=master)
|
6
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/YuzuruS/instagram_user.svg?style=flat)](https://codeclimate.com/github/YuzuruS/instagram_user)
|
7
|
+
|
8
|
+
Client for the Instagram Web Service for getting list of followers and follows without Instagram API.
|
9
|
+
It uses scraping and private api for instagram.
|
10
|
+
It may be unusable in the future because of using private api in the future.
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -26,10 +29,11 @@ Or install it yourself as:
|
|
26
29
|
|
27
30
|
```ruby
|
28
31
|
cli = InstagramUser.new(user_name: 'yuzuru_dev', password: 'PASSWORD')
|
29
|
-
|
32
|
+
|
33
|
+
follows = cli.get_follows('yuzuru_dev')
|
30
34
|
# => ["yudsuzuk", "instagram"]
|
31
35
|
|
32
|
-
followers = cli.get_followers(
|
36
|
+
followers = cli.get_followers('yuzuru_dev')
|
33
37
|
# => ["yudsuzuk"]
|
34
38
|
```
|
35
39
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'bundler/gem_tasks'
|
3
2
|
require 'rspec/core/rake_task'
|
4
3
|
require 'coveralls/rake/task'
|
@@ -13,5 +12,5 @@ RuboCop::RakeTask.new(:style)
|
|
13
12
|
|
14
13
|
Coveralls::RakeTask.new
|
15
14
|
|
16
|
-
task :default =>
|
17
|
-
task :ci =>
|
15
|
+
task :default => ["rspec", "style"]
|
16
|
+
task :ci => ["rspec", "style", "coveralls:push"]
|
data/instagram_user.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'mechanize'
|
4
2
|
require 'json'
|
5
3
|
require 'instagram_user/version'
|
@@ -9,8 +7,9 @@ module InstagramUser
|
|
9
7
|
|
10
8
|
BASE_URL = 'https://www.instagram.com/graphql/query/?query_hash=%s&variables=%s'.freeze
|
11
9
|
LOGIN_URL = 'https://www.instagram.com/accounts/login/ajax/'.freeze
|
10
|
+
USER_INFO_URL = 'https://www.instagram.com/%s/?__a=1'.freeze
|
12
11
|
DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'.freeze
|
13
|
-
DEFAULT_MAX_NUM_USERS = 3000
|
12
|
+
DEFAULT_MAX_NUM_USERS = 3000
|
14
13
|
DEFAULT_REFERER = 'https://www.instagram.com/'.freeze
|
15
14
|
|
16
15
|
USER_MAP = {
|
@@ -31,44 +30,55 @@ module InstagramUser
|
|
31
30
|
@referer = (ENV['INSTAGRAM_REFERER'] || options[:referer] || DEFAULT_REFERER)
|
32
31
|
@num_users = (ENV['INSTAGRAM_NUM_USERS'] || options[:num_users] || DEFAULT_MAX_NUM_USERS)
|
33
32
|
@session = Mechanize.new
|
33
|
+
@user_ids = {}
|
34
34
|
logined_session
|
35
35
|
end
|
36
36
|
|
37
|
-
def get_follows(
|
37
|
+
def get_follows(user_name)
|
38
|
+
user_id = @user_ids[user_name].nil? ? get_user_id(user_name) : @user_ids[user_name]
|
38
39
|
fetch_all_user_names(user_id, USER_MAP[:follow])
|
39
40
|
end
|
40
41
|
|
41
|
-
def get_followers(
|
42
|
+
def get_followers(user_name)
|
43
|
+
user_id = @user_ids[user_name].nil? ? get_user_id(user_name) : @user_ids[user_name]
|
42
44
|
fetch_all_user_names(user_id, USER_MAP[:follower])
|
43
45
|
end
|
44
46
|
|
45
47
|
private
|
46
48
|
|
49
|
+
def get_user_id(user_name)
|
50
|
+
url = USER_INFO_URL % [user_name]
|
51
|
+
page = @session.get(url)
|
52
|
+
json = JSON.parse(page.body)
|
53
|
+
@user_ids[user_name] = json["user"]["id"]
|
54
|
+
@user_ids[user_name]
|
55
|
+
end
|
56
|
+
|
47
57
|
def logined_session
|
48
58
|
@session.request_headers = login_http_headers
|
49
|
-
@session.post(LOGIN_URL,
|
59
|
+
@session.post(LOGIN_URL, user_info)
|
50
60
|
end
|
51
61
|
|
52
62
|
def login_http_headers
|
53
63
|
{
|
54
|
-
"user-agent"
|
55
|
-
"referer"
|
56
|
-
"x-csrftoken"
|
57
|
-
"cookie"
|
64
|
+
"user-agent" => @user_agent,
|
65
|
+
"referer" => @referer,
|
66
|
+
"x-csrftoken" => "null",
|
67
|
+
"cookie" => "sessionid=null; csrftoken=null"
|
58
68
|
}
|
59
69
|
end
|
60
70
|
|
61
71
|
def username_http_headers
|
62
72
|
{
|
63
|
-
"user-agent"
|
64
|
-
"referer"
|
73
|
+
"user-agent" => @user_agent,
|
74
|
+
"referer" => @referer
|
65
75
|
}
|
66
76
|
end
|
67
77
|
|
68
|
-
def
|
78
|
+
def user_info
|
69
79
|
{
|
70
|
-
|
71
|
-
|
80
|
+
username: @user_name,
|
81
|
+
password: @password
|
72
82
|
}
|
73
83
|
end
|
74
84
|
|
@@ -88,10 +98,10 @@ module InstagramUser
|
|
88
98
|
def fetch_user_names(user_id, request_params, after = nil)
|
89
99
|
variables = {
|
90
100
|
id: user_id,
|
91
|
-
first: @num_users
|
101
|
+
first: @num_users
|
92
102
|
}
|
93
103
|
variables[:after] = after unless after.nil?
|
94
|
-
url =
|
104
|
+
url = BASE_URL % [request_params[:query_hash], JSON.generate(variables)]
|
95
105
|
@session.request_headers = username_http_headers
|
96
106
|
page = @session.get(url)
|
97
107
|
json = JSON.parse(page.body)
|
@@ -99,7 +109,7 @@ module InstagramUser
|
|
99
109
|
{
|
100
110
|
after: edge["page_info"]["end_cursor"],
|
101
111
|
has_next: edge["page_info"]["has_next_page"],
|
102
|
-
user_names: edge["edges"].map{|f| f["node"]["username"]}
|
112
|
+
user_names: edge["edges"].map{ |f| f["node"]["username"] }
|
103
113
|
}
|
104
114
|
end
|
105
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagram_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuzuru Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -144,8 +144,11 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
+
- ".coveralls.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rspec"
|
150
|
+
- ".rubocop.yml"
|
151
|
+
- ".rubocop_todo.yml"
|
149
152
|
- ".travis.yml"
|
150
153
|
- CODE_OF_CONDUCT.md
|
151
154
|
- Gemfile
|
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
182
|
version: '0'
|
180
183
|
requirements: []
|
181
184
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.7.4
|
183
186
|
signing_key:
|
184
187
|
specification_version: 4
|
185
188
|
summary: Getting following and follower user list on Instagram
|