instagram_uploader 0.1.1.3 → 0.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instagram_uploader.rb +1 -3
- data/lib/instagram_uploader/login.rb +31 -0
- data/lib/instagram_uploader/photo_commit.rb +71 -0
- data/lib/instagram_uploader/photo_uploader.rb +39 -0
- data/lib/instagram_uploader/uploader.rb +12 -97
- data/lib/instagram_uploader/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbe2a280a2e13daa77f63c5fbd93b6a937b366ea
|
4
|
+
data.tar.gz: 5abc54fc8d2dcb88b64146f8bd6a746e12a47558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73e3cb66dae3dab59cc1f19ca63a0b44854b5489935e4e08696512af51fb7e4f06d2dca75601214a52b86533968636a006a9387bb14d20dde7ba6579306bf16
|
7
|
+
data.tar.gz: aa6502dcc15599854200365d9d772e832027d5f4c77c61b62e2e1fd5f80c6c4a0ec43c153bc1b287d1099650c2a7e63d3665548fd0f1276866edc020be1e9b78
|
data/lib/instagram_uploader.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module InstagramUploader
|
2
|
+
module Login
|
3
|
+
def login
|
4
|
+
url = 'https://instagram.com/api/v1/accounts/login/'
|
5
|
+
|
6
|
+
data = "{'username':'#{@username}','password':'#{@password}','guid':'#{generate_guid}','device_id':'#{generate_device_id}','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}".gsub("'", '"')
|
7
|
+
signature = generate_signature(data)
|
8
|
+
body = 'ig_sig_key_version=4&signed_body=' + signature + '.' + URI::encode(data, /\W/)
|
9
|
+
|
10
|
+
response = login_request(url, body)
|
11
|
+
raise Error, response['message'] if response['status'] != 'ok'
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def login_request(url,data)
|
17
|
+
http = Curl::Easy.new(url)
|
18
|
+
http.headers["User-Agent"] = generate_user_agent
|
19
|
+
http.verbose = true
|
20
|
+
http.follow_location = true
|
21
|
+
http.enable_cookies = true
|
22
|
+
http.cookiejar = @cookie
|
23
|
+
http.send('post', data)
|
24
|
+
response = JSON.parse(http.body)
|
25
|
+
http.close
|
26
|
+
response
|
27
|
+
end
|
28
|
+
class Error < RuntimeError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module InstagramUploader
|
2
|
+
module PhotoCommit
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
def commit_photo(media_id, desc)
|
6
|
+
url = 'https://instagram.com/api/v1/media/configure/'
|
7
|
+
|
8
|
+
device_timestamp = Time.now.to_i.to_s
|
9
|
+
data = "{'guid':'#{@guid}','device_id':'#{@device_id}','device_timestamp':'#{device_timestamp}','media_id':'#{media_id}','caption': '#{desc}','source_type':'5','filter_type':'0','extra':'{}','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}".gsub("'", '"')
|
10
|
+
signature = generate_signature(data)
|
11
|
+
body = 'ig_sig_key_version=4&signed_body=' + signature + '.' + URI::encode(data, /\W/)
|
12
|
+
|
13
|
+
response = commit_request(url, body)
|
14
|
+
if response['status'] != 'ok'
|
15
|
+
raise Error, response['message']
|
16
|
+
else
|
17
|
+
response
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def commit_request(url, data)
|
24
|
+
http = Curl::Easy.new(url)
|
25
|
+
|
26
|
+
http.headers["User-Agent"] = generate_user_agent
|
27
|
+
http.verbose = true
|
28
|
+
http.follow_location = true
|
29
|
+
http.enable_cookies = true
|
30
|
+
|
31
|
+
http.cookiefile = @cookie
|
32
|
+
|
33
|
+
http.send('post', data)
|
34
|
+
response = JSON.parse(http.body)
|
35
|
+
http.close
|
36
|
+
|
37
|
+
response
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_guid
|
41
|
+
guid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
42
|
+
rand(0..65535),
|
43
|
+
rand(0..65535),
|
44
|
+
rand(0..65535),
|
45
|
+
rand(16384..20479),
|
46
|
+
rand(32768..49151),
|
47
|
+
rand(0..65535),
|
48
|
+
rand(0..65535),
|
49
|
+
rand(0..65535))
|
50
|
+
end
|
51
|
+
|
52
|
+
def generate_device_id
|
53
|
+
guid = generate_guid
|
54
|
+
"android-#{guid}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_signature(data)
|
58
|
+
return OpenSSL::HMAC.hexdigest('sha256', 'b4a23f5e39b5929e0666ac5de94c89d1618a2916', data)
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_user_agent
|
62
|
+
resolution = ['720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320'].sample
|
63
|
+
version = ['GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100'].sample
|
64
|
+
dpi = ['120', '160', '320', '240'].sample
|
65
|
+
|
66
|
+
'Instagram 4.' + rand(1..2).to_s + '.' + rand(0..2).to_s + ' Android (' + rand(10..11).to_s + '/' + rand(1..3).to_s + '.' + rand(3..5).to_s + '.' + rand(0..5).to_s + "; #{dpi}; #{resolution}; samsung; #{version }; #{version}; smdkc210; ru_RU)"
|
67
|
+
end
|
68
|
+
class Error < RuntimeError
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module InstagramUploader
|
2
|
+
module PhotoUploader
|
3
|
+
|
4
|
+
def upload_photo(image)
|
5
|
+
url = 'https://instagram.com/api/v1/media/upload/'
|
6
|
+
device_timestamp = Time.now.to_i.to_s
|
7
|
+
|
8
|
+
data = [
|
9
|
+
Curl::PostField.file('photo', image),
|
10
|
+
Curl::PostField.content('device_timestamp', device_timestamp)
|
11
|
+
]
|
12
|
+
response = upload_request(url, data)
|
13
|
+
|
14
|
+
response['status'] != 'ok' ? (raise Error, response['message']) : response
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def upload_request(url, data)
|
20
|
+
http = Curl::Easy.new(url)
|
21
|
+
|
22
|
+
http.headers["User-Agent"] = generate_user_agent
|
23
|
+
http.multipart_form_post = true
|
24
|
+
http.verbose = true
|
25
|
+
http.follow_location = true
|
26
|
+
http.enable_cookies = true
|
27
|
+
|
28
|
+
http.cookiefile = @cookie
|
29
|
+
|
30
|
+
http.send('post', data)
|
31
|
+
response = JSON.parse(http.body)
|
32
|
+
http.close
|
33
|
+
|
34
|
+
response
|
35
|
+
end
|
36
|
+
class Error < RuntimeError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,5 +1,17 @@
|
|
1
|
+
require "instagram_uploader/login"
|
2
|
+
require "instagram_uploader/photo_uploader"
|
3
|
+
require "instagram_uploader/photo_commit"
|
4
|
+
|
5
|
+
require "curb"
|
6
|
+
require "tempfile"
|
7
|
+
|
1
8
|
module InstagramUploader
|
2
9
|
class Uploader
|
10
|
+
include Login
|
11
|
+
include PhotoUploader
|
12
|
+
include PhotoCommit
|
13
|
+
|
14
|
+
|
3
15
|
def initialize(username, password)
|
4
16
|
@username = username
|
5
17
|
@password = password
|
@@ -13,103 +25,6 @@ module InstagramUploader
|
|
13
25
|
end
|
14
26
|
|
15
27
|
private
|
16
|
-
|
17
|
-
def login
|
18
|
-
url = 'https://instagram.com/api/v1/accounts/login/'
|
19
|
-
|
20
|
-
data = "{'username':'#{@username}','password':'#{@password}','guid':'#{generate_guid}','device_id':'#{generate_device_id}','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}".gsub("'", '"')
|
21
|
-
signature = generate_signature(data)
|
22
|
-
body = 'ig_sig_key_version=4&signed_body=' + signature + '.' + URI::encode(data, /\W/)
|
23
|
-
|
24
|
-
response = request(url, body, false, false)
|
25
|
-
raise Error, response['message'] if response['status'] != 'ok'
|
26
|
-
end
|
27
|
-
|
28
|
-
def upload_photo(image)
|
29
|
-
url = 'https://instagram.com/api/v1/media/upload/'
|
30
|
-
device_timestamp = Time.now.to_i.to_s
|
31
|
-
|
32
|
-
data = [
|
33
|
-
Curl::PostField.file('photo', image),
|
34
|
-
Curl::PostField.content('device_timestamp', device_timestamp)
|
35
|
-
]
|
36
|
-
|
37
|
-
response = request(url, data, true, true)
|
38
|
-
|
39
|
-
if response['status'] != 'ok'
|
40
|
-
raise Error, response['message']
|
41
|
-
else
|
42
|
-
response
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def commit_photo(media_id, desc)
|
47
|
-
url = 'https://instagram.com/api/v1/media/configure/'
|
48
|
-
|
49
|
-
device_timestamp = Time.now.to_i.to_s
|
50
|
-
data = "{'guid':'#{@guid}','device_id':'#{@device_id}','device_timestamp':'#{device_timestamp}','media_id':'#{media_id}','caption': '#{desc}','source_type':'5','filter_type':'0','extra':'{}','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}".gsub("'", '"')
|
51
|
-
signature = generate_signature(data)
|
52
|
-
body = 'ig_sig_key_version=4&signed_body=' + signature + '.' + URI::encode(data, /\W/)
|
53
|
-
|
54
|
-
response = request(url, body, false, true)
|
55
|
-
if response['status'] != 'ok'
|
56
|
-
raise Error, response['message']
|
57
|
-
else
|
58
|
-
response
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def request(url, data, is_upload, cookies)
|
63
|
-
http = Curl::Easy.new(url)
|
64
|
-
|
65
|
-
http.headers["User-Agent"] = generate_user_agent
|
66
|
-
http.multipart_form_post = is_upload
|
67
|
-
http.verbose = true
|
68
|
-
http.follow_location = true
|
69
|
-
http.enable_cookies = true
|
70
|
-
|
71
|
-
if cookies
|
72
|
-
http.cookiefile = @cookie
|
73
|
-
else
|
74
|
-
http.cookiejar = @cookie
|
75
|
-
end
|
76
|
-
|
77
|
-
http.send('post', data)
|
78
|
-
response = JSON.parse(http.body)
|
79
|
-
http.close
|
80
|
-
|
81
|
-
response
|
82
|
-
end
|
83
|
-
|
84
|
-
def generate_guid
|
85
|
-
guid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
86
|
-
rand(0..65535),
|
87
|
-
rand(0..65535),
|
88
|
-
rand(0..65535),
|
89
|
-
rand(16384..20479),
|
90
|
-
rand(32768..49151),
|
91
|
-
rand(0..65535),
|
92
|
-
rand(0..65535),
|
93
|
-
rand(0..65535))
|
94
|
-
end
|
95
|
-
|
96
|
-
def generate_device_id
|
97
|
-
guid = generate_guid
|
98
|
-
"android-#{guid}"
|
99
|
-
end
|
100
|
-
|
101
|
-
def generate_signature(data)
|
102
|
-
return OpenSSL::HMAC.hexdigest('sha256', 'b4a23f5e39b5929e0666ac5de94c89d1618a2916', data)
|
103
|
-
end
|
104
|
-
|
105
|
-
def generate_user_agent
|
106
|
-
resolution = ['720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320'].sample
|
107
|
-
version = ['GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100'].sample
|
108
|
-
dpi = ['120', '160', '320', '240'].sample
|
109
|
-
|
110
|
-
'Instagram 4.' + rand(1..2).to_s + '.' + rand(0..2).to_s + ' Android (' + rand(10..11).to_s + '/' + rand(1..3).to_s + '.' + rand(3..5).to_s + '.' + rand(0..5).to_s + "; #{dpi}; #{resolution}; samsung; #{version }; #{version}; smdkc210; ru_RU)"
|
111
|
-
end
|
112
|
-
|
113
28
|
class Error < RuntimeError
|
114
29
|
end
|
115
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagram_uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
4
|
+
version: 0.1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- q3pp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,9 @@ files:
|
|
68
68
|
- bin/setup
|
69
69
|
- instagram_uploader.gemspec
|
70
70
|
- lib/instagram_uploader.rb
|
71
|
+
- lib/instagram_uploader/login.rb
|
72
|
+
- lib/instagram_uploader/photo_commit.rb
|
73
|
+
- lib/instagram_uploader/photo_uploader.rb
|
71
74
|
- lib/instagram_uploader/uploader.rb
|
72
75
|
- lib/instagram_uploader/version.rb
|
73
76
|
homepage: https://github.com/q3pp/instagram_uploader
|