Sha256: 4eeeb300048089eebd83773d0c0e4713ccaee2b5a604b9d515d9a9c0b19847e3

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

module Redd
  module Client
    class Unauthenticated
      module LinksComments
        # @note Reddit does accept a subreddit, but with fullnames and urls, I
        #   assumed that was unnecessary.
        def get_info(params = {})
          object_from_response :get, "/api/info.json"
        end

        def get_comments(submission)
          id = extract_id(submission)
          comments_from_response :get, "/comments/#{id}.json"
        end

        def get_replies(comment)
          replies = comment.attributes[:replies]
          return [] unless replies.is_a?(Hash) and replies.has_key?(:kind)
          object_from_body(replies)
        end

        # FIX THIS ASAP
        def replace_morecomments(morecomments)
          parent_id = morecomments.parent_id
          link_id = 
            if parent_id.start_with?("t1_")
              get_info(id: parent_id).first.link_id
            elsif parent_id.start_with?("t3_")
              parent_id
            end

          meth = :post
          path = "/api/morechildren"
          params = {
            api_type: "json", link_id: link_id,
            children: morecomments.children.join(",")
          }

          send(meth, path, params)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redd-0.1.5 lib/redd/client/unauthenticated/links_comments.rb
redd-0.1.4 lib/redd/client/unauthenticated/links_comments.rb
redd-0.1.3 lib/redd/client/unauthenticated/links_comments.rb
redd-0.1.2 lib/redd/client/unauthenticated/links_comments.rb