From 93d83d300890e50260bef10852c81b0a03992666 Mon Sep 17 00:00:00 2001 From: james cook Date: Sun, 10 Oct 2010 01:20:24 -0400 Subject: [PATCH] Parse comment replies into their own Comment objects. Fix failing tests. --- README | 2 +- VERSION | 2 +- doc/Reddit.html | 2 +- doc/Reddit/Api.html | 2 +- doc/Reddit/Base.html | 2 +- doc/Reddit/Comment.html | 360 ++++++++++++++---- doc/Reddit/JsonListing.html | 2 +- doc/Reddit/JsonListing/ClassMethods.html | 2 +- doc/Reddit/JsonListing/InstanceMethods.html | 2 +- doc/Reddit/Message.html | 2 +- doc/Reddit/Submission.html | 2 +- doc/Reddit/Thing.html | 2 +- doc/Reddit/User.html | 2 +- doc/Reddit/Vote.html | 2 +- doc/_index.html | 2 +- doc/file.README.html | 2 +- doc/index.html | 2 +- doc/method_list.html | 302 ++++++++------- doc/top-level-namespace.html | 2 +- features/step_definitions/submission_steps.rb | 1 + lib/ruby_reddit_api/comment.rb | 38 +- 21 files changed, 491 insertions(+), 244 deletions(-) diff --git a/README b/README index 8535857..0727fdf 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Ruby Reddit Client v0.2.1 +Ruby Reddit Client v0.2.2 ================== Tested with ruby 1.9.2 diff --git a/VERSION b/VERSION index 0c62199..ee1372d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.1 +0.2.2 diff --git a/doc/Reddit.html b/doc/Reddit.html index 26429ca..31a2187 100644 --- a/doc/Reddit.html +++ b/doc/Reddit.html @@ -147,7 +147,7 @@

Returns:

diff --git a/doc/Reddit/Api.html b/doc/Reddit/Api.html index 5b057ef..f51d315 100644 --- a/doc/Reddit/Api.html +++ b/doc/Reddit/Api.html @@ -832,7 +832,7 @@

Returns:

diff --git a/doc/Reddit/Base.html b/doc/Reddit/Base.html index e63f681..e2f9bf6 100644 --- a/doc/Reddit/Base.html +++ b/doc/Reddit/Base.html @@ -1639,7 +1639,7 @@

Returns:

diff --git a/doc/Reddit/Comment.html b/doc/Reddit/Comment.html index f111665..75dd7b7 100644 --- a/doc/Reddit/Comment.html +++ b/doc/Reddit/Comment.html @@ -478,6 +478,33 @@

Instance Attribute Summary (collap

+ + + +
  • + + + - (Object) replies + + + + + + + readonly + + + + + + + + +

    +Returns the value of attribute replies. +

    +
    +
  • @@ -684,6 +711,30 @@

    + + + +
  • + + + - (true) handle_replies(data) + + + + + + + + + + + + +

    +Parse nested comment hashes into a Comment. +

    +
    +
  • @@ -735,7 +786,7 @@

  • - - (Comment) initialize(json) + - (Comment) initialize(json, options = {}) @@ -933,7 +984,7 @@

    Constructor Details

    - - (Comment) initialize(json) + - (Comment) initialize(json, options = {}) @@ -957,13 +1008,41 @@

    Constructor Details

    7 8 9 -10 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24
    # File 'lib/ruby_reddit_api/comment.rb', line 7
     
    -def initialize(json)
    -  parse(json)
    +def initialize(json, options={})
    +  mode = options.fetch(:mode){ :json }
    +  if mode == :json
    +    parse(json)
    +  end
    +
    +  if mode == :replies
    +    json.keys.each do |key|
    +      instance_variable_set("@#{key}", json[key])
    +    end
    +  end
    +
    +  if replies.is_a?(Hash)
    +    handle_replies(replies)
    +  end
    +
       @debug = StringIO.new
     end
    @@ -1523,6 +1602,48 @@

    Instance Attribute Details

    + + +
    +

    + + - (Object) replies (readonly) + + + +

    +
    +

    +Returns the value of attribute replies +

    + + +
    +
    +
    + +
    + + + + +
    +
    +
    +
    +6
    +7
    +8
    +
    +
    # File 'lib/ruby_reddit_api/comment.rb', line 6
    +
    +def replies
    +  @replies
    +end
    +
    +
    + +
    @@ -1668,18 +1789,16 @@

    Instance Method Details

     
     
    -90
    -91
    -92
    -93
    -94
    +104 +105 +106 +107 -
    # File 'lib/ruby_reddit_api/comment.rb', line 90
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 104
     
     def add_distinction(verb)
       resp=self.class.post("/api/distinguish/#{verb}", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "distinguishing..."}, :headers => base_headers, :debug_output => @debug })
    -  puts resp.headers
       resp.code == 200
     end
    @@ -1700,12 +1819,12 @@

    Instance Method Details

     
     
    -64
    -65
    -66
    +78 +79 +80
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 64
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 78
     
     def admin_distinguish
       add_distinction "admin"
    @@ -1752,13 +1871,13 @@ 

    Returns:

     
     
    -55
    -56
    -57
    -58
    +69 +70 +71 +72
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 55
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 69
     
     def approve
       resp=self.class.post("/api/approve", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug })
    @@ -1806,17 +1925,17 @@ 

    Returns:

     
     
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    +37 +38 +39 +40 +41 +42 +43 +44
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 23
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 37
     
     def comments
       opts = {:handler => "Comment",
    @@ -1868,13 +1987,13 @@ 

    Returns:

     
     
    -34
    -35
    -36
    -37
    +48 +49 +50 +51
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 34
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 48
     
     def edit(newtext)
       resp=self.class.post("/api/editusertext", {:body => {:thing_id => id, :uh => modhash, :r => subreddit, :text => newtext }, :headers => base_headers, :debug_output => @debug })
    @@ -1883,6 +2002,91 @@ 

    Returns:

    +
    + +
    +

    + + - (true) handle_replies(data) + + + +

    +
    +

    +Parse nested comment hashes into a Comment +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + (Hash) + + + JSON + + + + — +

      +containing reply data +

      +
      + +
    • + +
    +

    Returns:

    +
      + +
    • + + (true) + + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +112
    +113
    +114
    +115
    +116
    +117
    +118
    +119
    +120
    +
    +
    # File 'lib/ruby_reddit_api/comment.rb', line 112
    +
    +def handle_replies(data)
    +   dup = data.dup
    +   _kind, data       = dup["kind"],     dup["data"]
    +   modhash, children = data["modhash"], data["children"]
    +   if children.is_a?(Array)
    +     @replies = children.map{|reply| Comment.new(reply["data"], :mode => :replies) }
    +   end
    +   true
    +end
    +
    @@ -1922,13 +2126,13 @@

    Returns:

     
     
    -41
    -42
    -43
    -44
    +55 +56 +57 +58 -
    # File 'lib/ruby_reddit_api/comment.rb', line 41
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 55
     
     def hide
       resp=self.class.post("/api/del", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "removed" }, :headers => base_headers, :debug_output => @debug })
    @@ -1952,12 +2156,12 @@ 

    Returns:

     
     
    -68
    -69
    -70
    +82 +83 +84
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 68
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 82
     
     def indistinguish
       add_distinction "no"
    @@ -1980,15 +2184,15 @@ 

    Returns:

     
     
    -12
    -13
    -14
    +26 +27 +28
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 12
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 26
     
     def inspect
    -  "<Reddit::Comment author='#{@author}' body='#{short_body}'>"
    +  "<Reddit::Comment author='#{@author}' body='#{short_body}' replies='#{replies.size}' ups='#{ups}' downs='#{downs}'>"
     end
    @@ -2008,12 +2212,12 @@

    Returns:

     
     
    -60
    -61
    -62
    +74 +75 +76
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 60
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 74
     
     def moderator_distinguish
       add_distinction "yes"
    @@ -2060,13 +2264,13 @@ 

    Returns:

     
     
    -48
    -49
    -50
    -51
    +62 +63 +64 +65
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 48
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 62
     
     def remove
       resp=self.class.post("/api/remove", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug })
    @@ -2114,13 +2318,13 @@ 

    Returns:

     
     
    -74
    -75
    -76
    -77
    +88 +89 +90 +91
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 74
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 88
     
     def reply(text)
       resp = self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug })
    @@ -2168,20 +2372,20 @@ 

    Returns:

     
     
    -81
    -82
    -83
    -84
    -85
    -86
    -87
    -88
    +95 +96 +97 +98 +99 +100 +101 +102
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 81
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 95
     
     def short_body
    -  str = body.to_s
    +  str = body.to_s.strip
       if str.size > 15
         str[0..15] + "..."
       else
    @@ -2227,12 +2431,12 @@ 

    Returns:

     
     
    -17
    -18
    -19
    +31 +32 +33
    -
    # File 'lib/ruby_reddit_api/comment.rb', line 17
    +      
    # File 'lib/ruby_reddit_api/comment.rb', line 31
     
     def to_s
       body
    @@ -2247,7 +2451,7 @@ 

    Returns:

    diff --git a/doc/Reddit/JsonListing.html b/doc/Reddit/JsonListing.html index 3faf7ed..2d3f219 100644 --- a/doc/Reddit/JsonListing.html +++ b/doc/Reddit/JsonListing.html @@ -154,7 +154,7 @@

    Class Method Details

    diff --git a/doc/Reddit/JsonListing/ClassMethods.html b/doc/Reddit/JsonListing/ClassMethods.html index af9b664..d7d1910 100644 --- a/doc/Reddit/JsonListing/ClassMethods.html +++ b/doc/Reddit/JsonListing/ClassMethods.html @@ -214,7 +214,7 @@

    Returns:

    diff --git a/doc/Reddit/JsonListing/InstanceMethods.html b/doc/Reddit/JsonListing/InstanceMethods.html index abb550d..c6389c7 100644 --- a/doc/Reddit/JsonListing/InstanceMethods.html +++ b/doc/Reddit/JsonListing/InstanceMethods.html @@ -192,7 +192,7 @@

    Returns:

    diff --git a/doc/Reddit/Message.html b/doc/Reddit/Message.html index f17c6d7..1a0637b 100644 --- a/doc/Reddit/Message.html +++ b/doc/Reddit/Message.html @@ -1542,7 +1542,7 @@

    Returns:

    diff --git a/doc/Reddit/Submission.html b/doc/Reddit/Submission.html index 0f2d53a..e71e2ba 100644 --- a/doc/Reddit/Submission.html +++ b/doc/Reddit/Submission.html @@ -2654,7 +2654,7 @@

    Returns:

    diff --git a/doc/Reddit/Thing.html b/doc/Reddit/Thing.html index fda44c6..b2540df 100644 --- a/doc/Reddit/Thing.html +++ b/doc/Reddit/Thing.html @@ -677,7 +677,7 @@

    Returns:

    diff --git a/doc/Reddit/User.html b/doc/Reddit/User.html index 010302c..61b6fd8 100644 --- a/doc/Reddit/User.html +++ b/doc/Reddit/User.html @@ -1238,7 +1238,7 @@

    Returns:

    diff --git a/doc/Reddit/Vote.html b/doc/Reddit/Vote.html index c2f1433..9726d5d 100644 --- a/doc/Reddit/Vote.html +++ b/doc/Reddit/Vote.html @@ -492,7 +492,7 @@

    Returns:

    diff --git a/doc/_index.html b/doc/_index.html index 253e8f3..2690a10 100644 --- a/doc/_index.html +++ b/doc/_index.html @@ -245,7 +245,7 @@

    Namespace Listing A-Z

    diff --git a/doc/file.README.html b/doc/file.README.html index 2ee03ab..a35ab2b 100644 --- a/doc/file.README.html +++ b/doc/file.README.html @@ -123,7 +123,7 @@
    - Set up the reddit VM ( - Generated on Wed Oct 6 23:21:39 2010 by + Generated on Sun Oct 10 01:18:34 2010 by yard 0.6.1 (ruby-1.9.2). diff --git a/doc/index.html b/doc/index.html index 2ee03ab..a35ab2b 100644 --- a/doc/index.html +++ b/doc/index.html @@ -123,7 +123,7 @@
    - Set up the reddit VM ( - Generated on Wed Oct 6 23:21:39 2010 by + Generated on Sun Oct 10 01:18:34 2010 by yard 0.6.1 (ruby-1.9.2). diff --git a/doc/method_list.html b/doc/method_list.html index fa55919..46f298b 100644 --- a/doc/method_list.html +++ b/doc/method_list.html @@ -77,17 +77,17 @@

    Method List

  • - #author + #author - Reddit::Message + Reddit::Comment
  • - #author + #author - Reddit::Comment + Reddit::Message
  • @@ -109,17 +109,17 @@

    Method List

  • - #body + #body - Reddit::Message + Reddit::Comment
  • - #body + #body - Reddit::Comment + Reddit::Message
  • @@ -165,9 +165,9 @@

    Method List

  • - #comments + #comments - Reddit::Submission + Reddit::Api
  • @@ -181,9 +181,9 @@

    Method List

  • - #comments + #comments - Reddit::Api + Reddit::Submission
  • @@ -197,7 +197,7 @@

    Method List

  • - cookie + #cookie Reddit::Base @@ -205,7 +205,7 @@

    Method List

  • - #cookie + cookie Reddit::Base @@ -213,65 +213,65 @@

    Method List

  • - #created + #created - Reddit::Comment + Reddit::Message
  • - #created + #created - Reddit::User + Reddit::Comment
  • - #created + #created - Reddit::Submission + Reddit::User
  • - #created + #created - Reddit::Message + Reddit::Submission
  • - #created_utc + #created_utc - Reddit::Message + Reddit::Comment
  • - #created_utc + #created_utc - Reddit::Submission + Reddit::Message
  • - #created_utc + #created_utc - Reddit::Comment + Reddit::User
  • - #created_utc + #created_utc - Reddit::User + Reddit::Submission
  • @@ -285,33 +285,33 @@

    Method List

  • - #debug + #debug - Reddit::User + Reddit::Api
  • - #debug + #debug - Reddit::Comment + Reddit::Message
  • - #debug + #debug - Reddit::Message + Reddit::Comment
  • - #debug + #debug - Reddit::Api + Reddit::User
  • @@ -341,17 +341,17 @@

    Method List

  • - #downs + #downs - Reddit::Comment + Reddit::Submission
  • - #downs + #downs - Reddit::Submission + Reddit::Comment
  • @@ -389,25 +389,25 @@

    Method List

  • - #has_mod_mail + #handle_replies - Reddit::User + Reddit::Comment
  • - #hidden + #has_mod_mail - Reddit::Submission + Reddit::User
  • - #hide + #hidden - Reddit::Comment + Reddit::Submission
  • @@ -421,17 +421,17 @@

    Method List

  • - #id + #hide - Reddit::Message + Reddit::Comment
  • - #id + #id - Reddit::User + Reddit::Message
  • @@ -445,33 +445,33 @@

    Method List

  • - included + #id - Reddit::JsonListing + Reddit::User
  • - #indistinguish + included - Reddit::Comment + Reddit::JsonListing
  • - #indistinguish + #indistinguish - Reddit::Submission + Reddit::Comment
  • - #initialize + #indistinguish - Reddit::Base + Reddit::Submission
  • @@ -485,17 +485,17 @@

    Method List

  • - #initialize + #initialize - Reddit::Thing + Reddit::Vote
  • - #initialize + #initialize - Reddit::User + Reddit::Base
  • @@ -509,9 +509,9 @@

    Method List

  • - #initialize + #initialize - Reddit::Vote + Reddit::Thing
  • @@ -525,17 +525,17 @@

    Method List

  • - #inspect + #initialize - Reddit::Base + Reddit::User
  • - #inspect + #inspect - Reddit::Message + Reddit::User
  • @@ -549,55 +549,55 @@

    Method List

  • - #inspect + #inspect - Reddit::Api + Reddit::Submission
  • - #inspect + #inspect - Reddit::User + Reddit::Api
  • - #inspect + #inspect - Reddit::Vote + Reddit::Base
  • - #inspect + #inspect - Reddit::Submission + Reddit::Message
  • - #is_mod + #inspect - Reddit::User + Reddit::Vote
  • - #is_self + #is_mod - Reddit::Submission + Reddit::User
  • - #kind + #is_self Reddit::Submission @@ -605,9 +605,9 @@

    Method List

  • - #kind + #kind - Reddit::User + Reddit::Submission
  • @@ -629,6 +629,14 @@

    Method List

  • + #kind + + Reddit::User + +
  • + + +
  • #last_action Reddit::Api @@ -636,7 +644,7 @@

    Method List

  • -
  • +
  • #last_action Reddit::Base @@ -644,7 +652,7 @@

    Method List

  • -
  • +
  • #last_comment_id Reddit::Submission @@ -652,7 +660,7 @@

    Method List

  • -
  • +
  • #likes Reddit::Comment @@ -660,7 +668,7 @@

    Method List

  • -
  • +
  • #likes Reddit::Submission @@ -668,7 +676,7 @@

    Method List

  • -
  • +
  • #link_id Reddit::Comment @@ -676,7 +684,7 @@

    Method List

  • -
  • +
  • #link_karma Reddit::User @@ -684,7 +692,7 @@

    Method List

  • -
  • +
  • #logged_in? Reddit::Base @@ -692,7 +700,7 @@

    Method List

  • -
  • +
  • #login Reddit::Base @@ -700,7 +708,7 @@

    Method List

  • -
  • +
  • #logout Reddit::Base @@ -708,16 +716,8 @@

    Method List

  • -
  • - #media - - Reddit::Submission - -
  • - -
  • - #media_embed + #media Reddit::Submission @@ -725,7 +725,7 @@

    Method List

  • - #moderator_distinguish + #media_embed Reddit::Submission @@ -741,15 +741,15 @@

    Method List

  • - modhash + #moderator_distinguish - Reddit::Base + Reddit::Submission
  • - #modhash + modhash Reddit::Base @@ -757,39 +757,39 @@

    Method List

  • - #name + #modhash - Reddit::User + Reddit::Base
  • - #name + #name - Reddit::Message + Reddit::Comment
  • - #name + #name - Reddit::Comment + Reddit::Message
  • - #name + #name - Reddit::Submission + Reddit::User
  • - #num_comments + #name Reddit::Submission @@ -805,7 +805,7 @@

    Method List

  • - #over_18 + #num_comments Reddit::Submission @@ -813,25 +813,25 @@

    Method List

  • - #parent_id + #over_18 - Reddit::Comment + Reddit::Submission
  • - #parent_id + #parent_id - Reddit::Message + Reddit::Comment
  • - #parse + #parent_id - Reddit::JsonListing::InstanceMethods + Reddit::Message
  • @@ -845,6 +845,14 @@

    Method List

  • + #parse + + Reddit::JsonListing::InstanceMethods + +
  • + + +
  • #permalink Reddit::Submission @@ -852,7 +860,7 @@

    Method List

  • -
  • +
  • #post_replies Reddit::Api @@ -860,7 +868,7 @@

    Method List

  • -
  • +
  • #read Reddit::Base @@ -868,7 +876,7 @@

    Method List

  • -
  • +
  • #received_messages Reddit::Api @@ -876,7 +884,7 @@

    Method List

  • -
  • +
  • #remove Reddit::Comment @@ -884,6 +892,14 @@

    Method List

  • +
  • + #replies + + Reddit::Comment + +
  • + +
  • #replies @@ -957,17 +973,17 @@

    Method List

  • - #short_body + #short_body - Reddit::Comment + Reddit::Message
  • - #short_body + #short_body - Reddit::Message + Reddit::Comment
  • @@ -997,17 +1013,17 @@

    Method List

  • - #subreddit + #subreddit - Reddit::Comment + Reddit::Message
  • - #subreddit + #subreddit - Reddit::Message + Reddit::Comment
  • @@ -1045,17 +1061,17 @@

    Method List

  • - #to_s + #to_s - Reddit::User + Reddit::Comment
  • - #to_s + #to_s - Reddit::Comment + Reddit::User
  • @@ -1101,17 +1117,17 @@

    Method List

  • - #ups + #ups - Reddit::Comment + Reddit::Submission
  • - #ups + #ups - Reddit::Submission + Reddit::Comment
  • diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html index 45213e7..f12b434 100644 --- a/doc/top-level-namespace.html +++ b/doc/top-level-namespace.html @@ -79,7 +79,7 @@

    Defined Under Namespace

    diff --git a/features/step_definitions/submission_steps.rb b/features/step_definitions/submission_steps.rb index 398ba2c..2f9107c 100644 --- a/features/step_definitions/submission_steps.rb +++ b/features/step_definitions/submission_steps.rb @@ -112,6 +112,7 @@ end Then /^I should be able to see the comments$/ do + @submission.instance_variable_set("@last_action", Time.now - 60) if @submission comments = @submission.comments comments.size.should > 0 end diff --git a/lib/ruby_reddit_api/comment.rb b/lib/ruby_reddit_api/comment.rb index f4ca875..c1ddfee 100644 --- a/lib/ruby_reddit_api/comment.rb +++ b/lib/ruby_reddit_api/comment.rb @@ -3,14 +3,28 @@ module Reddit class Comment < Thing include JsonListing - attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :num_comments, :subreddit, :ups, :debug, :kind - def initialize(json) - parse(json) + attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :num_comments, :subreddit, :ups, :debug, :kind, :replies + def initialize(json, options={}) + mode = options.fetch(:mode){ :json } + if mode == :json + parse(json) + end + + if mode == :replies + json.keys.each do |key| + instance_variable_set("@#{key}", json[key]) + end + end + + if replies.is_a?(Hash) + handle_replies(replies) + end + @debug = StringIO.new end def inspect - "" + "" end # @return [String] @@ -79,7 +93,7 @@ def reply(text) # Trimmed comment body suitable for #inspect # @return [String] def short_body - str = body.to_s + str = body.to_s.strip if str.size > 15 str[0..15] + "..." else @@ -89,8 +103,20 @@ def short_body def add_distinction(verb) resp=self.class.post("/api/distinguish/#{verb}", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "distinguishing..."}, :headers => base_headers, :debug_output => @debug }) - puts resp.headers resp.code == 200 end + + # Parse nested comment hashes into a Comment + # @param [Hash] JSON containing reply data + # @return [true] + def handle_replies(data) + dup = data.dup + _kind, data = dup["kind"], dup["data"] + modhash, children = data["modhash"], data["children"] + if children.is_a?(Array) + @replies = children.map{|reply| Comment.new(reply["data"], :mode => :replies) } + end + true + end end end