Class: Denglu::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/denglu/comment.rb

Instance Attribute Summary

Attributes inherited from Base

#app_id, #app_key

Instance Method Summary collapse

Methods inherited from Base

#initialize

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'
  req_options = {
    :count => max
  }

  response = request_api(req_method, req_uri, req_options)

  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'
  req_options = {
    :commentid => comment_id,
    :count => max
  }

  response = request_api(req_method, req_uri, req_options)

  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'
  req_options = {
    :time => from_ts || generate_millisecond
  }

  response = request_api(req_method, req_uri, req_options)
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'
  req_options = {}
  case
  when resource.is_a?(Integer)
    req_options[:postid] = resource
  when resource.is_a?(String)
    req_options[:url] = resource
  end

  response = request_api(req_method, req_uri, req_options)

  response = JSON.parse(response)
  unless resource.nil?
    response = response[0]
  end

  response
end