From acc6f1f97cff420aaf43a920c440fd3168fd45da Mon Sep 17 00:00:00 2001 From: Adam Haris Date: Tue, 18 Oct 2016 08:44:09 +0900 Subject: [PATCH] add page ids to get_tag_media_nodes --- lib/ruby-instagram-scraper.rb | 13 ++++++++----- test/ruby_instagram_scraper_test.rb | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ruby-instagram-scraper.rb b/lib/ruby-instagram-scraper.rb index 404a2af..44d233c 100644 --- a/lib/ruby-instagram-scraper.rb +++ b/lib/ruby-instagram-scraper.rb @@ -7,7 +7,7 @@ module RubyInstagramScraper def self.search ( query ) # return false unless query - + url = "#{BASE_URL}/web/search/topsearch/" params = "?query=#{ query }" @@ -35,7 +35,10 @@ def self.get_tag_media_nodes ( tag, max_id = nil ) params = "" params = "&max_id=#{ max_id }" if max_id - JSON.parse( open( "#{url}#{params}" ).read )["tag"]["media"]["nodes"] + nodes = JSON.parse( open( "#{url}#{params}" ).read )["tag"]["media"]["nodes"] + page = JSON.parse( open( "#{url}#{params}" ).read )["tag"]["media"]["page_info"] + + { nodes: nodes, page: page } end def self.get_media ( code ) @@ -46,7 +49,7 @@ def self.get_media ( code ) end def self.get_media_comments ( shortcode, count = 40, before = nil ) - params = before.nil?? "comments.last(#{ count })" : "comments.before( #{ before } , #{count})" + params = before.nil?? "comments.last(#{ count })" : "comments.before( #{ before } , #{count})" url = "#{BASE_URL}/query/?q=ig_shortcode(#{ shortcode }){#{ params }\ {count,nodes{id,created_at,text,user{id,profile_pic_url,username,\ follows{count},followed_by{count},biography,full_name,media{count},\ @@ -54,5 +57,5 @@ def self.get_media_comments ( shortcode, count = 40, before = nil ) JSON.parse( open( url ).read )["comments"] end - -end \ No newline at end of file + +end diff --git a/test/ruby_instagram_scraper_test.rb b/test/ruby_instagram_scraper_test.rb index 73e4d60..990274a 100644 --- a/test/ruby_instagram_scraper_test.rb +++ b/test/ruby_instagram_scraper_test.rb @@ -14,13 +14,13 @@ RubyInstagramScraper.get_user_media_nodes( "borodanov" ).must_be_instance_of Array end end - + describe "when request tag media nodes" do it "must be an array" do - RubyInstagramScraper.get_tag_media_nodes( "academgorodok" ).must_be_instance_of Array + RubyInstagramScraper.get_tag_media_nodes( "academgorodok" ).must_be_instance_of Hash end end - + describe "when request a media" do it "must has equal code in field" do RubyInstagramScraper.get_media( "vKQeMNu7H1" )["code"].must_equal "vKQeMNu7H1" @@ -39,4 +39,4 @@ end end -end \ No newline at end of file +end