denglu 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +20 -0
- data/LICENSE.md +0 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/denglu.gemspec +25 -0
- data/lib/denglu.rb +12 -0
- data/lib/denglu/auth.rb +9 -0
- data/lib/denglu/base.rb +60 -0
- data/lib/denglu/comment.rb +75 -0
- data/lib/denglu/config.rb +36 -0
- data/lib/denglu/version.rb +5 -0
- data/spec/denglu/base_spec.rb +8 -0
- data/spec/denglu/comment_spec.rb +35 -0
- data/spec/spec_helper.rb +17 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
denglu (0.0.1)
|
5
|
+
json
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
json (1.7.4)
|
13
|
+
mime-types (1.19)
|
14
|
+
rest-client (1.6.7)
|
15
|
+
mime-types (>= 1.16)
|
16
|
+
rspec (2.11.0)
|
17
|
+
rspec-core (~> 2.11.0)
|
18
|
+
rspec-expectations (~> 2.11.0)
|
19
|
+
rspec-mocks (~> 2.11.0)
|
20
|
+
rspec-core (2.11.1)
|
21
|
+
rspec-expectations (2.11.2)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.11.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
denglu!
|
30
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Spring MC <Heresy.Mc@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.md
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Denglu
|
2
|
+
|
3
|
+
denglu library provides access to [Denglu](http://www.denglu.cc), this is unofficial ruby implementation.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
gem install denglu
|
8
|
+
|
9
|
+
# Usage
|
10
|
+
|
11
|
+
## Initialize the comment
|
12
|
+
|
13
|
+
require 'denglu'
|
14
|
+
|
15
|
+
# Setup global default configurations, see Denglu::Config for more info
|
16
|
+
Denglu::Config.app_id = 'your-app-id'
|
17
|
+
Denglu::Config.app_key = 'your-app-key'
|
18
|
+
|
19
|
+
or use object initialize params
|
20
|
+
|
21
|
+
require 'denglu'
|
22
|
+
|
23
|
+
comment = Denglu::Comment.new('your-app-id', 'your-app-key')
|
24
|
+
#=> #<Denglu::Comment:...>
|
25
|
+
|
26
|
+
## List comments
|
27
|
+
|
28
|
+
comment.list
|
29
|
+
#=> [{"postid" => ..., "content" => ..., "mediaID" => ..., "createTime" => ..., "state" => ..., "commentID" => ..., "parentID" => ..., ...},
|
30
|
+
# {...}]
|
31
|
+
|
32
|
+
## Count comments
|
33
|
+
|
34
|
+
comment.total
|
35
|
+
#=> [{"id" => ..., "count" => ..., "url" => ...},
|
36
|
+
# {...}]
|
37
|
+
|
38
|
+
# See also
|
39
|
+
|
40
|
+
* [Denglu Document](http://developer.denglu.cc/)
|
41
|
+
|
42
|
+
# Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2012 Spring MC. See [LICENSE](http://github.com/mcspring/denglu/raw/master/LICENSE) for details.
|
45
|
+
|
data/Rakefile
ADDED
data/denglu.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'denglu/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'denglu'
|
7
|
+
gem.version = Denglu::VERSION
|
8
|
+
gem.authors = ['Spring MC']
|
9
|
+
gem.email = ['Heresy.Mc@gmail.com']
|
10
|
+
gem.homepage = 'http://github.com/mcspring/denglu'
|
11
|
+
gem.summary = 'Denglu open API wrapper of ruby language'
|
12
|
+
gem.description = 'NONE OFFICIAL'
|
13
|
+
|
14
|
+
gem.rubyforge_project = 'denglu'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
gem.test_files = gem.files.grep(%r{^(spec,test,features)/})
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_dependency 'json'
|
22
|
+
gem.add_dependency 'rest-client'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rspec'
|
25
|
+
end
|
data/lib/denglu.rb
ADDED
data/lib/denglu/auth.rb
ADDED
data/lib/denglu/base.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Denglu
|
4
|
+
|
5
|
+
class Base
|
6
|
+
attr_reader :app_id, :app_key
|
7
|
+
|
8
|
+
def initialize(app_id=nil, app_key=nil)
|
9
|
+
@app_id = app_id || Config.app_id
|
10
|
+
@app_key = app_key || Config.app_key
|
11
|
+
|
12
|
+
unless @app_id || @app_key
|
13
|
+
raise 'Uninitialized app_id or app_key!'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def request_api(method, uri, options)
|
19
|
+
uri = "#{Config.host}#{uri}"
|
20
|
+
|
21
|
+
params = options.merge({
|
22
|
+
:appid => @app_id,
|
23
|
+
:timestamp => generate_millisecond,
|
24
|
+
:sign_type => Config.sign_type
|
25
|
+
})
|
26
|
+
params[:sign] = generate_sign(params)
|
27
|
+
|
28
|
+
case method.upcase.to_sym
|
29
|
+
when :POST
|
30
|
+
RestClient.post uri, params
|
31
|
+
when :GET
|
32
|
+
RestClient.get uri, :params => params
|
33
|
+
else
|
34
|
+
raise "Unexpected http request method: #{method}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_sign(options={})
|
39
|
+
sign_str = ''
|
40
|
+
options.keys.sort.each do |key|
|
41
|
+
sign_str << "#{key}=#{options[key]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
sign_str << @app_key
|
45
|
+
|
46
|
+
case Config.sign_type.upcase.to_sym
|
47
|
+
when :MD5
|
48
|
+
Digest::MD5.hexdigest(sign_str)
|
49
|
+
else
|
50
|
+
raise "Unsupported sign method: #{sign_type}, only :md5 method used for now!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_millisecond
|
55
|
+
Time.now.to_i * 1000
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -* encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Denglu
|
4
|
+
|
5
|
+
class Comment < Base
|
6
|
+
|
7
|
+
def list(comment_id=0, max=50)
|
8
|
+
req_method = :GET
|
9
|
+
req_uri = '/api/v4/get_comment_list'
|
10
|
+
req_options = {
|
11
|
+
:commentid => comment_id,
|
12
|
+
:count => max
|
13
|
+
}
|
14
|
+
|
15
|
+
response = request_api(req_method, req_uri, req_options)
|
16
|
+
|
17
|
+
normalize_comments JSON.parse(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def latest(max=20)
|
21
|
+
req_method = :GET
|
22
|
+
req_uri = '/api/v4/latest_comment'
|
23
|
+
req_options = {
|
24
|
+
:count => max
|
25
|
+
}
|
26
|
+
|
27
|
+
response = request_api(req_method, req_uri, req_options)
|
28
|
+
|
29
|
+
JSON.parse(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def total(resource=nil)
|
33
|
+
req_method = :GET
|
34
|
+
req_uri = '/api/v4/get_comment_count'
|
35
|
+
req_options = {}
|
36
|
+
case
|
37
|
+
when resource.is_a?(Integer)
|
38
|
+
req_options[:postid] = resource
|
39
|
+
when resource.is_a?(String)
|
40
|
+
req_options[:url] = resource
|
41
|
+
end
|
42
|
+
|
43
|
+
response = request_api(req_method, req_uri, req_options)
|
44
|
+
|
45
|
+
JSON.parse response
|
46
|
+
end
|
47
|
+
|
48
|
+
def stat(from_ts=nil)
|
49
|
+
req_method = :GET
|
50
|
+
req_uri = '/api/v4/get_change_comment_ids'
|
51
|
+
req_options = {
|
52
|
+
:time => from_ts || generate_millisecond
|
53
|
+
}
|
54
|
+
|
55
|
+
response = request_api(req_method, req_uri, req_options)
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
def normalize_comments(comments)
|
60
|
+
comments.collect do |comment|
|
61
|
+
comment['parentID'] = 0
|
62
|
+
if comment.has_key?('parent')
|
63
|
+
comment['parentID'] = comment['parent']['commentID']
|
64
|
+
|
65
|
+
comment.delete 'parent'
|
66
|
+
end
|
67
|
+
|
68
|
+
comment
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Denglu
|
4
|
+
|
5
|
+
class Config
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :app_id, :app_key
|
9
|
+
attr_accessor :host, :version, :sign_type
|
10
|
+
|
11
|
+
def app_id
|
12
|
+
@app_id ||= ''
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_key
|
16
|
+
@app_key ||= ''
|
17
|
+
end
|
18
|
+
|
19
|
+
def host
|
20
|
+
@host ||= 'http://open.denglu.cc'
|
21
|
+
end
|
22
|
+
|
23
|
+
def version
|
24
|
+
@version ||= '1.0'
|
25
|
+
end
|
26
|
+
|
27
|
+
def sign_type
|
28
|
+
@sign_type ||= :md5
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Denglu
|
4
|
+
|
5
|
+
describe Comment do
|
6
|
+
before :each do
|
7
|
+
@comment = Comment.new
|
8
|
+
end
|
9
|
+
|
10
|
+
context '.list' do
|
11
|
+
it "should works" do
|
12
|
+
result = @comment.list
|
13
|
+
|
14
|
+
result.should be_instance_of(Array)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '.latest' do
|
19
|
+
it "should works" do
|
20
|
+
result = @comment.latest
|
21
|
+
|
22
|
+
result.should be_instance_of(Array)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '.total' do
|
27
|
+
it "should works" do
|
28
|
+
result = @comment.total
|
29
|
+
|
30
|
+
result.should be_instance_of(Array)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'denglu'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.include RSpec::Matchers
|
6
|
+
|
7
|
+
config.mock_with :rspec
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Setup spec app config
|
12
|
+
module Denglu
|
13
|
+
|
14
|
+
Config.app_id = '43669den56kf1gxRCmfn7UBW5kevQ3'
|
15
|
+
Config.app_key = '458394366Cr0ppwALx71Sx9m2f8jm6'
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: denglu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Spring MC
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: NONE OFFICIAL
|
63
|
+
email:
|
64
|
+
- Heresy.Mc@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE
|
74
|
+
- LICENSE.md
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- denglu.gemspec
|
78
|
+
- lib/denglu.rb
|
79
|
+
- lib/denglu/auth.rb
|
80
|
+
- lib/denglu/base.rb
|
81
|
+
- lib/denglu/comment.rb
|
82
|
+
- lib/denglu/config.rb
|
83
|
+
- lib/denglu/version.rb
|
84
|
+
- spec/denglu/base_spec.rb
|
85
|
+
- spec/denglu/comment_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: http://github.com/mcspring/denglu
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project: denglu
|
107
|
+
rubygems_version: 1.8.24
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Denglu open API wrapper of ruby language
|
111
|
+
test_files: []
|