douban-cite 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/bin/douban-cite +7 -0
- data/douban-cite.gemspec +31 -0
- data/lib/douban/cite.rb +54 -0
- data/lib/douban/cite/version.rb +5 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ab70768a5a9caccb90896fc70096a639c81bd00
|
4
|
+
data.tar.gz: 76527535b53d7e2e5cd2ff00bee483f7d368761a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6293790559629e9aa67710a983f9f0d255f9ec1dd2aa9e08320de5e0a7f0d7f47edacd55fcfbffa67b1cad943a4133ba554ba016d5eae7c2c8f5fb1082436c87
|
7
|
+
data.tar.gz: bcff9813f627f4a5e0bfb6aef2c3ae2c5b64dceac39b4327201b7339242fc7e0394e175b8266e446d32ae445ccf5de7495ab98ec72ec5dd17d8975a6a6b33786
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jakukyo Friel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# douban-cite
|
2
|
+
|
3
|
+
A book reference generator. Book information is fetched from [douban](http://www.douban.com).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install douban-cite
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```sh
|
12
|
+
douban-cite ISBN_OR_DOUBAN_ID
|
13
|
+
```
|
14
|
+
|
15
|
+
### Example
|
16
|
+
|
17
|
+
```sh
|
18
|
+
; douban-cite 9780262560993
|
19
|
+
Daniel P. Friedman, Matthias Felleisen. 1995-12-21. The Little Schemer - 4th Edition[M]. Th: The MIT Press. ISBN 9780262560993
|
20
|
+
```
|
21
|
+
|
22
|
+
Note that the output is meant for manual editing afterwards, since Douban does not provide revision and publisher location.
|
23
|
+
|
24
|
+
For example, there are two issues in the above example:
|
25
|
+
|
26
|
+
`The Little Schemer - 4th Edition[M].` should be:
|
27
|
+
|
28
|
+
|
29
|
+
The Little Schemer[M]. 4th Edition.
|
30
|
+
|
31
|
+
And `Th: The MIT Press.` should be:
|
32
|
+
|
33
|
+
Cambridge, MA: MIT Press
|
34
|
+
|
35
|
+
(`Th` is a silly guess, which may be useful for some Chinese publisher.)
|
36
|
+
|
37
|
+
|
38
|
+
### As a library
|
39
|
+
|
40
|
+
You can also use it as a library:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'douban-cite'
|
44
|
+
|
45
|
+
Douban::Cite.convert_to_ref(Douban::Cite.get_book_info(id))
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/weakish/douban-cite/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/douban-cite
ADDED
data/douban-cite.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'douban/cite/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'douban-cite'
|
8
|
+
spec.version = Douban::Cite::VERSION
|
9
|
+
spec.authors = ['Jakukyo Friel']
|
10
|
+
spec.email = ['weakish@gmail.com']
|
11
|
+
spec.summary = %q{Generate book reference based on douban.}
|
12
|
+
spec.description = %q{A book reference generator. Book information is fetched from [douban](http://www.douban.com).}
|
13
|
+
spec.homepage = 'https://github.com/weakish/douban-cite/'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.metadata = {
|
16
|
+
'repository' => 'https://github.com/weakish/douban-cite.git',
|
17
|
+
'documentation' => 'http://www.rubydoc.info/gems/douban-cite/',
|
18
|
+
'issues' => 'https://github.com/weakish/douban-cite/issues',
|
19
|
+
'wiki' => 'https://github.com/weakish/ouban-cite/wiki',
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0")
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'library_stdnums', '~> 1.4'
|
28
|
+
spec.add_runtime_dependency 'rest_client', '~> 1.8'
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
end
|
data/lib/douban/cite.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'douban/cite/version'
|
2
|
+
|
3
|
+
require 'library_stdnums'
|
4
|
+
require 'json'
|
5
|
+
require 'rest_client'
|
6
|
+
|
7
|
+
|
8
|
+
module Douban
|
9
|
+
module Cite
|
10
|
+
Douban_API_base = 'http://api.douban.com'
|
11
|
+
Douban_Book_info = Douban_API_base + '/v2/book/'
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
# @param [String] id isbn or douban subject id
|
16
|
+
# @return [Hash] book info if success
|
17
|
+
# @return [String] response http code if something is wrong
|
18
|
+
def get_book_info(id)
|
19
|
+
# Currently douban subject id's length is 7.
|
20
|
+
if StdNum::ISBN.valid?(id)
|
21
|
+
id = 'isbn/' + id
|
22
|
+
end
|
23
|
+
res = RestClient.get(Douban_Book_info + id)
|
24
|
+
if res.code == 200
|
25
|
+
JSON.parse(res.body)
|
26
|
+
else
|
27
|
+
res.code
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Format:
|
32
|
+
# author. YYYY-MM. title[type]. other_author. location: publisher. ISBN isbn-number
|
33
|
+
# This format is based on:
|
34
|
+
# - [GB 7714-2005《文后参考文献著录规则》](http://gradschool.ustc.edu.cn/ylb/material/xw/wdxz/19.pdf)
|
35
|
+
# - [维基百科:列明来源](http://zh.wikipedia.org/wiki/Wikipedia:%E5%88%97%E6%98%8E%E6%9D%A5%E6%BA%90)
|
36
|
+
# - [Harvard referencing](http://en.wikipedia.org/wiki/Parenthetical_referencing)
|
37
|
+
#
|
38
|
+
# @param [Hash]
|
39
|
+
# @return [String]
|
40
|
+
def convert_to_ref(book_info, book_type='M')
|
41
|
+
author = book_info['author'].join(', ')
|
42
|
+
year_month = book_info['pubdate']
|
43
|
+
title = book_info['title']
|
44
|
+
other_author = book_info['translator'].join(', ')
|
45
|
+
publisher = book_info['publisher']
|
46
|
+
# This is a silly guess.
|
47
|
+
# TODO email douban to complain about this.
|
48
|
+
location = publisher[0..1]
|
49
|
+
isbn = book_info['isbn13']
|
50
|
+
# `other_author` is handled specially, because often it is not needed.
|
51
|
+
"#{author}. #{year_month}. #{title}[#{book_type}]. #{other_author == '' ? '' : other_author + '. ' }#{location}: #{publisher}. ISBN #{isbn}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: douban-cite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakukyo Friel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: library_stdnums
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest_client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A book reference generator. Book information is fetched from [douban](http://www.douban.com).
|
70
|
+
email:
|
71
|
+
- weakish@gmail.com
|
72
|
+
executables:
|
73
|
+
- douban-cite
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/douban-cite
|
83
|
+
- douban-cite.gemspec
|
84
|
+
- lib/douban/cite.rb
|
85
|
+
- lib/douban/cite/version.rb
|
86
|
+
homepage: https://github.com/weakish/douban-cite/
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata:
|
90
|
+
repository: https://github.com/weakish/douban-cite.git
|
91
|
+
documentation: http://www.rubydoc.info/gems/douban-cite/
|
92
|
+
issues: https://github.com/weakish/douban-cite/issues
|
93
|
+
wiki: https://github.com/weakish/ouban-cite/wiki
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Generate book reference based on douban.
|
114
|
+
test_files: []
|
115
|
+
has_rdoc:
|