douban-ruby 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile.lock +12 -11
- data/History.rdoc +4 -0
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/douban-ruby.gemspec +1 -0
- data/lib/douban.rb +58 -58
- data/lib/douban/authorize.rb +1400 -1369
- data/lib/douban/collection.rb +69 -69
- data/lib/douban/event.rb +80 -80
- data/lib/douban/miniblog.rb +63 -63
- data/lib/douban/note.rb +60 -60
- data/lib/douban/people.rb +48 -48
- data/lib/douban/review.rb +66 -66
- data/lib/douban/subject.rb +119 -119
- data/lib/douban/version.rb +1 -1
- data/spec/douban/authorize_spec.rb +36 -5
- metadata +19 -4
data/lib/douban/people.rb
CHANGED
@@ -1,48 +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
|
-
|
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
|
+
|
data/lib/douban/review.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'douban/subject'
|
3
|
-
require 'douban/author'
|
4
|
-
require 'douban/equal'
|
5
|
-
|
6
|
-
module Douban
|
7
|
-
class Review
|
8
|
-
include Douban::Equal
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def attr_names
|
12
|
-
[
|
13
|
-
:updated,
|
14
|
-
:subject,
|
15
|
-
:author,
|
16
|
-
:title,
|
17
|
-
:summary,
|
18
|
-
:link,
|
19
|
-
:id,
|
20
|
-
:rating,
|
21
|
-
:published,
|
22
|
-
:content
|
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
|
41
|
-
updated=REXML::XPath.first(doc,"./updated")
|
42
|
-
@updated=updated.text if updated
|
43
|
-
@published=REXML::XPath.first(doc,"./published/text()").to_s
|
44
|
-
summary=REXML::XPath.first(doc,"./summary")
|
45
|
-
@summary=summary.text if summary
|
46
|
-
@content = REXML::XPath.first(doc, "./content/text()").to_s
|
47
|
-
REXML::XPath.each(doc,"./link") do |link|
|
48
|
-
@link||={}
|
49
|
-
@link[link.attributes['rel']]=link.attributes['href']
|
50
|
-
end
|
51
|
-
id=REXML::XPath.first(doc,"./id")
|
52
|
-
@id=id.text if id
|
53
|
-
rating=REXML::XPath.first(doc,"./gd:rating")
|
54
|
-
if rating
|
55
|
-
@rating={}
|
56
|
-
@rating['min']=rating.attributes['min']
|
57
|
-
@rating['value']=rating.attributes['value']
|
58
|
-
@rating['max']=rating.attributes['max']
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def review_id
|
63
|
-
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/subject'
|
3
|
+
require 'douban/author'
|
4
|
+
require 'douban/equal'
|
5
|
+
|
6
|
+
module Douban
|
7
|
+
class Review
|
8
|
+
include Douban::Equal
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def attr_names
|
12
|
+
[
|
13
|
+
:updated,
|
14
|
+
:subject,
|
15
|
+
:author,
|
16
|
+
:title,
|
17
|
+
:summary,
|
18
|
+
:link,
|
19
|
+
:id,
|
20
|
+
:rating,
|
21
|
+
:published,
|
22
|
+
:content
|
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
|
41
|
+
updated=REXML::XPath.first(doc,"./updated")
|
42
|
+
@updated=updated.text if updated
|
43
|
+
@published=REXML::XPath.first(doc,"./published/text()").to_s
|
44
|
+
summary=REXML::XPath.first(doc,"./summary")
|
45
|
+
@summary=summary.text if summary
|
46
|
+
@content = REXML::XPath.first(doc, "./content/text()").to_s
|
47
|
+
REXML::XPath.each(doc,"./link") do |link|
|
48
|
+
@link||={}
|
49
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
50
|
+
end
|
51
|
+
id=REXML::XPath.first(doc,"./id")
|
52
|
+
@id=id.text if id
|
53
|
+
rating=REXML::XPath.first(doc,"./gd:rating")
|
54
|
+
if rating
|
55
|
+
@rating={}
|
56
|
+
@rating['min']=rating.attributes['min']
|
57
|
+
@rating['value']=rating.attributes['value']
|
58
|
+
@rating['max']=rating.attributes['max']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def review_id
|
63
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/douban/subject.rb
CHANGED
@@ -1,119 +1,119 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'douban/tag'
|
3
|
-
require 'douban/author'
|
4
|
-
require 'douban/equal'
|
5
|
-
|
6
|
-
module Douban
|
7
|
-
class Subject
|
8
|
-
include Douban::Equal
|
9
|
-
class << self
|
10
|
-
def attr_names
|
11
|
-
[
|
12
|
-
:id,
|
13
|
-
:title,
|
14
|
-
:category,
|
15
|
-
:author,
|
16
|
-
:link,
|
17
|
-
:summary,
|
18
|
-
:attribute,
|
19
|
-
:tag,
|
20
|
-
:rating
|
21
|
-
]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
attr_names.each do |attr|
|
25
|
-
attr_accessor attr
|
26
|
-
end
|
27
|
-
def initialize(atom='')
|
28
|
-
doc = case atom
|
29
|
-
when REXML::Document then atom.root
|
30
|
-
when REXML::Element then atom
|
31
|
-
when nil then nil
|
32
|
-
else REXML::Document.new(atom).root
|
33
|
-
end
|
34
|
-
|
35
|
-
id=REXML::XPath.first(doc,"./id")
|
36
|
-
@id=id.text if id
|
37
|
-
title=REXML::XPath.first(doc,"./title")
|
38
|
-
@title=title.text if title
|
39
|
-
@category={}
|
40
|
-
category=REXML::XPath.first(doc,"./category")
|
41
|
-
@category['term']=category.attributes['term'] if category
|
42
|
-
@category['scheme']=category.attributes['scheme'] if category
|
43
|
-
REXML::XPath.each(doc,"./db:tag") do |tag|
|
44
|
-
@tag||=[]
|
45
|
-
t=Tag.new
|
46
|
-
t.title=tag.attributes['name']
|
47
|
-
t.count=tag.attributes['count']
|
48
|
-
@tag<< t
|
49
|
-
end
|
50
|
-
@author||=Author.new
|
51
|
-
name=REXML::XPath.first(doc,"./author/name")
|
52
|
-
@author.name=name.text if name
|
53
|
-
uri=REXML::XPath.first(doc,"./author/uri")
|
54
|
-
@author.uri=uri.text if uri
|
55
|
-
REXML::XPath.each(doc,"./author/link") do |link|
|
56
|
-
@author.link||={}
|
57
|
-
@author.link[link.attributes['rel']]=link.attributes['href']
|
58
|
-
end
|
59
|
-
summary=REXML::XPath.first(doc,"./summary")
|
60
|
-
@summary=summary.text if summary
|
61
|
-
REXML::XPath.each(doc,"./link") do |link|
|
62
|
-
@link||={}
|
63
|
-
@link[link.attributes['rel']]=link.attributes['href']
|
64
|
-
end
|
65
|
-
REXML::XPath.each(doc,"./db:attribute") do |attribute|
|
66
|
-
@attribute||={}
|
67
|
-
@attribute[attribute.attributes['name']]=attribute.text
|
68
|
-
end
|
69
|
-
@rating={}
|
70
|
-
rating=REXML::XPath.first(doc,"./gd:rating")
|
71
|
-
if rating
|
72
|
-
@rating['min']=rating.attributes['min']
|
73
|
-
@rating['numRaters']=rating.attributes['numRaters']
|
74
|
-
@rating['average']=rating.attributes['average']
|
75
|
-
@rating['max']=rating.attributes['max']
|
76
|
-
end
|
77
|
-
end #initialize
|
78
|
-
|
79
|
-
def subject_id
|
80
|
-
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
81
|
-
end
|
82
|
-
|
83
|
-
end # class Subject
|
84
|
-
|
85
|
-
class Movie<Subject
|
86
|
-
def initialize(atom)
|
87
|
-
super(atom)
|
88
|
-
end
|
89
|
-
|
90
|
-
def imdb
|
91
|
-
/(tt\d+)\/$/.match(@attribute["imdb"])[1] rescue nil
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class Book<Subject
|
96
|
-
def initialize(atom)
|
97
|
-
super(atom)
|
98
|
-
end
|
99
|
-
|
100
|
-
def isbn10
|
101
|
-
@attribute["isbn10"] rescue nil
|
102
|
-
end
|
103
|
-
|
104
|
-
def isbn13
|
105
|
-
@attribute["isbn13"] rescue nil
|
106
|
-
end
|
107
|
-
|
108
|
-
def isbn
|
109
|
-
isbn13 ? isbn13 : isbn10
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class Music<Subject
|
114
|
-
def initialize(atom)
|
115
|
-
super(atom)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/tag'
|
3
|
+
require 'douban/author'
|
4
|
+
require 'douban/equal'
|
5
|
+
|
6
|
+
module Douban
|
7
|
+
class Subject
|
8
|
+
include Douban::Equal
|
9
|
+
class << self
|
10
|
+
def attr_names
|
11
|
+
[
|
12
|
+
:id,
|
13
|
+
:title,
|
14
|
+
:category,
|
15
|
+
:author,
|
16
|
+
:link,
|
17
|
+
:summary,
|
18
|
+
:attribute,
|
19
|
+
:tag,
|
20
|
+
:rating
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
attr_names.each do |attr|
|
25
|
+
attr_accessor attr
|
26
|
+
end
|
27
|
+
def initialize(atom='')
|
28
|
+
doc = case atom
|
29
|
+
when REXML::Document then atom.root
|
30
|
+
when REXML::Element then atom
|
31
|
+
when nil then nil
|
32
|
+
else REXML::Document.new(atom).root
|
33
|
+
end
|
34
|
+
|
35
|
+
id=REXML::XPath.first(doc,"./id")
|
36
|
+
@id=id.text if id
|
37
|
+
title=REXML::XPath.first(doc,"./title")
|
38
|
+
@title=title.text if title
|
39
|
+
@category={}
|
40
|
+
category=REXML::XPath.first(doc,"./category")
|
41
|
+
@category['term']=category.attributes['term'] if category
|
42
|
+
@category['scheme']=category.attributes['scheme'] if category
|
43
|
+
REXML::XPath.each(doc,"./db:tag") do |tag|
|
44
|
+
@tag||=[]
|
45
|
+
t=Tag.new
|
46
|
+
t.title=tag.attributes['name']
|
47
|
+
t.count=tag.attributes['count']
|
48
|
+
@tag<< t
|
49
|
+
end
|
50
|
+
@author||=Author.new
|
51
|
+
name=REXML::XPath.first(doc,"./author/name")
|
52
|
+
@author.name=name.text if name
|
53
|
+
uri=REXML::XPath.first(doc,"./author/uri")
|
54
|
+
@author.uri=uri.text if uri
|
55
|
+
REXML::XPath.each(doc,"./author/link") do |link|
|
56
|
+
@author.link||={}
|
57
|
+
@author.link[link.attributes['rel']]=link.attributes['href']
|
58
|
+
end
|
59
|
+
summary=REXML::XPath.first(doc,"./summary")
|
60
|
+
@summary=summary.text if summary
|
61
|
+
REXML::XPath.each(doc,"./link") do |link|
|
62
|
+
@link||={}
|
63
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
64
|
+
end
|
65
|
+
REXML::XPath.each(doc,"./db:attribute") do |attribute|
|
66
|
+
@attribute||={}
|
67
|
+
@attribute[attribute.attributes['name']]=attribute.text
|
68
|
+
end
|
69
|
+
@rating={}
|
70
|
+
rating=REXML::XPath.first(doc,"./gd:rating")
|
71
|
+
if rating
|
72
|
+
@rating['min']=rating.attributes['min']
|
73
|
+
@rating['numRaters']=rating.attributes['numRaters']
|
74
|
+
@rating['average']=rating.attributes['average']
|
75
|
+
@rating['max']=rating.attributes['max']
|
76
|
+
end
|
77
|
+
end #initialize
|
78
|
+
|
79
|
+
def subject_id
|
80
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
81
|
+
end
|
82
|
+
|
83
|
+
end # class Subject
|
84
|
+
|
85
|
+
class Movie<Subject
|
86
|
+
def initialize(atom)
|
87
|
+
super(atom)
|
88
|
+
end
|
89
|
+
|
90
|
+
def imdb
|
91
|
+
/(tt\d+)\/$/.match(@attribute["imdb"])[1] rescue nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class Book<Subject
|
96
|
+
def initialize(atom)
|
97
|
+
super(atom)
|
98
|
+
end
|
99
|
+
|
100
|
+
def isbn10
|
101
|
+
@attribute["isbn10"] rescue nil
|
102
|
+
end
|
103
|
+
|
104
|
+
def isbn13
|
105
|
+
@attribute["isbn13"] rescue nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def isbn
|
109
|
+
isbn13 ? isbn13 : isbn10
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Music<Subject
|
114
|
+
def initialize(atom)
|
115
|
+
super(atom)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|