denglu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,16 @@ module Denglu
5
5
  class Base
6
6
  attr_reader :app_id, :app_key
7
7
 
8
+ # Initialization
9
+ #
10
+ # Example:
11
+ # >> denglu = Denglu::Base.new
12
+ # => #<#Denglu::Base...>
13
+ #
14
+ # Arguments:
15
+ # app_id: (String)
16
+ # app_key: (String)
17
+ #
8
18
  def initialize(app_id=nil, app_key=nil)
9
19
  @app_id = app_id || Config.app_id
10
20
  @app_key = app_key || Config.app_key
@@ -4,6 +4,19 @@ module Denglu
4
4
 
5
5
  class Comment < Base
6
6
 
7
+ # Get comment list
8
+ # This will contains comments' relations in response.
9
+ #
10
+ # Example:
11
+ # >> comment = Denglu::Comment.new
12
+ # => #<#Denglu::Comment...>
13
+ # >> comments = comment.list
14
+ # => [{...}, {...}]
15
+ #
16
+ # Arguments:
17
+ # comment_id: (Integer) The offset marker of response, default to 0 mains from the begining
18
+ # max: (Integer) The max records of response, default to 50
19
+ #
7
20
  def list(comment_id=0, max=50)
8
21
  req_method = :GET
9
22
  req_uri = '/api/v4/get_comment_list'
@@ -17,6 +30,18 @@ module Denglu
17
30
  normalize_comments JSON.parse(response)
18
31
  end
19
32
 
33
+ # Get latest comments
34
+ # NOTE: This contains no relations of comments!
35
+ #
36
+ # Example:
37
+ # >> comment = Denglu::Comment.new
38
+ # => #<#Denglu::Comment...>
39
+ # >> comments = comment.latest
40
+ # => [{...}, {...}]
41
+ #
42
+ # Arguments:
43
+ # max: (Integer) The max records of response, default to 20
44
+ #
20
45
  def latest(max=20)
21
46
  req_method = :GET
22
47
  req_uri = '/api/v4/latest_comment'
@@ -29,6 +54,19 @@ module Denglu
29
54
  JSON.parse(response)
30
55
  end
31
56
 
57
+ # Get comment count
58
+ # If resource is nil it will return all posts comment count in an array, otherwise just return a hash object.
59
+ #
60
+ # Example:
61
+ # >> comment = Denglu::Comment.new
62
+ # => #<#Denglu::Comment...>
63
+ # >> comments = comment.total
64
+ # => [{"id"=>..., "count"=>..., "url"=>...},
65
+ # => {...}]
66
+ #
67
+ # Arguments:
68
+ # resource: (Mixed) Integer for resource id or string for uri.
69
+ #
32
70
  def total(resource=nil)
33
71
  req_method = :GET
34
72
  req_uri = '/api/v4/get_comment_count'
@@ -42,9 +80,15 @@ module Denglu
42
80
 
43
81
  response = request_api(req_method, req_uri, req_options)
44
82
 
45
- JSON.parse response
83
+ response = JSON.parse(response)
84
+ unless resource.nil?
85
+ response = response[0]
86
+ end
87
+
88
+ response
46
89
  end
47
90
 
91
+ # NOTE: NO IMPL!
48
92
  def stat(from_ts=nil)
49
93
  req_method = :GET
50
94
  req_uri = '/api/v4/get_change_comment_ids'
@@ -16,14 +16,17 @@ module Denglu
16
16
  @app_key ||= ''
17
17
  end
18
18
 
19
+ # Denglu api host, default to http://open.denglu.cc
19
20
  def host
20
21
  @host ||= 'http://open.denglu.cc'
21
22
  end
22
23
 
24
+ # Denglu api version, no used now
23
25
  def version
24
26
  @version ||= '1.0'
25
27
  end
26
28
 
29
+ # Denglu api rquest sign method, only support md5
27
30
  def sign_type
28
31
  @sign_type ||= :md5
29
32
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Denglu
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -7,28 +7,48 @@ module Denglu
7
7
  @comment = Comment.new
8
8
  end
9
9
 
10
- context '.list' do
10
+ context ".list" do
11
11
  it "should works" do
12
12
  result = @comment.list
13
-
14
13
  result.should be_instance_of(Array)
14
+ result.to_json.should include('parentID')
15
15
  end
16
16
  end
17
17
 
18
- context '.latest' do
18
+ context ".latest" do
19
19
  it "should works" do
20
20
  result = @comment.latest
21
-
22
21
  result.should be_instance_of(Array)
22
+ result.to_json.should_not include('parentID')
23
23
  end
24
24
  end
25
25
 
26
- context '.total' do
26
+ context ".total" do
27
27
  it "should works" do
28
28
  result = @comment.total
29
29
 
30
30
  result.should be_instance_of(Array)
31
31
  end
32
+
33
+ context "with argument" do
34
+ before :each do
35
+ @resource = @comment.total[0]
36
+ end
37
+
38
+ it "should return a hash object when supply resource id" do
39
+ resource_id = @resource['id'].to_i
40
+
41
+ result = @comment.total(resource_id)
42
+ result.should be_instance_of(Hash)
43
+ end
44
+
45
+ it "should return a hash object when supply resource url" do
46
+ resource_url = @resource['url']
47
+
48
+ result = @comment.total(resource_url)
49
+ result.should be_instance_of(Hash)
50
+ end
51
+ end
32
52
  end
33
53
  end
34
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denglu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000 Z
12
+ date: 2012-08-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -71,7 +71,6 @@ files:
71
71
  - Gemfile
72
72
  - Gemfile.lock
73
73
  - LICENSE
74
- - LICENSE.md
75
74
  - README.md
76
75
  - Rakefile
77
76
  - denglu.gemspec
@@ -109,3 +108,4 @@ signing_key:
109
108
  specification_version: 3
110
109
  summary: Denglu open API wrapper of ruby language
111
110
  test_files: []
111
+ has_rdoc:
data/LICENSE.md DELETED
File without changes