rugram 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c6a973bd9e28193b5bd5222986e64db28495b84311f59b49d1ef167efa6534
4
- data.tar.gz: 8ee6ff83f4dba6fdaa9bb25e1c1729ed7172b786c45cb460d1aa059118db260c
3
+ metadata.gz: bb3fa920442957abeee48e09aa41eddd3e25b9d9cdeeb82c3a5c186e6f2a1c58
4
+ data.tar.gz: 8a8f4cc34c204c51e9866b500c08ea9094dbafd963d4d51782435be68a8a6047
5
5
  SHA512:
6
- metadata.gz: 03feb7cf47dcdda9775759461d4d78c06f4f036103bb0baf796b7ca3c37b6060d634b947ca315dbefbf4d8db2a89b1b0e48d43d44590549e97d1edb156580172
7
- data.tar.gz: dde5a295899a3eefc3ddb307ecb3567f23caa5d5d8c858868e2ad35a84cd11b272f592cf401c846521dff2341484aaf775c378805c33e1d4ecc678b75a99164d
6
+ metadata.gz: 12ea0e2745e9212ea6bb29fc4f8acca9ba4c9a07f45ed15f0f65756138a0a071666224a0b6041347890f28cd4eaf5c254cf3f3f59698596a569ba9bd1eeaa3bb
7
+ data.tar.gz: 3df81b508afc61a71bfee97074c5159fa97ee16457c71412e47f23ff16f7ba37de729a8fadec3c06ca105d58524cb89ba7b916af44478d158709fee75b2eb9ea
@@ -0,0 +1,9 @@
1
+ require 'rugram/instagram'
2
+ require 'rugram/post'
3
+ require 'rugram/profile'
4
+ require 'rugram/stories'
5
+ require 'rugram/story'
6
+ require 'user_not_found_error'
7
+
8
+ module Rugram
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'rugram'
2
+ require 'httparty'
3
+ require 'nokogiri'
4
+ require 'json'
5
+ require 'user_not_found_error'
6
+ require 'byebug'
7
+
8
+ module Rugram
9
+ class Instagram
10
+ attr_reader :profile
11
+ def initialize(username)
12
+ @username = username
13
+ build_profile
14
+ end
15
+
16
+ def url
17
+ "https://instagram.com/#{@username}"
18
+ end
19
+
20
+ private
21
+
22
+ def request_profile_info
23
+ begin
24
+ request = HTTParty.get(url)
25
+ parsed_html = Nokogiri::HTML(request).xpath('/html/body/script[1]').text
26
+ json_data = JSON.parse(parsed_html[21, parsed_html.size-22])
27
+ @profile_information = json_data['entry_data']['ProfilePage'][0]['graphql']['user']
28
+ rescue
29
+ raise UserNotFoundError.new(@username)
30
+ end
31
+ end
32
+
33
+ def build_profile
34
+ request_profile_info
35
+ id = @profile_information['id']
36
+ name = @profile_information['full_name']
37
+ username = @profile_information['username']
38
+ profile_pic_url = @profile_information['profile_pic_url']
39
+ private_user = @profile_information['private_user']
40
+ @profile = Rugram::Profile.new(id, name, username, profile_pic_url, private_user)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ require 'rugram'
2
+ require 'httparty'
3
+ require 'nokogiri'
4
+ require 'json'
5
+ require 'byebug'
6
+
7
+ module Rugram
8
+ class Post
9
+ attr_reader :id, :profile, :caption, :taken_at, :display_url, :thumbnails
10
+ def initialize(id, profile, caption, taken_at, display_url, thumbnails)
11
+ @id = id
12
+ @profile = profile
13
+ @caption = caption
14
+ @taken_at = taken_at
15
+ @display_url = display_url
16
+ @thumbnails = thumbnails
17
+ end
18
+
19
+ def self.get_image(id)
20
+ @id = id
21
+ request = HTTParty.get(post_url)
22
+ parsed_html = Nokogiri::HTML(request).xpath("/html/body/script[1]").text
23
+ json_data = JSON.parse(parsed_html[21, parsed_html.size-22])
24
+ @post = json_data['entry_data']['PostPage'][0]['graphql']['shortcode_media']
25
+ fill_data
26
+ end
27
+
28
+ def post_url
29
+ "https://www.instagram.com/p/#{@id}"
30
+ end
31
+
32
+ def self.post_url
33
+ "https://www.instagram.com/p/#{@id}"
34
+ end
35
+
36
+ private
37
+ def self.fill_data
38
+ profile = create_profile
39
+ caption = @post['edge_media_to_caption']['edges'][0]['node']['text']
40
+ taken_at = @post['taken_at_timestamp']
41
+ Rugram::Post.new(@id, profile, caption, taken_at, display_url, thumbnails)
42
+ end
43
+
44
+ def self.create_profile
45
+ owner = @post['owner']
46
+ id = owner['id']
47
+ name = owner['full_name']
48
+ username = owner['username']
49
+ profile_pic_url = owner['profile_pic_url']
50
+ private_user = owner['private_user']
51
+ Rugram::Profile.new(id, name, username, profile_pic_url, private_user)
52
+ end
53
+
54
+ def self.display_url
55
+ @post['is_video'] ? @post['video_url'] : @post['display_url']
56
+ end
57
+
58
+ def self.thumbnails
59
+ urls = []
60
+ @post['display_resources'].each do |resource|
61
+ urls << resource['src']
62
+ end
63
+ urls
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ module Rugram
2
+ class Profile
3
+ attr_reader :id, :name, :username, :profile_pic_url
4
+ def initialize(id, name, username, profile_pic_url, private_user)
5
+ @id = id
6
+ @name = name
7
+ @username = username
8
+ @profile_pic_url = profile_pic_url
9
+ @private_user = private_user
10
+ end
11
+
12
+ def is_private?
13
+ @private_user
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,69 @@
1
+ require 'httparty'
2
+ require 'byebug'
3
+ require 'rugram'
4
+
5
+ module Rugram
6
+ class Stories
7
+ def initialize(id, cookie)
8
+ @id = id
9
+ @cookie = cookie
10
+ end
11
+
12
+ def last_stories
13
+ request_stories
14
+ end
15
+
16
+ def highlight(id)
17
+ request_stories(id)
18
+ end
19
+
20
+ private
21
+
22
+ def request_stories(highlight = nil)
23
+ @query = {
24
+ query_hash: '45246d3fe16ccc6577e0bd297a5db1ab',
25
+ variables: {
26
+ reel_ids:[@id],
27
+ tag_names:[],
28
+ location_ids:[],
29
+ highlight_reel_ids:[],
30
+ precomposed_overlay:false
31
+ }.to_json
32
+ }
33
+
34
+ @headers = {
35
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0',
36
+ 'Cookie' => @cookie,
37
+ 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
38
+ }
39
+ #@query[:variables][:highlight_reel_ids] << highlight
40
+
41
+ url = 'https://www.instagram.com/graphql/query'
42
+ request = HTTParty.get(
43
+ url,
44
+ query: @query,
45
+ headers: @headers
46
+ )
47
+
48
+ @parsed_stories = JSON.parse(request.body)
49
+ build_stories
50
+ end
51
+
52
+ def build_stories
53
+ story_items = @parsed_stories['data']['reels_media'][0]['items']
54
+ stories = Array.new
55
+ if story_items
56
+ story_items.each do |story|
57
+ id = story['id']
58
+ taken_at = story['taken_at']
59
+ stories << Rugram::Story.new(id, taken_at, display_url(story))
60
+ end
61
+ end
62
+ stories
63
+ end
64
+
65
+ def display_url(story)
66
+ story['is_video'] ? story['video_resources'].last()['src'] : story['display_url']
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ module Rugram
2
+ class Story
3
+ def initialize(id, taken_at, display_url)
4
+ @id = id
5
+ @taken_at = taken_at
6
+ @display_url = display_url
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,8 @@
1
- class UserNotFoundError < StandardError
2
- def initialize(user)
3
- msg = "Instagram User Not Found: #{user}"
4
- super(msg)
1
+ module Rugram
2
+ class UserNotFoundError < StandardError
3
+ def initialize(user)
4
+ msg = "Instagram User Not Found: #{user}"
5
+ super(msg)
6
+ end
5
7
  end
6
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Tripoloni
@@ -17,11 +17,12 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - Gemfile
20
- - lib/instagram.rb
21
- - lib/post.rb
22
- - lib/profile.rb
23
- - lib/stories.rb
24
- - lib/story.rb
20
+ - lib/rugram.rb
21
+ - lib/rugram/instagram.rb
22
+ - lib/rugram/post.rb
23
+ - lib/rugram/profile.rb
24
+ - lib/rugram/stories.rb
25
+ - lib/rugram/story.rb
25
26
  - lib/user_not_found_error.rb
26
27
  homepage:
27
28
  licenses: []
@@ -1,41 +0,0 @@
1
- require 'httparty'
2
- require 'nokogiri'
3
- require 'json'
4
- require 'profile'
5
- require 'user_not_found_error'
6
- require 'byebug'
7
-
8
- class Instagram
9
- attr_reader :profile
10
- def initialize(username)
11
- @username = username
12
- build_profile
13
- end
14
-
15
- def url
16
- "https://instagram.com/#{@username}"
17
- end
18
-
19
- private
20
-
21
- def request_profile_info
22
- begin
23
- request = HTTParty.get(url)
24
- parsed_html = Nokogiri::HTML(request).xpath('/html/body/script[1]').text
25
- json_data = JSON.parse(parsed_html[21, parsed_html.size-22])
26
- @profile_information = json_data['entry_data']['ProfilePage'][0]['graphql']['user']
27
- rescue
28
- raise UserNotFoundError.new(@username)
29
- end
30
- end
31
-
32
- def build_profile
33
- request_profile_info
34
- id = @profile_information['id']
35
- name = @profile_information['full_name']
36
- username = @profile_information['username']
37
- profile_pic_url = @profile_information['profile_pic_url']
38
- private_user = @profile_information['private_user']
39
- @profile = Profile.new(id, name, username, profile_pic_url, private_user)
40
- end
41
- end
@@ -1,63 +0,0 @@
1
- require 'httparty'
2
- require 'nokogiri'
3
- require 'json'
4
- require 'byebug'
5
-
6
- class Post
7
- attr_reader :id, :profile, :caption, :taken_at, :display_url, :thumbnails
8
- def initialize(id, profile, caption, taken_at, display_url, thumbnails)
9
- @id = id
10
- @profile = profile
11
- @caption = caption
12
- @taken_at = taken_at
13
- @display_url = display_url
14
- @thumbnails = thumbnails
15
- end
16
-
17
- def self.get_image(id)
18
- @id = id
19
- request = HTTParty.get(post_url)
20
- parsed_html = Nokogiri::HTML(request).xpath("/html/body/script[1]").text
21
- json_data = JSON.parse(parsed_html[21, parsed_html.size-22])
22
- @post = json_data['entry_data']['PostPage'][0]['graphql']['shortcode_media']
23
- fill_data
24
- end
25
-
26
- def post_url
27
- "https://www.instagram.com/p/#{@id}"
28
- end
29
-
30
- def self.post_url
31
- "https://www.instagram.com/p/#{@id}"
32
- end
33
-
34
- private
35
- def self.fill_data
36
- profile = create_profile
37
- caption = @post['edge_media_to_caption']['edges'][0]['node']['text']
38
- taken_at = @post['taken_at_timestamp']
39
- Post.new(@id, profile, caption, taken_at, display_url, thumbnails)
40
- end
41
-
42
- def self.create_profile
43
- owner = @post['owner']
44
- id = owner['id']
45
- name = owner['full_name']
46
- username = owner['username']
47
- profile_pic_url = owner['profile_pic_url']
48
- private_user = owner['private_user']
49
- Profile.new(id, name, username, profile_pic_url, private_user)
50
- end
51
-
52
- def self.display_url
53
- @post['is_video'] ? @post['video_url'] : @post['display_url']
54
- end
55
-
56
- def self.thumbnails
57
- urls = []
58
- @post['display_resources'].each do |resource|
59
- urls << resource['src']
60
- end
61
- urls
62
- end
63
- end
@@ -1,14 +0,0 @@
1
- class Profile
2
- attr_reader :id, :name, :username, :profile_pic_url
3
- def initialize(id, name, username, profile_pic_url, private_user)
4
- @id = id
5
- @name = name
6
- @username = username
7
- @profile_pic_url = profile_pic_url
8
- @private_user = private_user
9
- end
10
-
11
- def is_private?
12
- @private_user
13
- end
14
- end
@@ -1,66 +0,0 @@
1
- require 'httparty'
2
- require 'byebug'
3
- require 'story'
4
-
5
- class Stories
6
- def initialize(id, cookie)
7
- @id = id
8
- @cookie = cookie
9
- end
10
-
11
- def last_stories
12
- request_stories
13
- end
14
-
15
- def highlight(id)
16
- request_stories(id)
17
- end
18
-
19
- private
20
-
21
- def request_stories(highlight = nil)
22
- @query = {
23
- query_hash: '45246d3fe16ccc6577e0bd297a5db1ab',
24
- variables: {
25
- reel_ids:[@id],
26
- tag_names:[],
27
- location_ids:[],
28
- highlight_reel_ids:[],
29
- precomposed_overlay:false
30
- }.to_json
31
- }
32
-
33
- @headers = {
34
- 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0',
35
- 'Cookie' => @cookie,
36
- 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
37
- }
38
- #@query[:variables][:highlight_reel_ids] << highlight
39
-
40
- url = 'https://www.instagram.com/graphql/query'
41
- request = HTTParty.get(
42
- url,
43
- query: @query,
44
- headers: @headers
45
- )
46
-
47
- @parsed_stories = JSON.parse(request.body)
48
- build_stories
49
- end
50
-
51
- def build_stories
52
- story_items = @parsed_stories['data']['reels_media'][0]['items']
53
- stories = Array.new
54
- if story_items
55
- story_items.each do |story|
56
- id = story['id']
57
- taken_at = story['taken_at']
58
- stories << Story.new(id, taken_at, display_url(story))
59
- end
60
- end
61
- end
62
-
63
- def display_url(story)
64
- story['is_video'] ? story['video_resources'].last()['src'] : story['display_url']
65
- end
66
- end
@@ -1,7 +0,0 @@
1
- class Story
2
- def initialize(id, taken_at, display_url)
3
- @id = id
4
- @taken_at = taken_at
5
- @display_url = display_url
6
- end
7
- end