instagram-private-api 0.1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efb18574c9777d39682c3f43af28b74c243ff80f
4
+ data.tar.gz: 932785b19d1353d25265763d84ecd24cd5d99a90
5
+ SHA512:
6
+ metadata.gz: '08babf9c8d62f36e5a62ac3b504675df7f4c18920c979e45d37d92c01e45cfd9ce891ed7eafc518ed140437b0b8df9aedac3a7d8582792d02f2f7ba7d9b93cc3'
7
+ data.tar.gz: a83137d0a11db33047504ec92b4657075863221b750617e367ba939ae959bbae6936939abaf7cf705b81bbeebdd5fb6cd073bbd2162ebab5c5a2f5073dede65e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
@@ -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 vicoerv@gmail.com. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in Instagram-API.gemspec
6
+ gemspec
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Instagram/API/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'instagram-private-api'
8
+ spec.version = Instagram::API::VERSION
9
+ spec.authors = ['vicoerv']
10
+ spec.email = ['vicoerv@gmail.com']
11
+
12
+ spec.summary = 'Instagram private api, implemented from huttarichard/instagram-private-api as best NODE-JS Instagram api'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'http://www.vicoervanda.com'
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 atsuko_maeda_official
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,76 @@
1
+ # Instagram::API
2
+
3
+ Welcome to Instagram-API gem! This Gem is implemented from [huttarichard/instagram-private-api](https://github.com/huttarichard/instagram-private-api) the best `Node-JS` Insgtagram private API
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'instagram-private-api'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install instagram-private-api
19
+
20
+ ## Usage
21
+ - Login _for clearly new user_
22
+ ```ruby
23
+ user = Instagram::User.new 'username', 'password'
24
+ p Instagram::API::Accounts.login user
25
+ ```
26
+
27
+ - Initiate existing user
28
+ ```ruby
29
+ logged_in_user = User.find(id: 1) #User as Model
30
+ data = {}
31
+ data[:id] = logged_in_user.pk
32
+ data[:full_name] = logged_in_user.full_name
33
+ data[:is_private] = logged_in_user.is_private
34
+ data[:profile_pic_url] = logged_in_user.profile_pic_url
35
+ data[:profile_pic_id] = logged_in_user.profile_pic_id
36
+ data[:is_verified] = logged_in_user.is_verified
37
+ data[:is_business] = logged_in_user.is_business
38
+ session = logged_in_user.session
39
+
40
+ user = Instagram::User.new 'username', nil, data, session #password isn't mandatory, already have session
41
+ p user.search_for_user 'ogiyuka_ippaiwarae216' #then you can use it for any purpose
42
+ ```
43
+
44
+ - Search for user
45
+ ```ruby
46
+ p user.search_for_user 'ogiyuka_ippaiwarae216'
47
+ ```
48
+
49
+ - User feed
50
+ ```ruby
51
+ p user.user_media #your feed
52
+
53
+ user_target = user.search_for_user 'ogiyuka_ippaiwarae216'
54
+ p user.user_media user_id: user_target.data[:id] #ogiyuka_ippaiwarae216 feed, or
55
+ media = user_target.user_media #ogiyuka_ippaiwarae216 feed as shorthand
56
+ if media['next_available']
57
+ p user_target.user_media max_id: media['next_max_id'] #next page
58
+ end
59
+ ```
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/vicoerv/Instagram-API](https://github.com/vicoerv/instagram-private-api). 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.
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Instagram::API project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vicoerv/instagram-private-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Instagram/API"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/Instagram.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Instagram
2
+ end
3
+
4
+ require 'Instagram/API'
5
+ require 'Instagram/CONSTANTS'
6
+ require 'Instagram/Device'
7
+ require 'Instagram/User'
@@ -0,0 +1,5 @@
1
+ module Instagram
2
+ module API
3
+ VERSION = "0.1.5.2"
4
+ end
5
+ end
@@ -0,0 +1,69 @@
1
+ module Instagram
2
+ module Account
3
+ def self.login(user)
4
+ request = Instagram::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
+ Instagram::API.generate_signature(
11
+ device_id: user.device_id,
12
+ login_attempt_user: 0, password: user.password, username: user.username,
13
+ _csrftoken: 'missing', _uuid: Instagram::API.generate_uuid
14
+ ))
15
+ )
16
+ if request.code == '200'
17
+ json_body = JSON.parse request.body
18
+ logged_in_user = json_body['logged_in_user']
19
+ user.data = {
20
+ id: logged_in_user['pk'],
21
+ full_name: logged_in_user['full_name'],
22
+ is_private: logged_in_user['is_private'],
23
+ profile_pic_url: logged_in_user['profile_pic_url'],
24
+ profile_pic_id: logged_in_user['profile_pic_id'],
25
+ is_verified: logged_in_user['is_verified'],
26
+ is_business: logged_in_user['is_business']
27
+ }
28
+ cookies_array = []
29
+ all_cookies = request.get_fields('set-cookie')
30
+ all_cookies.each do |cookie|
31
+ cookies_array.push(cookie.split('; ')[0])
32
+ end
33
+ cookies = cookies_array.join('; ')
34
+ user.session = cookies
35
+ true
36
+ else
37
+ false
38
+ end
39
+ end
40
+
41
+ def self.search_for_user(user, username)
42
+ rank_token = Instagram::API.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
43
+ endpoint = 'https://i.instagram.com/api/v1/users/search/'
44
+ param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token)
45
+ result = Instagram::API.http(
46
+ url: endpoint + param,
47
+ method: 'GET',
48
+ user: user
49
+ )
50
+
51
+ json_result = JSON.parse result.body
52
+ if json_result['num_results'] > 0
53
+ user_result = json_result['users'][0]
54
+ user_object = Instagram::User.new username, nil
55
+ user_object.data = {
56
+ id: user_result['pk'],
57
+ full_name: user_result['full_name'],
58
+ is_private: user_result['is_prive'],
59
+ profile_pic_url: user_result['profile_pic_url'],
60
+ profile_pic_id: user_result['profile_pic_id'],
61
+ is_verified: user_result['is_verified'],
62
+ is_business: user_result['is_business']
63
+ }
64
+ user_object.session = user.session
65
+ user_object
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ require 'Instagram/API/version'
2
+ require 'openssl'
3
+ require 'Base64'
4
+ require 'digest/md5'
5
+ require 'net/http'
6
+ require 'json'
7
+ require 'Instagram/User'
8
+ require 'Instagram/account'
9
+ require 'Instagram/feed'
10
+
11
+ module Instagram
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, '127.0.0.1', '8888')
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[:user].useragent,
52
+ :Accept => Instagram::CONSTANTS::HEADER[:accept],
53
+ :'Accept-Encoding' => Instagram::CONSTANTS::HEADER[:encoding],
54
+ :'Accept-Language' => args[:user].language,
55
+ :'X-IG-Capabilities' => Instagram::CONSTANTS::HEADER[:capabilities],
56
+ :'X-IG-Connection-Type' => Instagram::CONSTANTS::HEADER[:type],
57
+ :Cookie => (args[:user].session.nil? ? '' : args[: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, Instagram::API.generate_uuid)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ module Instagram
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