module Douban::Cite

Constants

Douban_API_base
Douban_Book_info
VERSION

Public Instance Methods

convert_to_ref(book_info, book_type='M') click to toggle source

Format: author. YYYY-MM. title. other_author. location: publisher. ISBN isbn-number This format is based on:

@param [Hash] @return [String]

# File lib/douban/cite.rb, line 40
def convert_to_ref(book_info, book_type='M')
  author = book_info['author'].join(', ')
  year_month = book_info['pubdate']
  title = book_info['title']
  other_author = book_info['translator'].join(', ')
  publisher = book_info['publisher']
  # This is a silly guess.
  # TODO email douban to complain about this.
  location = publisher[0..1]
  isbn = book_info['isbn13']
  # `other_author` is handled specially, because often it is not needed.
  "#{author}. #{year_month}. #{title}[#{book_type}]. #{other_author == '' ? '' : other_author + '. ' }#{location}: #{publisher}. ISBN #{isbn}"
end
get_book_info(id) click to toggle source

@param [String] id isbn or douban subject id @return [Hash] book info if success @return [String] response http code if something is wrong

# File lib/douban/cite.rb, line 18
def get_book_info(id)
  # Currently douban subject id's length is 7.
  if StdNum::ISBN.valid?(id)
    id = 'isbn/' + id
  end
  res = RestClient.get(Douban_Book_info + id)
  if res.code == 200
    JSON.parse(res.body)
  else
    res.code
  end
end