instagram_upload 0.1.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: bfef720d84ff8046df5b16ccae2b07134ace4eee
4
+ data.tar.gz: 8486f9c0893599b602126b6b5fa597ed248e5a74
5
+ SHA512:
6
+ metadata.gz: 4cd2c4b0f36c3510a07431ede558aced57f4d47282f45c93b09250d2839c231761254f0af25bdae930e8c5316d88959e2757811434c5e05937353526da6ffdad
7
+ data.tar.gz: 8f9e7d46da66a48cd3a7aa142cf903ec212d7f8c6edf6f64fc6900b82eae7503bd0adc439b0f31585c25f9dad9db92c2263f1d90b3b23490f23cb5bfdedf0d09
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rubocop.yml ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in instagram_uploader.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 bezrukavyi
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,33 @@
1
+ # InstagramUpload
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'instagram_upload'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install instagram_upload
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ client = InstagramUpload::Client.new('login', 'password')
23
+ client.upload_photo('test.jpg', '#test_upload')
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/postwill/instagram_upload.
29
+
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'instagram_upload/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'instagram_upload'
8
+ spec.version = InstagramUpload::VERSION
9
+ spec.authors = ['bezrukavyi']
10
+ spec.email = ['yaroslav.bezrukavyi@gmail.com']
11
+
12
+ spec.summary = 'Instagram client'
13
+ spec.description = 'Instagram client'
14
+ spec.homepage = 'https://github.com/postwill/instagram_upload'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'curb', '~> 0.9.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.14'
25
+ spec.add_development_dependency 'pry', '~> 0.10.4'
26
+ spec.add_development_dependency 'rake', '~> 12.0'
27
+ spec.add_development_dependency 'rubocop', '~> 0.50.0'
28
+ end
@@ -0,0 +1,12 @@
1
+ require 'securerandom'
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'curb'
5
+ require 'tempfile'
6
+
7
+ require_relative 'instagram_upload/agent'
8
+ require_relative 'instagram_upload/request'
9
+ require_relative 'instagram_upload/client'
10
+
11
+ module InstagramUpload
12
+ end
@@ -0,0 +1,45 @@
1
+ module InstagramUpload
2
+ class Agent
3
+ SECRET_KEY = 'b4a23f5e39b5929e0666ac5de94c89d1618a2916'.freeze
4
+ CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8'
5
+ RESOLUTION = %w[720x1280 320x480 480x800 1024x768 1280x720 768x1024 480x320].freeze
6
+ VERSION = ['GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100'].freeze
7
+ DPI = %w[120 160 320 240].freeze
8
+
9
+ attr_reader :guid, :device_id, :user_agent
10
+
11
+ def initialize
12
+ @guid = SecureRandom.uuid
13
+ @device_id = 'android-' + guid
14
+ @user_agent = generate_user_agent
15
+ end
16
+
17
+ def body(data)
18
+ body_data = data.merge(
19
+ 'guid': guid,
20
+ 'device_id': device_id,
21
+ 'Content-Type': CONTENT_TYPE
22
+ ).to_json.tr("'", '"')
23
+
24
+ 'ig_sig_key_version=4&signed_body=' + signature(body_data) + '.' + URI.encode(body_data, /\W/)
25
+ end
26
+
27
+ private
28
+
29
+ def signature(data)
30
+ OpenSSL::HMAC.hexdigest('sha256', SECRET_KEY, data)
31
+ end
32
+
33
+ def generate_user_agent
34
+ resolution = RESOLUTION.sample
35
+ version = VERSION.sample
36
+ dpi = DPI.sample
37
+
38
+ instagram_version = '4.' + rand(1..2).to_s + '.' + rand(0..2).to_s
39
+ android_version = rand(10..11).to_s + '/' + [rand(1...3), rand(3..5), rand(0..5)].join('.')
40
+ android_config = [android_version, dpi, resolution, 'samsung', version, version, 'smdkc210', 'ru_RU'].join('; ')
41
+
42
+ "Instagram #{instagram_version} Android (#{android_config})"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ module InstagramUpload
2
+ class Client
3
+ API_URL = 'https://instagram.com/api/v1/'.freeze
4
+
5
+ LOGIN = API_URL + 'accounts/login/'
6
+ UPLOAD_PHOTO = API_URL + 'media/upload/'
7
+ CONFIGURE_PHOTO = API_URL + 'media/configure/'
8
+
9
+ attr_reader :username, :password, :agent, :request
10
+
11
+ def initialize(username, password)
12
+ @username = username
13
+ @password = password
14
+ @agent = Agent.new
15
+ @request = Request.new(agent)
16
+
17
+ login
18
+ end
19
+
20
+ def upload_photo(image, caption)
21
+ data = [
22
+ Curl::PostField.file('photo', image),
23
+ Curl::PostField.content('device_timestamp', device_timestamp)
24
+ ]
25
+
26
+ result = request.post(UPLOAD_PHOTO, data) do |http|
27
+ http.multipart_form_post = true
28
+ http.cookiefile = request.cookies.path
29
+ end
30
+
31
+ configure_photo(result['media_id'], caption)
32
+ end
33
+
34
+ def configure_photo(media_id, caption)
35
+ body = agent.body(
36
+ device_timestamp: device_timestamp,
37
+ media_id: media_id,
38
+ caption: caption,
39
+ source_type: 5,
40
+ filter_type: 0,
41
+ extra: {}
42
+ )
43
+
44
+ request.post(CONFIGURE_PHOTO, body) do |http|
45
+ http.cookiefile = request.cookies.path
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def login
52
+ body = agent.body(username: username, password: password)
53
+
54
+ request.post(LOGIN, body) do |http|
55
+ http.cookiejar = request.cookies.path
56
+ end
57
+ end
58
+
59
+ def device_timestamp
60
+ Time.now.to_i.to_s
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,24 @@
1
+ module InstagramUpload
2
+ class Request
3
+ attr_reader :agent, :cookies
4
+
5
+ def initialize(agent)
6
+ @agent = agent
7
+ @cookies = Tempfile.new('cookies')
8
+ end
9
+
10
+ def post(url, body)
11
+ http = Curl::Easy.new(url)
12
+ http.headers['User-Agent'] = agent.user_agent
13
+ http.verbose = true
14
+ http.follow_location = true
15
+ http.enable_cookies = true
16
+
17
+ yield(http) if block_given?
18
+
19
+ http.post(body)
20
+
21
+ JSON.parse(http.body).tap { http.close }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module InstagramUpload
2
+ VERSION = '0.1.2'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instagram_upload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - bezrukavyi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.50.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.50.0
83
+ description: Instagram client
84
+ email:
85
+ - yaroslav.bezrukavyi@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - instagram_upload.gemspec
97
+ - lib/instagram_upload.rb
98
+ - lib/instagram_upload/agent.rb
99
+ - lib/instagram_upload/client.rb
100
+ - lib/instagram_upload/request.rb
101
+ - lib/instagram_upload/version.rb
102
+ homepage: https://github.com/postwill/instagram_upload
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Instagram client
126
+ test_files: []