mini-douban 0.0.2 → 0.0.3
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/README.md +15 -0
- data/lib/mini/douban.rb +3 -1
- data/lib/mini/douban/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -16,6 +16,21 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install mini-douban
|
18
18
|
|
19
|
+
## Requirement
|
20
|
+
|
21
|
+
gem install xmlsimple
|
22
|
+
|
23
|
+
## Example
|
24
|
+
|
25
|
+
require 'mini/douban'
|
26
|
+
Mini::Douban.book_api :id=>3420144
|
27
|
+
|
28
|
+
参数格式大致为{:id=>3420144, :isbn=>'9781430218333', original=>false}.其中Id 和ISBN至少一个,Id优先.original默认为false,可以不填.
|
29
|
+
|
30
|
+
具体含义:id表示豆瓣对应的图书id;isbn表示对应豆瓣图书的isbn编号(10或13位即可);original表示是否显示原本信息.
|
31
|
+
|
32
|
+
|
33
|
+
|
19
34
|
## Usage
|
20
35
|
|
21
36
|
TODO: Write usage instructions here
|
data/lib/mini/douban.rb
CHANGED
@@ -32,13 +32,15 @@ module Mini
|
|
32
32
|
sample_book['tags'] = hash_book['tag'].map{ |tag| tag['name'] } if hash_book['tag']
|
33
33
|
sample_book['summary'] = hash_book['summary'].join if hash_book['summary']
|
34
34
|
sample_book['links'] = hash_book['link'].map{ |m| m['href']} if hash_book['link']
|
35
|
+
sample_book['rating'] = hash_book['rating'].first['average'] if hash_book['rating']
|
36
|
+
sample_book['rater_number'] = hash_book['rating'].first['numRaters'] if hash_book['rating']
|
35
37
|
if sample_book['links']
|
36
38
|
sample_book['image_url'] = sample_book['links'].select{ |s| s.start_with?('http://img')}.join
|
37
39
|
sample_book['api_url'] = sample_book['links'].select{ |s| s.start_with?('http://api')}.join
|
38
40
|
sample_book['mobile_url'] = sample_book['links'].select{ |s| s.start_with?('http://m')}.join
|
39
41
|
sample_book['website_url'] = sample_book['links'].select{ |s| s.start_with?('http://book')}.join
|
40
42
|
end
|
41
|
-
return sample_book
|
43
|
+
return sample_book.inject({}){|book_info,(k,v)| book_info[k.to_sym] = v; book_info}
|
42
44
|
end
|
43
45
|
hash_book
|
44
46
|
end
|
data/lib/mini/douban/version.rb
CHANGED