class Redd::Models::Comment
A comment.
Public Class Methods
from_id(client, id)
click to toggle source
Create a Comment
from its fullname. @param client [APIClient] the api client to initialize the object with @param id [String] the fullname @return [Comment]
# File lib/redd/models/comment.rb, line 28 def self.from_id(client, id) new(client, name: id) end
Private Instance Methods
after_initialize()
click to toggle source
# File lib/redd/models/comment.rb, line 34 def after_initialize @attributes[:replies] = if @attributes[:replies].is_a?(Hash) @client.unmarshal(@attributes[:replies]) else Models::Listing.new(@client, children: [], after: nil, before: nil) end @attributes[:author] = User.from_id(@client, @attributes.fetch(:author)) @attributes[:subreddit] = Subreddit.from_id(@client, @attributes.fetch(:subreddit)) end
default_loader()
click to toggle source
# File lib/redd/models/comment.rb, line 45 def default_loader @attributes.key?(:link_id) ? load_with_comments : load_without_comments end
load_with_comments()
click to toggle source
# File lib/redd/models/comment.rb, line 49 def load_with_comments id = @attributes.fetch(:id) { @attributes.fetch(:name).sub('t1_', '') } link_id = @attributes[:link_id].sub('t3_', '') @client.get("/comments/#{link_id}/_/#{id}").body[1][:data][:children][0][:data] end
load_without_comments()
click to toggle source
# File lib/redd/models/comment.rb, line 55 def load_without_comments id = @attributes.fetch(:id) { @attributes.fetch(:name).sub('t1_', '') } @client.get('/api/info', id: "t1_#{id}").body[:data][:children][0][:data] end