Class: InstagramCrawler::Parser::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/instagram_crawler/parser/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_info, user_id) ⇒ Json

Returns a new instance of Json.



6
7
8
9
# File 'lib/instagram_crawler/parser/json.rb', line 6

def initialize(page_info, user_id)
  @page_info = page_info
  @user_id   = user_id
end

Instance Attribute Details

#page_infoObject (readonly)

Returns the value of attribute page_info.



4
5
6
# File 'lib/instagram_crawler/parser/json.rb', line 4

def page_info
  @page_info
end

#user_idObject (readonly)

Returns the value of attribute user_id.



4
5
6
# File 'lib/instagram_crawler/parser/json.rb', line 4

def user_id
  @user_id
end

Instance Method Details

#parsingObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/instagram_crawler/parser/json.rb', line 11

def parsing
  begin
    end_cursor = page_info["end_cursor"][0..-3]
    url        = next_url(end_cursor, user_id)
    html       = get_json(url)
    json       = JSON.parse(html)
    @page_info = json["data"]["user"]["edge_owner_to_timeline_media"]["page_info"]
    edges      = json["data"]["user"]["edge_owner_to_timeline_media"]["edges"]

    loop_edges(edges)
  end while page_info["has_next_page"]
end