Class: Denglu::Comment
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#latest(max = 20) ⇒ Object
Get latest comments NOTE: This contains no relations of comments!.
-
#list(comment_id = 0, max = 50) ⇒ Object
Get comment list This will contains comments’ relations in response.
-
#stat(from_ts = nil) ⇒ Object
NOTE: NO IMPL!.
-
#total(resource = nil) ⇒ Object
Get comment count If resource is nil it will return all posts comment count in an array, otherwise just return a hash object.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Denglu::Base
Instance Method Details
#latest(max = 20) ⇒ Object
Get latest comments NOTE: This contains no relations of comments!
Example:
>> comment = Denglu::Comment.new
=> #<#Denglu::Comment...>
>> comments = comment.latest
=> [{...}, {...}]
Arguments:
max: (Integer) The max records of response, default to 20
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/denglu/comment.rb', line 45 def latest(max=20) req_method = :GET req_uri = '/api/v4/latest_comment' = { :count => max } response = request_api(req_method, req_uri, ) JSON.parse(response) end |
#list(comment_id = 0, max = 50) ⇒ Object
Get comment list This will contains comments’ relations in response.
Example:
>> comment = Denglu::Comment.new
=> #<#Denglu::Comment...>
>> comments = comment.list
=> [{...}, {...}]
Arguments:
comment_id: (Integer) The offset marker of response, default to 0 mains from the begining
max: (Integer) The max records of response, default to 50
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/denglu/comment.rb', line 20 def list(comment_id=0, max=50) req_method = :GET req_uri = '/api/v4/get_comment_list' = { :commentid => comment_id, :count => max } response = request_api(req_method, req_uri, ) normalize_comments JSON.parse(response) end |
#stat(from_ts = nil) ⇒ Object
NOTE: NO IMPL!
92 93 94 95 96 97 98 99 100 |
# File 'lib/denglu/comment.rb', line 92 def stat(from_ts=nil) req_method = :GET req_uri = '/api/v4/get_change_comment_ids' = { :time => from_ts || generate_millisecond } response = request_api(req_method, req_uri, ) end |
#total(resource = nil) ⇒ Object
Get comment count If resource is nil it will return all posts comment count in an array, otherwise just return a hash object.
Example:
>> comment = Denglu::Comment.new
=> #<#Denglu::Comment...>
>> comments = comment.total
=> [{"id"=>..., "count"=>..., "url"=>...},
=> {...}]
Arguments:
resource: (Mixed) Integer for resource id or string for uri.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/denglu/comment.rb', line 70 def total(resource=nil) req_method = :GET req_uri = '/api/v4/get_comment_count' = {} case when resource.is_a?(Integer) [:postid] = resource when resource.is_a?(String) [:url] = resource end response = request_api(req_method, req_uri, ) response = JSON.parse(response) unless resource.nil? response = response[0] end response end |