Class: IGScrape::Post
- Inherits:
-
Object
- Object
- IGScrape::Post
- Defined in:
- lib/ig_scrape/post.rb
Instance Attribute Summary collapse
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#code ⇒ Object
Returns the value of attribute code.
-
#comment_count ⇒ Object
Returns the value of attribute comment_count.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#display_src ⇒ Object
Returns the value of attribute display_src.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_video ⇒ Object
Returns the value of attribute is_video.
-
#likes ⇒ Object
Returns the value of attribute likes.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #has_more_comments? ⇒ Boolean
-
#initialize(payload) ⇒ Post
constructor
A new instance of Post.
- #load_comments ⇒ Object
Constructor Details
#initialize(payload) ⇒ Post
Returns a new instance of Post.
5 6 7 8 |
# File 'lib/ig_scrape/post.rb', line 5 def initialize payload @comments = [] load_from_payload(payload) end |
Instance Attribute Details
#caption ⇒ Object
Returns the value of attribute caption.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def caption @caption end |
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def code @code end |
#comment_count ⇒ Object
Returns the value of attribute comment_count.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def comment_count @comment_count end |
#comments ⇒ Object
Returns the value of attribute comments.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def comments @comments end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def created_at @created_at end |
#display_src ⇒ Object
Returns the value of attribute display_src.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def display_src @display_src end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def id @id end |
#is_video ⇒ Object
Returns the value of attribute is_video.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def is_video @is_video end |
#likes ⇒ Object
Returns the value of attribute likes.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def likes @likes end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/ig_scrape/post.rb', line 3 def type @type end |
Class Method Details
.edge_timeline_to_payload(node) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ig_scrape/post.rb', line 29 def self.edge_timeline_to_payload node { "id" => node["id"], "__typename" => node["__typename"], "is_video" => node["is_video"], "code" => node["shortcode"], "display_src" => node["display_url"], "caption" => (node["edge_media_to_caption"]["edges"].length > 0 ? node["edge_media_to_caption"]["edges"].first["node"]["text"] : ""), "date" => node["taken_at_timestamp"], "comments" => node["edge_media_to_comment"], "likes" => node["edge_media_preview_like"] } end |
.load_from_shortcode(code) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ig_scrape/post.rb', line 10 def self.load_from_shortcode code url = "https://www.instagram.com/p/#{code}/?__a=1" resp = HTTParty.get(url) response = JSON.parse(resp.body) payload = response["graphql"]["shortcode_media"] post = IGScrape::Post.new(self.edge_timeline_to_payload(payload)) end |
Instance Method Details
#has_more_comments? ⇒ Boolean
19 20 21 |
# File 'lib/ig_scrape/post.rb', line 19 def has_more_comments? @comments.length < @comment_count end |
#load_comments ⇒ Object
23 24 25 26 27 |
# File 'lib/ig_scrape/post.rb', line 23 def load_comments while has_more_comments? do load_more_comments end end |