Module: RedditKit::Client::Comments
- Included in:
- RedditKit::Client
- Defined in:
- lib/redditkit/client/comments.rb
Overview
Methods for interacting with comment threads.
Instance Method Summary collapse
-
#comment(comment_full_name) ⇒ RedditKit::Comment
Get a comment object from its full name.
-
#comments(link, options = {}) ⇒ Array<RedditKit::Comment>
Get comments on a link.
-
#submit_comment(link_or_comment, text) ⇒ RedditKit::Comment
Submit a comment on a link or comment.
Instance Method Details
#comment(comment_full_name) ⇒ RedditKit::Comment
Note:
This method does not include any replies to the comment.
Get a comment object from its full name.
14 15 16 17 |
# File 'lib/redditkit/client/comments.rb', line 14 def comment(comment_full_name) comments = objects_from_response(:get, 'api/info.json', { :id => comment_full_name }) comments.first end |
#comments(link, options = {}) ⇒ Array<RedditKit::Comment>
Get comments on a link.
24 25 26 27 28 29 30 31 |
# File 'lib/redditkit/client/comments.rb', line 24 def comments(link, = {}) return nil unless link link_id = extract_id link path = "comments/#{link_id}.json" comments_from_response(:get, path, ) end |
#submit_comment(link_or_comment, text) ⇒ RedditKit::Comment
Submit a comment on a link or comment.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/redditkit/client/comments.rb', line 38 def submit_comment(link_or_comment, text) object_full_name = extract_full_name link_or_comment parameters = { :text => text, :thing_id => object_full_name, :api_type => :json } response = post('/api/comment', parameters) response_data = response[:body][:json][:data] full_comment_data = response_data[:things].first comment_data = full_comment_data[:data] comment_full_name = comment_data[:id] comment comment_full_name end |