doubapi 0.1.4 → 0.1.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.
@@ -1,3 +1,3 @@
1
1
  module Doubapi
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/doubapi.rb CHANGED
@@ -37,14 +37,28 @@ require 'json'
37
37
  #at_xpath is to return single element and you know only there is only one element.
38
38
  #xpath is to return an array of elements
39
39
 
40
+ class Struct
41
+ def to_map
42
+ map = Hash.new
43
+ self.members.each { |m| map[m] = self[m] }
44
+ map
45
+ end
46
+
47
+ def to_json(*a)
48
+ to_map.to_json(*a)
49
+ end
50
+
51
+ def json
52
+ JSON.pretty_generate(self)
53
+ end
54
+ end
40
55
  module Doubapi
41
- #return a Nokogiri XML object
42
- #use Douban API
43
56
  Event = Struct.new :title, :when, :where, :what,:link,:poster_mobile,:bar_icon
57
+
44
58
  #release_date is in the format of YY-MM-DD
45
59
  Album = Struct.new :author, :title, :release_date, :link,:cover_thumbnail,:cover_big,:publisher,:mobile_site,:rating,:tracks
46
60
 
47
- Track = Struct.new :title
61
+ Track = Struct.new :title,:url
48
62
 
49
63
 
50
64
  #input:{key => "all/singer_name", :location => "shanghai", :start_index => 16,:max_result => 15}
@@ -206,11 +220,11 @@ def search_albums_of_v2 h
206
220
  formated_release_day = m["pubdate"].first
207
221
  link = mobile_site = item['mobile_link']
208
222
  cover_thumnail = cover_big = item['image']
209
- publisher = m['publisher']
223
+ publisher = m['publisher'].first
210
224
  rating = item['rating']['average']
211
225
  tracks=[]
212
- m['tracks'].first.split('\n').each do |t|
213
- tracks << Doubapi::Track.new(t)
226
+ m['tracks'].first.split('\n').each_with_index do |t,index|
227
+ tracks << Doubapi::Track.new(t,nil)
214
228
  end
215
229
 
216
230
  albums << Doubapi::Album.new(author, title, formated_release_day, link,
data/lib/test.rb CHANGED
@@ -37,6 +37,8 @@ def test2
37
37
  album.tracks.each do |track|
38
38
  puts track.title
39
39
  end
40
+
41
+ puts album.json
40
42
  end
41
43
 
42
44
  #rating decending
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.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: