bibsonomy 0.4.5 → 0.4.6
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 +4 -4
- data/README.md +25 -2
- data/bibsonomy.gemspec +3 -1
- data/lib/bibsonomy.rb +1 -0
- data/lib/bibsonomy/api.rb +38 -4
- data/lib/bibsonomy/csl.rb +36 -2
- data/lib/bibsonomy/post.rb +6 -1
- data/lib/bibsonomy/version.rb +1 -1
- data/test/csl_test.rb +21 -0
- data/test/post_test.rb +39 -4
- metadata +34 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a51a2bb7d05aefff235013de9cd8cab94ca6c8
|
4
|
+
data.tar.gz: a89cbb97919dbefb6ceb9c08cc8b9892509c0b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0a4005e5b141210c61fbc08a1a2961180c6e70b58cd3f68d3def639ffdf30361af41f944f13aa762e2f451ef803dff2100f23d3cae40fbb8ed8e9d2b26f420
|
7
|
+
data.tar.gz: dd70c37fddda3115fa62aaaddf383be4b0ec5201c3018417d6a73896f013e8ed82edf20f323b30e136338ab39a63ffe2b6664b3d32cd301b0f234d6322c6785c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BibSonomy
|
2
2
|
|
3
|
-
BibSonomy client for Ruby
|
3
|
+
[BibSonomy](http://www.bibsonomy.org/) client for Ruby
|
4
4
|
|
5
5
|
[](http://badge.fury.io/rb/bibsonomy)
|
6
6
|
[](https://travis-ci.org/rjoberon/bibsonomy-ruby)
|
@@ -49,6 +49,26 @@ require 'bibsonomy/csl'
|
|
49
49
|
print BibSonomy::main(ARGV)
|
50
50
|
```
|
51
51
|
|
52
|
+
## Testing
|
53
|
+
|
54
|
+
Get an API-Key from <http://www.bibsonomy.org/settings?selTab=1> and
|
55
|
+
then run the following commands:
|
56
|
+
|
57
|
+
```shell
|
58
|
+
export BIBSONOMY_USER_NAME="yourusername"
|
59
|
+
export BIBSONOMY_API_KEY="yourapikey"
|
60
|
+
bundle exec rake test
|
61
|
+
```
|
62
|
+
|
63
|
+
## Supported API Calls
|
64
|
+
|
65
|
+
- `get_post`: [post details](https://bitbucket.org/bibsonomy/bibsonomy/wiki/documentation/api/methods/DetailsForPost)
|
66
|
+
- `get_posts_for_user`:
|
67
|
+
[posts for a user](https://bitbucket.org/bibsonomy/bibsonomy/wiki/documentation/api/methods/ListOfPostsForUser)
|
68
|
+
- `get_posts_for_group` : posts for a group (= posts of the group members)
|
69
|
+
- `get_document`: documents for post
|
70
|
+
- `get_document_preview`: preview image for a document
|
71
|
+
|
52
72
|
## Jekyll
|
53
73
|
|
54
74
|
A [Jekyll](http://jekyllrb.com/) plugin:
|
@@ -115,7 +135,10 @@ bibsonomy_document_directory: pdf
|
|
115
135
|
bibsonomy_style: springer-lecture-notes-in-computer-science
|
116
136
|
```
|
117
137
|
|
118
|
-
For an example, have a look at
|
138
|
+
For an example how to use the Jekyll plugin, have a look at
|
139
|
+
[the demo project](https://github.com/rjoberon/bibsonomy-jekyll-demo)
|
140
|
+
and for an example showing the output, have a look at
|
141
|
+
[my publication list](http://www.kbs.uni-hannover.de/~jaeschke/publications.html).
|
119
142
|
|
120
143
|
|
121
144
|
## Contributing
|
data/bibsonomy.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '
|
21
|
+
spec.required_ruby_version = '>= 1.9'
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -31,6 +31,8 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_dependency "faraday", "~> 0.9"
|
32
32
|
spec.add_dependency "json", "~> 1.8"
|
33
33
|
spec.add_dependency "citeproc", "~> 1.0"
|
34
|
+
spec.add_dependency "citeproc-ruby", "~> 1.0"
|
34
35
|
spec.add_dependency "csl-styles", "~> 1.0"
|
36
|
+
spec.add_dependency "csl", "~> 1.2"
|
35
37
|
|
36
38
|
end
|
data/lib/bibsonomy.rb
CHANGED
data/lib/bibsonomy/api.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
|
6
5
|
# configuration options
|
7
6
|
$API_URL = "https://www.bibsonomy.org/"
|
8
7
|
$MAX_POSTS_PER_REQUEST = 20
|
@@ -20,6 +19,10 @@ $resource_types_bibtex = ['bibtex', 'pub', 'publication', 'publications', 'publ'
|
|
20
19
|
# @todo getting more than 1000 posts
|
21
20
|
#
|
22
21
|
# @author Robert Jäschke
|
22
|
+
#
|
23
|
+
# Changes:
|
24
|
+
# 2017-05-30 (rja)
|
25
|
+
# - added get_posts_for_group
|
23
26
|
#
|
24
27
|
module BibSonomy
|
25
28
|
class API
|
@@ -102,6 +105,37 @@ module BibSonomy
|
|
102
105
|
return response.body
|
103
106
|
end
|
104
107
|
|
108
|
+
#
|
109
|
+
# Get the posts of the users of a group, optionally filtered by tags.
|
110
|
+
#
|
111
|
+
# @param group_name [String] the name of the group
|
112
|
+
# @param resource_type [String] the type of the post. Currently supported are 'bookmark' and 'publication'.
|
113
|
+
# @param tags [Array<String>] the tags that all posts must contain (can be empty)
|
114
|
+
# @param start [Integer] number of first post to download
|
115
|
+
# @param endc [Integer] number of last post to download
|
116
|
+
# @return [Array<BibSonomy::Post>, String] the requested posts
|
117
|
+
def get_posts_for_group(group_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST)
|
118
|
+
params = {
|
119
|
+
:format => @format,
|
120
|
+
:resourcetype => get_resource_type(resource_type),
|
121
|
+
:start => start,
|
122
|
+
:end => endc,
|
123
|
+
:group => group_name
|
124
|
+
}
|
125
|
+
# add tags, if requested
|
126
|
+
if tags != nil
|
127
|
+
params[:tags] = tags.join(" ")
|
128
|
+
end
|
129
|
+
response = @conn.get "/api/posts", params
|
130
|
+
|
131
|
+
if @parse
|
132
|
+
posts = JSON.parse(response.body)["posts"]["post"]
|
133
|
+
return posts.map { |attributes| Post.new(attributes) }
|
134
|
+
end
|
135
|
+
return response.body
|
136
|
+
end
|
137
|
+
|
138
|
+
|
105
139
|
def get_document_href(user_name, intra_hash, file_name)
|
106
140
|
return "/api/users/" + CGI.escape(user_name) + "/posts/" + CGI.escape(intra_hash) + "/documents/" + CGI.escape(file_name)
|
107
141
|
end
|
@@ -127,11 +161,11 @@ module BibSonomy
|
|
127
161
|
# @param user_name
|
128
162
|
# @param intra_hash
|
129
163
|
# @param file_name
|
130
|
-
# @param size
|
164
|
+
# @param size [String] requested preview size (allowed values: SMALL, MEDIUM, LARGE)
|
131
165
|
# @return the preview image and the content type `image/jpeg`
|
132
166
|
def get_document_preview(user_name, intra_hash, file_name, size)
|
133
|
-
response = get_document_href(user_name, intra_hash, file_name), { :preview => size }
|
134
|
-
if response.status
|
167
|
+
response = @conn.get get_document_href(user_name, intra_hash, file_name), { :preview => size }
|
168
|
+
if response.status == 200
|
135
169
|
return [response.body, 'image/jpeg']
|
136
170
|
end
|
137
171
|
return nil, nil
|
data/lib/bibsonomy/csl.rb
CHANGED
@@ -18,8 +18,12 @@ require 'bibsonomy'
|
|
18
18
|
# - number of posts
|
19
19
|
# - style
|
20
20
|
# - directory
|
21
|
+
# - group
|
21
22
|
#
|
22
23
|
# Changes:
|
24
|
+
# 2017-01-19
|
25
|
+
# - added optional parameter group to control which posts are
|
26
|
+
# included based on their viewability for a specific group (not yet activated!)
|
23
27
|
# 2015-02-24
|
24
28
|
# - initial version
|
25
29
|
#
|
@@ -29,6 +33,7 @@ require 'bibsonomy'
|
|
29
33
|
# @todo add intra_hash, user_name, etc. to CSL (cf. https://bitbucket.org/bibsonomy/bibsonomy/issue/2411/)
|
30
34
|
# @todo integrate AJAX abstract
|
31
35
|
# @todo make all options available via command line
|
36
|
+
# @todo support filtering of posts by group (viewability)
|
32
37
|
#
|
33
38
|
# @author Robert Jäschke
|
34
39
|
|
@@ -68,6 +73,9 @@ module BibSonomy
|
|
68
73
|
# ignored. (default: '_oa.pdf')
|
69
74
|
attr_accessor :public_doc_postfix
|
70
75
|
|
76
|
+
# @return [String] which posts shall be included, based on the groups they are viewable for
|
77
|
+
attr_accessor :group
|
78
|
+
|
71
79
|
#
|
72
80
|
# Create a new BibSonomy instance.
|
73
81
|
#
|
@@ -82,6 +90,7 @@ module BibSonomy
|
|
82
90
|
@css_class = 'publications'
|
83
91
|
@year_headings = true
|
84
92
|
@public_doc_postfix = '_oa.pdf'
|
93
|
+
@group = 'public'
|
85
94
|
|
86
95
|
# optional parts to be rendered (or not)
|
87
96
|
@doi_link = true
|
@@ -109,6 +118,17 @@ module BibSonomy
|
|
109
118
|
# to check for duplicate file names
|
110
119
|
file_names = []
|
111
120
|
|
121
|
+
# filter posts by group
|
122
|
+
# 2017-05-30, rja, disabled until group information is returned by the API
|
123
|
+
# posts.delete_if do |v|
|
124
|
+
# if v["group"] == @group
|
125
|
+
# true
|
126
|
+
# else
|
127
|
+
# print("WARN: " + v["group"])
|
128
|
+
# false
|
129
|
+
# end
|
130
|
+
# end
|
131
|
+
|
112
132
|
# sort posts by year
|
113
133
|
sorted_keys = posts.keys.sort { |a,b| get_sort_posts(posts[b], posts[a]) }
|
114
134
|
|
@@ -190,7 +210,16 @@ module BibSonomy
|
|
190
210
|
private
|
191
211
|
|
192
212
|
def get_year(post)
|
193
|
-
|
213
|
+
issued = post["issued"]
|
214
|
+
# if the post contains only a "year" field, it is contained in
|
215
|
+
# the field "literal"
|
216
|
+
if issued["literal"]
|
217
|
+
return issued["literal"]
|
218
|
+
else
|
219
|
+
# otherwise, the date can be contained in the "raw" field
|
220
|
+
# TODO: extract the year ([12][0-9]{3}) from that field
|
221
|
+
return issued["raw"]
|
222
|
+
end
|
194
223
|
end
|
195
224
|
|
196
225
|
def get_sort_posts(a, b)
|
@@ -202,6 +231,8 @@ module BibSonomy
|
|
202
231
|
if person_b.length == 0
|
203
232
|
person_b = b["editor"]
|
204
233
|
end
|
234
|
+
# we switch the order of person_b and person_a, to sort
|
235
|
+
# descending by year but ascending by person name
|
205
236
|
return [get_year(a), a["type"], person_b[0]["family"]] <=> [get_year(b), b["type"], person_a[0]["family"]]
|
206
237
|
end
|
207
238
|
|
@@ -275,6 +306,7 @@ module BibSonomy
|
|
275
306
|
options.directory = nil
|
276
307
|
options.tags = []
|
277
308
|
options.style = "apa.csl"
|
309
|
+
options.group = "public"
|
278
310
|
options.posts = 1000
|
279
311
|
|
280
312
|
opt_parser = OptionParser.new do |opts|
|
@@ -289,6 +321,7 @@ module BibSonomy
|
|
289
321
|
opts.on('-u', '--user USER', 'return posts for USER instead of user') { |v| options[:user] = v }
|
290
322
|
opts.on('-t', '--tags TAG,TAG,...', Array, 'return posts with the given tags') { |v| options[:tags] = v }
|
291
323
|
opts.on('-s', '--style STYLE', 'use CSL style STYLE for rendering') { |v| options[:style] = v }
|
324
|
+
opts.on('-g', '--group GROUP', 'include only posts viewable for GROUP') { |v| options[:group] = v }
|
292
325
|
opts.on('-n', '--number-of-posts [COUNT]', Integer, 'number of posts to download') { |v| options[:posts] = v }
|
293
326
|
opts.on('-d', '--directory DIR', 'target directory', ' (if not given, no documents are downloaed)') { |v| options[:directory] = v }
|
294
327
|
|
@@ -333,13 +366,14 @@ module BibSonomy
|
|
333
366
|
|
334
367
|
# set defaults for optional arguments
|
335
368
|
options[:user] = options[:user_name] unless options[:user]
|
336
|
-
|
369
|
+
|
337
370
|
#
|
338
371
|
# do the actual work
|
339
372
|
#
|
340
373
|
csl = BibSonomy::CSL.new(options[:user_name], options[:api_key])
|
341
374
|
csl.pdf_dir = options[:directory]
|
342
375
|
csl.style = options[:style]
|
376
|
+
csl.group = options[:group]
|
343
377
|
|
344
378
|
html = csl.render(options[:user], options[:tags], options[:posts])
|
345
379
|
|
data/lib/bibsonomy/post.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module BibSonomy
|
4
4
|
class Post
|
5
5
|
|
6
|
-
attr_reader :user_name, :intra_hash, :title, :year, :entrytype, :booktitle, :journal, :url
|
6
|
+
attr_reader :user_name, :intra_hash, :groups, :title, :year, :entrytype, :booktitle, :journal, :url
|
7
7
|
|
8
8
|
def initialize(post)
|
9
9
|
publication = post["bibtex"]
|
@@ -15,6 +15,11 @@ module BibSonomy
|
|
15
15
|
@booktitle = publication["booktitle"]
|
16
16
|
@journal = publication["journal"]
|
17
17
|
@url = publication["url"]
|
18
|
+
# extract group names
|
19
|
+
@groups = []
|
20
|
+
post["group"].each do |group|
|
21
|
+
@groups << group["name"]
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
end
|
data/lib/bibsonomy/version.rb
CHANGED
data/test/csl_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
|
3
|
+
class BibSonomyCSLTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@csl = BibSonomy::CSL.new(ENV['BIBSONOMY_USER_NAME'], ENV['BIBSONOMY_API_KEY'])
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_exists
|
10
|
+
assert BibSonomy::CSL
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_render
|
14
|
+
VCR.use_cassette('render') do
|
15
|
+
html = @csl.render("bibsonomy-ruby", [], 10)
|
16
|
+
|
17
|
+
assert_equal "<h3>2010</h3>", html[0..12]
|
18
|
+
assert_equal "</ul>", html[-6..-2]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/test/post_test.rb
CHANGED
@@ -11,8 +11,8 @@ class BibSonomyPostTest < Minitest::Test
|
|
11
11
|
assert BibSonomy::API
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
VCR.use_cassette('
|
14
|
+
def test_get_post
|
15
|
+
VCR.use_cassette('get_post') do
|
16
16
|
post = @api.get_post("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3")
|
17
17
|
assert_equal BibSonomy::Post, post.class
|
18
18
|
|
@@ -24,8 +24,8 @@ class BibSonomyPostTest < Minitest::Test
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
VCR.use_cassette('
|
27
|
+
def test_get_posts_for_user
|
28
|
+
VCR.use_cassette('get_posts_for_user') do
|
29
29
|
result = @api.get_posts_for_user("bibsonomy-ruby", "publication", ["test"], 0, 20)
|
30
30
|
|
31
31
|
# Make sure we got all the posts
|
@@ -36,4 +36,39 @@ class BibSonomyPostTest < Minitest::Test
|
|
36
36
|
assert result.first.kind_of?(BibSonomy::Post)
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_get_posts_for_group
|
41
|
+
VCR.use_cassette('get_posts_for_group') do
|
42
|
+
result = @api.get_posts_for_group("iccs", "publication", ["test"], 0, 10)
|
43
|
+
|
44
|
+
# Make sure we got all the posts
|
45
|
+
assert_equal 2, result.length
|
46
|
+
|
47
|
+
# Make sure that the JSON was parsed
|
48
|
+
assert result.kind_of?(Array)
|
49
|
+
assert result.first.kind_of?(BibSonomy::Post)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_document_href
|
54
|
+
assert_equal "/api/users/bibsonomy-ruby/posts/c9437d5ec56ba949f533aeec00f571e3/documents/paper.pdf", @api.get_document_href("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "paper.pdf")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_document
|
58
|
+
VCR.use_cassette('get_document') do
|
59
|
+
pdf, mimetype = @api.get_document("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "test.pdf")
|
60
|
+
assert_equal "application/octet-stream;charset=UTF-8", mimetype
|
61
|
+
assert_equal "A test file\n", pdf
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def test_get_document_preview
|
67
|
+
VCR.use_cassette('get_document_preview') do
|
68
|
+
jpeg, mimetype = @api.get_document_preview("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "test.pdf", "SMALL")
|
69
|
+
assert_equal "image/jpeg", mimetype
|
70
|
+
assert_equal ["ffd8ffe00010"].pack('H*') + "JFIF", jpeg[0..9]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
39
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibsonomy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Jäschke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '1.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: citeproc-ruby
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: csl-styles
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +178,20 @@ dependencies:
|
|
164
178
|
- - "~>"
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '1.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: csl
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '1.2'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '1.2'
|
167
195
|
description: Enables calls to the BibSonomy REST API with Ruby.
|
168
196
|
email:
|
169
197
|
- jaeschke@l3s.de
|
@@ -183,6 +211,7 @@ files:
|
|
183
211
|
- lib/bibsonomy/csl.rb
|
184
212
|
- lib/bibsonomy/post.rb
|
185
213
|
- lib/bibsonomy/version.rb
|
214
|
+
- test/csl_test.rb
|
186
215
|
- test/post_test.rb
|
187
216
|
- test/test_helper.rb
|
188
217
|
homepage: https://github.com/rjoberon/bibsonomy-ruby
|
@@ -195,9 +224,9 @@ require_paths:
|
|
195
224
|
- lib
|
196
225
|
required_ruby_version: !ruby/object:Gem::Requirement
|
197
226
|
requirements:
|
198
|
-
- - "
|
227
|
+
- - ">="
|
199
228
|
- !ruby/object:Gem::Version
|
200
|
-
version: '
|
229
|
+
version: '1.9'
|
201
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
231
|
requirements:
|
203
232
|
- - ">="
|
@@ -210,6 +239,6 @@ signing_key:
|
|
210
239
|
specification_version: 4
|
211
240
|
summary: Wraps the BibSonomy REST API.
|
212
241
|
test_files:
|
242
|
+
- test/csl_test.rb
|
213
243
|
- test/post_test.rb
|
214
244
|
- test/test_helper.rb
|
215
|
-
has_rdoc:
|