doubapi 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/doubapi/version.rb +1 -1
- data/lib/doubapi.rb +20 -6
- data/lib/test.rb +2 -0
- metadata +1 -1
data/lib/doubapi/version.rb
CHANGED
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').
|
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