Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/ruby-instagram-scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module RubyInstagramScraper

def self.search ( query )
# return false unless query

url = "#{BASE_URL}/web/search/topsearch/"
params = "?query=#{ query }"

Expand Down Expand Up @@ -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 )
Expand All @@ -46,13 +49,13 @@ 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},\
is_private,external_url,is_verified}},page_info}}"

JSON.parse( open( url ).read )["comments"]
end
end

end
8 changes: 4 additions & 4 deletions test/ruby_instagram_scraper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,4 +39,4 @@
end
end

end
end