mini-douban 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,16 +18,24 @@ Or install it yourself as:
18
18
 
19
19
  ## Requirement
20
20
 
21
- gem install xmlsimple
21
+ gem install xml-simple
22
22
 
23
23
  ## Example
24
24
 
25
25
  require 'mini/douban'
26
26
  Mini::Douban.book_api :id=>3420144
27
27
 
28
- 参数格式大致为{:id=>3420144, :isbn=>'9781430218333', original=>false}.其中Id 和ISBN至少一个,Id优先.original默认为false,可以不填.
28
+ 参数格式大致为
29
29
 
30
- 具体含义:id表示豆瓣对应的图书id;isbn表示对应豆瓣图书的isbn编号(10或13位即可);original表示是否显示原本信息.
30
+ {:id=>3420144, :isbn=>'9781430218333', original=>false}.
31
+
32
+ 其中Id 和ISBN至少有一个.Id优先.original默认为false,可以不填.
33
+
34
+ 具体含义:
35
+ * id表示豆瓣对应的图书id;
36
+ * isbn表示对应豆瓣图书的isbn编号(10或13位即可);
37
+ * original表示是否显示原本信息.
38
+ * 由于获取的原本图片尺寸太小,如果需要较大的尺寸可以将原本的作稍微修改,例如:[:image_url].gsub('spic','mpic')
31
39
 
32
40
 
33
41
 
data/lib/mini/douban.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "mini/douban/version"
2
- require 'xmlsimple'
2
+ require 'json'
3
3
  require 'net/http'
4
4
 
5
5
  module Mini
@@ -17,23 +17,23 @@ module Mini
17
17
  opts = opts.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
18
18
 
19
19
  if opts[:id]
20
- book_with_xml = Net::HTTP.get_response(URI.parse(BOOK_API_WITH_ID + opts[:id].to_s)).body
20
+ book_with_json = Net::HTTP.get_response(URI.parse(BOOK_API_WITH_ID + opts[:id].to_s + '?alt=json')).body
21
21
  elsif opts[:isbn]
22
- book_with_xml = Net::HTTP.get_response(URI.parse(BOOK_API_WITH_ISBN + opts[:isbn].to_s)).body
22
+ book_with_json = Net::HTTP.get_response(URI.parse(BOOK_API_WITH_ISBN + opts[:isbn].to_s + '?alt=json')).body
23
23
  else
24
24
  return 'input options lack id or isbn'
25
25
  end
26
26
 
27
- hash_book = XmlSimple.xml_in(book_with_xml)
27
+ hash_book = JSON.parse(book_with_json)
28
28
 
29
- if hash_book.include?('attribute') and opts[:original] != true
29
+ if hash_book.include?('db:attribute') and opts[:original] != true
30
30
  sample_book = {}
31
- hash_book['attribute'].map{|attr| sample_book[attr['name']] = attr['content']}
32
- sample_book['tags'] = hash_book['tag'].map{ |tag| tag['name'] } if hash_book['tag']
33
- sample_book['summary'] = hash_book['summary'].join if hash_book['summary']
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']
31
+ hash_book['db:attribute'].map{|attr| sample_book[attr['@name']] = attr['$t']}
32
+ sample_book['tags'] = hash_book['db:tag'].map{ |tag| tag['@name'] } if hash_book['db:tag']
33
+ sample_book['summary'] = hash_book['summary']['$t'] if hash_book['summary']
34
+ sample_book['links'] = hash_book['link'].map{ |m| m['@href']} if hash_book['link']
35
+ sample_book['rating'] = hash_book['gd:rating']['@average'] if hash_book['gd:rating']
36
+ sample_book['rater_number'] = hash_book['gd:rating']['@numRaters'] if hash_book['gd:rating']
37
37
  if sample_book['links']
38
38
  sample_book['image_url'] = sample_book['links'].select{ |s| s.start_with?('http://img')}.join
39
39
  sample_book['api_url'] = sample_book['links'].select{ |s| s.start_with?('http://api')}.join
@@ -1,5 +1,5 @@
1
1
  module Mini
2
2
  module Douban
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini-douban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2013-05-18 00:00:00.000000000 Z
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler