doubapi 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Doubapi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/doubapi.rb CHANGED
@@ -21,7 +21,7 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #
23
23
 
24
- require 'RUBYgems' #a hack to require failure for nokogiri
24
+ require 'rubygems' #a hack to require failure for nokogiri
25
25
  require 'open-uri'
26
26
  require 'nokogiri'
27
27
  require 'pp'
@@ -41,7 +41,7 @@ module Doubapi
41
41
  #use Douban API
42
42
  Event = Struct.new :title, :when, :where, :what,:link,:poster_mobile,:bar_icon
43
43
  #release_date is in the format of YY-MM-DD
44
- Album = Struct.new :author, :title, :release_date, :link,:cover_thumbnail,:cover_big,:publisher,:mobile_site
44
+ Album = Struct.new :author, :title, :release_date, :link,:cover_thumbnail,:cover_big,:publisher,:mobile_site,:rating
45
45
 
46
46
  #input:{key => "all/singer_name", :location => "shanghai", :start_index => 16,:max_result => 15}
47
47
  #return total number of events satisfying the search criterion
@@ -211,6 +211,9 @@ def search_albums_of h
211
211
  #publisher
212
212
  pubItem = entry.at_xpath(".//attribute[@name='publisher']")
213
213
  publisher = if pubItem.nil? then "unknow" else pubItem.text end
214
+
215
+ #rating
216
+ rating = entry.at_xpath(".//rating")["average"]
214
217
  #link - mobile_site
215
218
  mobile_site = entry.at_xpath(".//link[@rel='mobile']")["href"]
216
219
  #release_date
@@ -219,7 +222,7 @@ def search_albums_of h
219
222
  formated_release_day = formate_release_date(release_date)
220
223
  #check the release date
221
224
  if compare_date release_date, after_date
222
- albums << Doubapi::Album.new(author, title, formated_release_day, link, cover_thumnail,cover_big ,publisher,mobile_site)
225
+ albums << Doubapi::Album.new(author, title, formated_release_day, link, cover_thumnail,cover_big ,publisher,mobile_site,rating)
223
226
  end
224
227
  end
225
228
  #improve ME
data/lib/test.rb CHANGED
@@ -18,8 +18,12 @@ end
18
18
 
19
19
 
20
20
  def test2
21
- author = "李志"
22
- Doubapi.search_albums_of(:singer=>author,:since=>"2010-05") do |album|
21
+ #author = "李志"
22
+ author = "窦唯"
23
+ total, albums = Doubapi.search_albums_of(:singer=>author,:since=>"1900-05",:max_result => 20)
24
+
25
+ #release date decending
26
+ albums.sort {|a , b| b.release_date <=> a.release_date }.each do |album|
23
27
  puts "-------------------------------"
24
28
  puts album.author
25
29
  puts album.release_date
@@ -28,7 +32,24 @@ def test2
28
32
  puts album.publisher
29
33
  puts album.link
30
34
  puts album.mobile_site
35
+ puts album.rating
31
36
  end
37
+
38
+ #rating decending
39
+
40
+ #release date decending
41
+ albums.sort {|a , b| b.rating <=> a.rating }.each do |album|
42
+ puts "-------------------------------"
43
+ puts album.author
44
+ puts album.release_date
45
+ puts album.title
46
+ puts album.cover_thumbnail
47
+ puts album.publisher
48
+ puts album.link
49
+ puts album.mobile_site
50
+ puts album.rating
51
+ end
52
+ puts "total #{total}"
32
53
  end
33
54
 
34
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doubapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-07-23 00:00:00.000000000 Z
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec