douban-ruby 0.0.5
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.tar.gz.sig +0 -0
- data/History.txt +40 -0
- data/Manifest.txt +34 -0
- data/README.txt +25 -0
- data/Rakefile +34 -0
- data/examples/example.rb +21 -0
- data/lib/douban.rb +57 -0
- data/lib/douban/author.rb +41 -0
- data/lib/douban/authorize.rb +1150 -0
- data/lib/douban/collection.rb +69 -0
- data/lib/douban/equal.rb +11 -0
- data/lib/douban/event.rb +80 -0
- data/lib/douban/mail.rb +56 -0
- data/lib/douban/miniblog.rb +59 -0
- data/lib/douban/note.rb +60 -0
- data/lib/douban/people.rb +48 -0
- data/lib/douban/recommendation.rb +47 -0
- data/lib/douban/recommendation_comment.rb +36 -0
- data/lib/douban/review.rb +66 -0
- data/lib/douban/subject.rb +87 -0
- data/lib/douban/tag.rb +39 -0
- data/spec/douban/author_spec.rb +32 -0
- data/spec/douban/authorize_spec.rb +508 -0
- data/spec/douban/collection_spec.rb +77 -0
- data/spec/douban/event_spec.rb +60 -0
- data/spec/douban/mail_spec.rb +98 -0
- data/spec/douban/miniblog_spec.rb +48 -0
- data/spec/douban/note_spec.rb +60 -0
- data/spec/douban/people_spec.rb +49 -0
- data/spec/douban/recommendation_comment_spec.rb +38 -0
- data/spec/douban/recommendation_spec.rb +48 -0
- data/spec/douban/review_spec.rb +76 -0
- data/spec/douban/tag_spec.rb +29 -0
- data/spec/douban_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- metadata +152 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/subject'
|
3
|
+
require 'douban/author'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class Collection
|
7
|
+
|
8
|
+
include Douban::Equal
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def attr_names
|
12
|
+
[
|
13
|
+
:tag,
|
14
|
+
:updated,
|
15
|
+
:subject,
|
16
|
+
:author,
|
17
|
+
:title,
|
18
|
+
:summary,
|
19
|
+
:link,
|
20
|
+
:id,
|
21
|
+
:rating,
|
22
|
+
:status
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
attr_names.each do |attr|
|
27
|
+
attr_accessor attr
|
28
|
+
end
|
29
|
+
def initialize(atom)
|
30
|
+
doc = case atom
|
31
|
+
when REXML::Document then atom.root
|
32
|
+
when REXML::Element then atom
|
33
|
+
else REXML::Document.new(atom).root
|
34
|
+
end
|
35
|
+
subject=REXML::XPath.first(doc,"./db:subject")
|
36
|
+
@subject=Subject.new(subject) if subject
|
37
|
+
author=REXML::XPath.first(doc,"./author")
|
38
|
+
@author=Author.new(author.to_s) if author
|
39
|
+
title=REXML::XPath.first(doc,"./title")
|
40
|
+
@title=title.text if !title.nil?
|
41
|
+
updated=REXML::XPath.first(doc,"./updated")
|
42
|
+
@updated=updated.text if updated
|
43
|
+
@summary = REXML::XPath.first(doc, "./summary/text()").to_s
|
44
|
+
@status = REXML::XPath.first(doc, "./db:status/text()").to_s
|
45
|
+
@link = Hash.new
|
46
|
+
REXML::XPath.each(doc, "./link") do |e|
|
47
|
+
@link[e.attributes["rel"]] = e.attributes["href"]
|
48
|
+
end
|
49
|
+
id=REXML::XPath.first(doc,"./id")
|
50
|
+
@id=id.text if id
|
51
|
+
REXML::XPath.each(doc,"./db:tag") do |tag|
|
52
|
+
@tag||=[]
|
53
|
+
@tag<< tag.attributes['name']
|
54
|
+
end
|
55
|
+
rating=REXML::XPath.first(doc,"./db:rating")
|
56
|
+
if rating
|
57
|
+
@rating={}
|
58
|
+
@rating['min']=rating.attributes['min']
|
59
|
+
@rating['value']=rating.attributes['value']
|
60
|
+
@rating['max']=rating.attributes['max']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def collection_id
|
65
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/douban/equal.rb
ADDED
data/lib/douban/event.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/equal'
|
3
|
+
require 'douban/author'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class Event
|
7
|
+
include Douban::Equal
|
8
|
+
class << self
|
9
|
+
def attr_names
|
10
|
+
[
|
11
|
+
:id,
|
12
|
+
:title,
|
13
|
+
:category,
|
14
|
+
:author,
|
15
|
+
:link,
|
16
|
+
:summary,
|
17
|
+
:content,
|
18
|
+
:attribute,
|
19
|
+
:location,
|
20
|
+
:when,
|
21
|
+
:where
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
attr_names.each do |attr|
|
26
|
+
attr_accessor attr
|
27
|
+
end
|
28
|
+
def initialize(atom='')
|
29
|
+
doc = case atom
|
30
|
+
when REXML::Document then atom.root
|
31
|
+
when REXML::Element then atom
|
32
|
+
else REXML::Document.new(atom).root
|
33
|
+
end
|
34
|
+
|
35
|
+
@id=REXML::XPath.first(doc,"./id/text()").to_s
|
36
|
+
title=REXML::XPath.first(doc,"./title")
|
37
|
+
@title=title.text if title
|
38
|
+
@category={}
|
39
|
+
category=REXML::XPath.first(doc,"./category")
|
40
|
+
@category['term']=category.attributes['term'] if category
|
41
|
+
@category['scheme']=category.attributes['scheme'] if category
|
42
|
+
@author||=Author.new
|
43
|
+
name=REXML::XPath.first(doc,"//author/name")
|
44
|
+
@author.name=name.text if name
|
45
|
+
uri=REXML::XPath.first(doc,"//author/uri")
|
46
|
+
@author.uri=uri.text if uri
|
47
|
+
REXML::XPath.each(doc,"//author/link") do |link|
|
48
|
+
@author.link||={}
|
49
|
+
@author.link[link.attributes['rel']]=link.attributes['href']
|
50
|
+
end
|
51
|
+
summary=REXML::XPath.first(doc,"./summary")
|
52
|
+
@summary=summary.text if summary
|
53
|
+
content=REXML::XPath.first(doc,"./content")
|
54
|
+
@content=content.text if content
|
55
|
+
REXML::XPath.each(doc,"./link") do |link|
|
56
|
+
@link||={}
|
57
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
58
|
+
end
|
59
|
+
REXML::XPath.each(doc,"./db:attribute") do |attribute|
|
60
|
+
@attribute||={}
|
61
|
+
@attribute[attribute.attributes['name']]=attribute.text
|
62
|
+
end
|
63
|
+
location=REXML::XPath.first(doc,"./db:location")
|
64
|
+
@location=location.text if location
|
65
|
+
@when={}
|
66
|
+
time=REXML::XPath.first(doc,"./gd:when")
|
67
|
+
if time
|
68
|
+
@when['startTime']=time.attributes['startTime']
|
69
|
+
@when['endTime']=time.attributes['endTime']
|
70
|
+
end
|
71
|
+
where=REXML::XPath.first(doc,"./gd:where")
|
72
|
+
@where=where.attributes['valueString'] if where
|
73
|
+
end
|
74
|
+
|
75
|
+
def event_id
|
76
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/lib/douban/mail.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require "douban/subject"
|
3
|
+
require 'douban/author'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class Mail
|
7
|
+
class << self
|
8
|
+
def attr_names
|
9
|
+
[
|
10
|
+
:id,
|
11
|
+
:title,
|
12
|
+
:category,
|
13
|
+
:published,
|
14
|
+
:link,
|
15
|
+
:content,
|
16
|
+
:attribute,
|
17
|
+
:author,
|
18
|
+
:receiver
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
attr_names.each do |attr|
|
23
|
+
attr_accessor attr
|
24
|
+
end
|
25
|
+
def initialize(doc)
|
26
|
+
doc=REXML::XPath.first(REXML::Document.new(doc), "//entry") unless doc.kind_of?(REXML::Element)
|
27
|
+
title=REXML::XPath.first(doc,"./title")
|
28
|
+
@title=title.text if title
|
29
|
+
published=REXML::XPath.first(doc,"./published")
|
30
|
+
@published=published.text if published
|
31
|
+
REXML::XPath.each(doc,"./link") do |link|
|
32
|
+
@link||={}
|
33
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
34
|
+
end
|
35
|
+
id=REXML::XPath.first(doc,"./id")
|
36
|
+
@id=id.text if id
|
37
|
+
REXML::XPath.each(doc,"./db:attribute") do |attr|
|
38
|
+
@attribute||={}
|
39
|
+
@attribute[attr.attributes['name']]=attr.text
|
40
|
+
end
|
41
|
+
category=REXML::XPath.first(doc,"./category")
|
42
|
+
if category
|
43
|
+
@category={}
|
44
|
+
@category['term']=category.attributes['term']
|
45
|
+
@category['scheme']=category.attributes['scheme']
|
46
|
+
end
|
47
|
+
content=REXML::XPath.first(doc,"./content")
|
48
|
+
@content=content.text if content
|
49
|
+
author=REXML::XPath.first(doc,"./author")
|
50
|
+
@author=Author.new(author) if author
|
51
|
+
receiver=REXML::XPath.first(doc,"./db:entity[@name='receiver']")
|
52
|
+
@receiver=Author.new(receiver) if receiver
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require'rexml/document'
|
2
|
+
|
3
|
+
require 'douban/author'
|
4
|
+
require 'douban/equal'
|
5
|
+
|
6
|
+
module Douban
|
7
|
+
class Miniblog
|
8
|
+
include Douban::Equal
|
9
|
+
class << self
|
10
|
+
def attr_names
|
11
|
+
[
|
12
|
+
:id,
|
13
|
+
:title,
|
14
|
+
:category,
|
15
|
+
:published,
|
16
|
+
:link,
|
17
|
+
:content,
|
18
|
+
:attribute,
|
19
|
+
:author
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
attr_names.each do |attr|
|
24
|
+
attr_accessor attr
|
25
|
+
end
|
26
|
+
def initialize(atom)
|
27
|
+
doc = case atom
|
28
|
+
when REXML::Document then atom.root
|
29
|
+
when REXML::Element then atom
|
30
|
+
else REXML::Document.new(atom).root
|
31
|
+
end
|
32
|
+
title=REXML::XPath.first(doc,"./title")
|
33
|
+
@title=title.text if title
|
34
|
+
published=REXML::XPath.first(doc,"./published")
|
35
|
+
@published=published.text if published
|
36
|
+
REXML::XPath.each(doc,"./link") do |link|
|
37
|
+
@link||={}
|
38
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
39
|
+
end
|
40
|
+
id=REXML::XPath.first(doc,"./id")
|
41
|
+
@id=id.text if id
|
42
|
+
REXML::XPath.each(doc,"./db:attribute") do |attr|
|
43
|
+
@attribute||={}
|
44
|
+
@attribute[attr.attributes['name']]=attr.text
|
45
|
+
end
|
46
|
+
category=REXML::XPath.first(doc,"./category")
|
47
|
+
if category
|
48
|
+
@category={}
|
49
|
+
@category['term']=category.attributes['term']
|
50
|
+
@category['scheme']=category.attributes['scheme']
|
51
|
+
end
|
52
|
+
content=REXML::XPath.first(doc,"./content")
|
53
|
+
@content=content.text if content
|
54
|
+
author=REXML::XPath.first(doc,"./author")
|
55
|
+
@author=Author.new(author.to_s) if author
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/douban/note.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require'rexml/document'
|
2
|
+
|
3
|
+
require 'douban/author'
|
4
|
+
require 'douban/equal'
|
5
|
+
|
6
|
+
module Douban
|
7
|
+
class Note
|
8
|
+
include Douban::Equal
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def attr_names
|
12
|
+
[
|
13
|
+
:id,
|
14
|
+
:title,
|
15
|
+
:summary,
|
16
|
+
:updated,
|
17
|
+
:published,
|
18
|
+
:link,
|
19
|
+
:content,
|
20
|
+
:attribute,
|
21
|
+
:author
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
attr_names.each do |attr|
|
26
|
+
attr_accessor attr
|
27
|
+
end
|
28
|
+
def initialize(doc)
|
29
|
+
doc = REXML::Document.new(doc).root unless doc.kind_of?(REXML::Element)
|
30
|
+
doc = doc.root if doc.kind_of?(REXML::Document)
|
31
|
+
|
32
|
+
title=REXML::XPath.first(doc,"./title")
|
33
|
+
@title=title.text if title
|
34
|
+
published=REXML::XPath.first(doc,"./published")
|
35
|
+
@published=published.text if published
|
36
|
+
updated=REXML::XPath.first(doc,"./updated")
|
37
|
+
@updated=updated.text if updated
|
38
|
+
REXML::XPath.each(doc,"./link") do |link|
|
39
|
+
@link||={}
|
40
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
41
|
+
end
|
42
|
+
id=REXML::XPath.first(doc,"./id")
|
43
|
+
@id=id.text if id
|
44
|
+
REXML::XPath.each(doc,"./db:attribute") do |attr|
|
45
|
+
@attribute||={}
|
46
|
+
@attribute[attr.attributes['name']]=attr.text
|
47
|
+
end
|
48
|
+
content=REXML::XPath.first(doc,"./content")
|
49
|
+
@content=content.text if content
|
50
|
+
summary=REXML::XPath.first(doc,"./summary")
|
51
|
+
@summary=summary.text if summary
|
52
|
+
author=REXML::XPath.first(doc,"./author")
|
53
|
+
@author=Author.new(author.to_s) if author
|
54
|
+
end
|
55
|
+
|
56
|
+
def note_id
|
57
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
require 'douban/equal'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class People
|
7
|
+
include Douban::Equal
|
8
|
+
class << self
|
9
|
+
def attr_names
|
10
|
+
[
|
11
|
+
:id,
|
12
|
+
:location,
|
13
|
+
:title,
|
14
|
+
:link,
|
15
|
+
:content,
|
16
|
+
:uid
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
attr_names.each do |attr|
|
21
|
+
attr_accessor attr
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(atom="")
|
25
|
+
doc = case atom
|
26
|
+
when REXML::Document then atom.root
|
27
|
+
when REXML::Element then atom
|
28
|
+
else REXML::Document.new(atom).root
|
29
|
+
end
|
30
|
+
|
31
|
+
id=REXML::XPath.first(doc,"./id")
|
32
|
+
@id=id.text if id
|
33
|
+
content=REXML::XPath.first(doc,"./content")
|
34
|
+
@content=content.text if content
|
35
|
+
title=REXML::XPath.first(doc,"./title")
|
36
|
+
@title=title.text if title
|
37
|
+
location=REXML::XPath.first(doc,"./db:location")
|
38
|
+
@location=location.text if location
|
39
|
+
uid=REXML::XPath.first(doc,"./db:uid")
|
40
|
+
@uid=uid.text if uid
|
41
|
+
REXML::XPath.each(doc,"./link") do|link|
|
42
|
+
@link||={}
|
43
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/author'
|
3
|
+
require 'douban/equal'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class Recommendation
|
7
|
+
include Douban::Equal
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def attr_names
|
11
|
+
@@attr_names ||= %w(id title author published content content_type category comment comments_count).map {|x| x.to_sym}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_names.each do |attr|
|
16
|
+
attr_accessor attr
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(entry="")
|
20
|
+
if entry.kind_of? REXML::Element
|
21
|
+
doc = entry
|
22
|
+
else
|
23
|
+
doc = REXML::Document.new(entry)
|
24
|
+
end
|
25
|
+
|
26
|
+
@id = REXML::XPath.first(doc, ".//id/text()").to_s
|
27
|
+
|
28
|
+
@title = REXML::XPath.first(doc, ".//title/text()").to_s
|
29
|
+
|
30
|
+
@author = REXML::XPath.first(doc, ".//author")
|
31
|
+
@author = Author.new(@author.to_s) if @author
|
32
|
+
|
33
|
+
@published = REXML::XPath.first(doc, ".//published/text()").to_s
|
34
|
+
|
35
|
+
@content = REXML::XPath.first(doc, ".//content/text()").to_s
|
36
|
+
@content_type = REXML::XPath.first(doc, ".//content/@type").value() rescue nil
|
37
|
+
|
38
|
+
@category = REXML::XPath.first(doc, ".//db:attribute[@name='category']/text()").to_s
|
39
|
+
@comment = REXML::XPath.first(doc, ".//db:attribute[@name='comment']/text()").to_s
|
40
|
+
@comments_count = REXML::XPath.first(doc, ".//db:attribute[@name='comment_count']/text()").to_i rescue 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def recommendation_id
|
44
|
+
%r{/(\d+)$}.match(@id)[1].to_i rescue nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'douban/author'
|
2
|
+
require 'douban/equal'
|
3
|
+
|
4
|
+
module Douban
|
5
|
+
class RecommendationComment
|
6
|
+
include Douban::Equal
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def attr_names
|
10
|
+
@@attr_names ||= %w{id author published content}.map {|x| x.to_sym}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_names.each do |x|
|
15
|
+
attr_accessor x
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(entry="")
|
19
|
+
doc = entry.kind_of?(REXML::Element) ? entry : REXML::Document.new(entry)
|
20
|
+
@id = REXML::XPath.first(doc, ".//id/text()").to_s
|
21
|
+
@author = REXML::XPath.first(doc, ".//author")
|
22
|
+
@author = Author.new(@author.to_s) if @author
|
23
|
+
@published = REXML::XPath.first(doc, ".//published/text()").to_s
|
24
|
+
@content = REXML::XPath.first(doc, ".//content/text()").to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def recommendation_id
|
28
|
+
/recommendation\/(\d+)\/comment/.match(@id)[1].to_i rescue nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def comment_id
|
32
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|