insta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2de0e3c65be90703324796c45b3c7243e2062b87e8172fa52d272f0db434eac8
|
4
|
+
data.tar.gz: dc6911831ddc19c61872d7d5cec20d380a312823259b45a9afc1180ae1f549a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8a2b67f56e384d60f9fbbf511f6cc98cfc4ec75643c85ef929e0c9a9ebfc86ba5164f546483d10f849f4ede5a900c70116640e7fd48cf54b64888e2a59d068e
|
7
|
+
data.tar.gz: 559cff009e1186bcde48d09bb0bc48b66fa2591709090c9a273c5595e8d7adb4a80f1a167db9f930d4245008a27eb58f05c6c3de77eb72b41da74195f940bb0c
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at email@renangarcia.me. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
insta (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
insta!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Renan Garcia
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Insta
|
2
|
+
|
3
|
+
Welcome to Insta gem! This Gem is hard fork from [VicoErv/instagram-private-api](https://github.com/VicoErv/instagram-private-api) and the implement from [huttarichard/instagram-private-api](https://github.com/huttarichard/instagram-private-api) the best `Node-JS` Insgtagram private API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'insta'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install insta
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/renan-garcia/insta. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the Insta project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/renan-garcia/insta/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "insta"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/insta.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'insta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'insta'
|
8
|
+
spec.version = Insta::VERSION
|
9
|
+
spec.authors = ['Renan Garcia']
|
10
|
+
spec.email = ['email@renangarcia.me']
|
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'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'http://renangarcia.me'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Insta
|
2
|
+
module Account
|
3
|
+
def self.login(user, config = Insta::Configuration.new)
|
4
|
+
request = Insta::API.http(
|
5
|
+
url: CONSTANTS::URL + 'accounts/login/',
|
6
|
+
method: 'POST',
|
7
|
+
user: user,
|
8
|
+
body: format(
|
9
|
+
'ig_sig_key_version=4&signed_body=%s',
|
10
|
+
Insta::API.generate_signature(
|
11
|
+
device_id: user.device_id,
|
12
|
+
login_attempt_user: 0, password: user.password, username: user.username,
|
13
|
+
_csrftoken: 'missing', _uuid: Insta::API.generate_uuid
|
14
|
+
))
|
15
|
+
)
|
16
|
+
json_body = JSON.parse request.body
|
17
|
+
logged_in_user = json_body['logged_in_user']
|
18
|
+
user.data = {
|
19
|
+
id: logged_in_user['pk'],
|
20
|
+
full_name: logged_in_user['full_name'],
|
21
|
+
is_private: logged_in_user['is_private'],
|
22
|
+
profile_pic_url: logged_in_user['profile_pic_url'],
|
23
|
+
profile_pic_id: logged_in_user['profile_pic_id'],
|
24
|
+
is_verified: logged_in_user['is_verified'],
|
25
|
+
is_business: logged_in_user['is_business']
|
26
|
+
}
|
27
|
+
cookies_array = []
|
28
|
+
all_cookies = request.get_fields('set-cookie')
|
29
|
+
all_cookies.each do |cookie|
|
30
|
+
cookies_array.push(cookie.split('; ')[0])
|
31
|
+
end
|
32
|
+
cookies = cookies_array.join('; ')
|
33
|
+
user.config = config
|
34
|
+
user.session = cookies
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.search_for_user_graphql(user, username)
|
38
|
+
endpoint = "https://www.instagram.com/#{username}/?__a=1"
|
39
|
+
result = Insta::API.http(
|
40
|
+
url: endpoint,
|
41
|
+
method: 'GET',
|
42
|
+
user: user
|
43
|
+
)
|
44
|
+
response = JSON.parse result.body, symbolize_names: true
|
45
|
+
return nil unless response[:user].any?
|
46
|
+
{
|
47
|
+
profile_id: response[:user][:id],
|
48
|
+
external_url: response[:user][:external_url],
|
49
|
+
followers: response[:user][:followed_by][:count],
|
50
|
+
following: response[:user][:follows][:count],
|
51
|
+
full_name: response[:user][:full_name],
|
52
|
+
avatar_url: response[:user][:profile_pic_url],
|
53
|
+
avatar_url_hd: response[:user][:profile_pic_url_hd],
|
54
|
+
username: response[:user][:username],
|
55
|
+
biography: response[:user][:biography],
|
56
|
+
verified: response[:user][:is_verified],
|
57
|
+
medias_count: response[:user][:media][:count],
|
58
|
+
is_private: response[:user][:is_private]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.search_for_user(user, username)
|
63
|
+
rank_token = Insta::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
|
64
|
+
endpoint = 'https://i.instagram.com/api/v1/users/search/'
|
65
|
+
param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token)
|
66
|
+
result = Insta::API.http(
|
67
|
+
url: endpoint + param,
|
68
|
+
method: 'GET',
|
69
|
+
user: user
|
70
|
+
)
|
71
|
+
|
72
|
+
json_result = JSON.parse result.body
|
73
|
+
if json_result['num_results'] > 0
|
74
|
+
user_result = json_result['users'][0]
|
75
|
+
user_object = Insta::User.new username, nil
|
76
|
+
user_object.data = {
|
77
|
+
id: user_result['pk'],
|
78
|
+
full_name: user_result['full_name'],
|
79
|
+
is_private: user_result['is_prive'],
|
80
|
+
profile_pic_url: user_result['profile_pic_url'],
|
81
|
+
profile_pic_id: user_result['profile_pic_id'],
|
82
|
+
is_verified: user_result['is_verified'],
|
83
|
+
is_business: user_result['is_business']
|
84
|
+
}
|
85
|
+
user_object.session = user.session
|
86
|
+
user_object
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/insta/api.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'Base64'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
require 'Insta/User'
|
7
|
+
require 'Insta/account'
|
8
|
+
require 'Insta/feed'
|
9
|
+
require 'Insta/Configuration'
|
10
|
+
|
11
|
+
module Insta
|
12
|
+
module API
|
13
|
+
def self.compute_hash(data)
|
14
|
+
OpenSSL::HMAC.hexdigest OpenSSL::Digest.new('sha256'), CONSTANTS::PRIVATE_KEY[:SIG_KEY], data
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.generate_uuid
|
18
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.gsub(/[xy]/) do |c|
|
19
|
+
r = (Random.rand * 16).round | 0
|
20
|
+
v = c == 'x' ? r : (r & 0x3 | 0x8)
|
21
|
+
c.gsub(c, v.to_s(16))
|
22
|
+
end.downcase
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create_md5(data)
|
26
|
+
Digest::MD5.hexdigest(data).to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.generate_device_id
|
30
|
+
timestamp = Time.now.to_i.to_s
|
31
|
+
'android-' + create_md5(timestamp)[0..16]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.generate_signature(data)
|
35
|
+
data = data.to_json
|
36
|
+
compute_hash(data) + '.' + data
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.http(args)
|
40
|
+
args[:url] = URI.parse(args[:url])
|
41
|
+
http = Net::HTTP.new(args[:url].host, args[:url].port, ENV['INSTAGRAM_PROXY_HOST'], ENV['INSTAGRAM_PROXY_PORT'])
|
42
|
+
http.use_ssl = true
|
43
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
44
|
+
request = nil
|
45
|
+
if args[:method] == 'POST'
|
46
|
+
request = Net::HTTP::Post.new(args[:url].path)
|
47
|
+
elsif args[:method] == 'GET'
|
48
|
+
request = Net::HTTP::Get.new(args[:url].path + (!args[:url].nil? ? '?' + args[:url].query : ''))
|
49
|
+
end
|
50
|
+
|
51
|
+
request.initialize_http_header(:'User-Agent' => args.dig(:user)&.useragent,
|
52
|
+
:Accept => Insta::CONSTANTS::HEADER[:accept],
|
53
|
+
:'Accept-Encoding' => Insta::CONSTANTS::HEADER[:encoding],
|
54
|
+
:'Accept-Language' => args.dig(:user)&.language,
|
55
|
+
:'X-IG-Capabilities' => Insta::CONSTANTS::HEADER[:capabilities],
|
56
|
+
:'X-IG-Connection-Type' => Insta::CONSTANTS::HEADER[:type],
|
57
|
+
:Cookie => (args.dig(:user)&.session.nil? ? '' : args.dig(:user)&.session))
|
58
|
+
request.body = args.key?(:body) ? args[:body] : nil
|
59
|
+
http.request(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.generate_rank_token(pk)
|
63
|
+
format('%s_%s', pk, Insta::API.generate_uuid)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Insta
|
2
|
+
module CONSTANTS
|
3
|
+
PRIVATE_KEY = {
|
4
|
+
SIG_KEY: '0443b39a54b05f064a4917a3d1da4d6524a3fb0878eacabf1424515051674daa'.freeze,
|
5
|
+
SIG_VERSION: '4'.freeze,
|
6
|
+
APP_VERSION: '10.33.0'.freeze
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
HEADER = {
|
10
|
+
capabilities: '3QI='.freeze,
|
11
|
+
type: 'WIFI'.freeze,
|
12
|
+
host: 'i.instagram.com'.freeze,
|
13
|
+
connection: 'Close'.freeze,
|
14
|
+
encoding: 'gzip, deflate, sdch'.freeze,
|
15
|
+
accept: '*/*'.freeze
|
16
|
+
}
|
17
|
+
|
18
|
+
URL = 'https://i.instagram.com/api/v1/'.freeze
|
19
|
+
end
|
20
|
+
end
|