doubapi 0.0.4 → 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/lib/doubapi/version.rb +1 -1
- data/lib/doubapi.rb +17 -4
- data/spec/doubapi_spec.rb +16 -2
- metadata +3 -3
data/lib/doubapi/version.rb
CHANGED
data/lib/doubapi.rb
CHANGED
@@ -39,6 +39,9 @@ def self.search_ablum artist_chinese ,max=10
|
|
39
39
|
end
|
40
40
|
|
41
41
|
Douban_Event = Struct.new :title, :when, :where, :what, :link
|
42
|
+
|
43
|
+
#
|
44
|
+
#release_date is in the format of YY-MM-DD
|
42
45
|
Douban_Album = Struct.new :author, :title, :release_date, :link
|
43
46
|
|
44
47
|
|
@@ -66,13 +69,17 @@ def self.compare_date a , b
|
|
66
69
|
return true if (ya.to_i * 12 + ma.to_i ) >= (yb.to_i*12+mb.to_i)
|
67
70
|
end
|
68
71
|
|
69
|
-
def self.
|
72
|
+
def self.search_albums_of artist , after_date = "1900.01"
|
70
73
|
doc = search_ablum artist
|
71
74
|
albums=[]
|
72
75
|
|
73
76
|
doc.xpath("//entry").each do |entry|
|
74
77
|
title = entry.at_xpath(".//title").text
|
75
|
-
author = entry.at_xpath(".//name").
|
78
|
+
author = unless entry.at_xpath(".//name").nil?
|
79
|
+
entry.at_xpath(".//name").text
|
80
|
+
else
|
81
|
+
"unknown(#{artist}?)"
|
82
|
+
end
|
76
83
|
release_date = unless entry.at_xpath(".//attribute[@name='pubdate']").nil?
|
77
84
|
entry.at_xpath(".//attribute[@name='pubdate']").text
|
78
85
|
else
|
@@ -80,10 +87,16 @@ def self.search_album_of artist , after_date = "1900.01"
|
|
80
87
|
"0000-00"
|
81
88
|
end
|
82
89
|
link = entry.at_xpath(".//link[@rel='alternate']")["href"]
|
83
|
-
|
90
|
+
|
91
|
+
#make release data YY-MM-DD style
|
92
|
+
r = release_date.scan(/\d{1,4}/)
|
93
|
+
#if DD was not specified
|
94
|
+
r << "01" if r.size == 2
|
95
|
+
r << "01" << "01" if r.size == 1
|
96
|
+
formated_release_day = "#{r[0]}-#{r[1]}-#{r[2]}"
|
84
97
|
#check the release date
|
85
98
|
if compare_date release_date, after_date
|
86
|
-
albums << Douban_Album.new(author, title,
|
99
|
+
albums << Douban_Album.new(author, title, formated_release_day, link)
|
87
100
|
end
|
88
101
|
end
|
89
102
|
albums
|
data/spec/doubapi_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Doubapi do
|
|
14
14
|
|
15
15
|
it "should be able to search albums of 李志 " do
|
16
16
|
author = "李志"
|
17
|
-
Doubapi.
|
17
|
+
Doubapi.search_albums_of(author).each do |album|
|
18
18
|
puts album.author
|
19
19
|
puts album.release_date
|
20
20
|
puts album.title
|
@@ -24,12 +24,26 @@ describe Doubapi do
|
|
24
24
|
|
25
25
|
it "should be able to search albums of 李志 that released after 2010 " do
|
26
26
|
author = "李志"
|
27
|
-
Doubapi.
|
27
|
+
Doubapi.search_albums_of(author, "2010-05").each do |album|
|
28
|
+
puts album.author
|
29
|
+
puts album.release_date
|
30
|
+
puts album.title
|
31
|
+
puts album.link
|
32
|
+
|
33
|
+
album.release_date.should >= "2010-05"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it "should be handle the search results that have no author node" do
|
39
|
+
author = "何勇"
|
40
|
+
Doubapi.search_albums_of(author, "2010/01").each do |album|
|
28
41
|
puts album.author
|
29
42
|
puts album.release_date
|
30
43
|
puts album.title
|
31
44
|
puts album.link
|
32
45
|
end
|
46
|
+
|
33
47
|
end
|
34
48
|
|
35
49
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doubapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pierr chen
|