bibsonomy 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32cf0dbab26bbf3420c93d33ca576845c363542f
4
- data.tar.gz: 2f30eb91cd65347ab3bc7d8b18ad061cb5cc04ca
3
+ metadata.gz: '08a8cca92bb613eee121fc83132952133523cbea'
4
+ data.tar.gz: b02c0ef8002b4d9bbf3d70688c951d4d30c7c545
5
5
  SHA512:
6
- metadata.gz: ec363069944e2b3ff51d3e61f7c666b34872abd8b7de43ff167068a624f8d6d99a754dd4d1d1d3a21f2dcc05296b8560b0e24ef6d47d063208a1e68abc765756
7
- data.tar.gz: e20f1151a59b2431c7f40be23bfca5ea1d4d065b8d7b64081edfb3492d65767beac2e9885e34930577721fe7ba8da04903494750d7d0b07132a7473a64dde152
6
+ metadata.gz: 400ef771b97d5dd937dee0412ccdb2a147989b8685792adca8bf0dd631d4a45dfb8a2214f961c473c7fd8e4161f9bbeb3cf1d9c9135631f5ba3a95da5493ae12
7
+ data.tar.gz: aec2bb9a73eb1caa933b0d59971459b84d6bea767153c459128b33d3d900697ffe351eea62e7558c0d525d9ead7787fa372cce70b58f15bfd71fbcd128c84c89
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BibSonomy
2
2
 
3
- [BibSonomy](http://www.bibsonomy.org/) client for Ruby
3
+ [BibSonomy](https://www.bibsonomy.org/) client for Ruby
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/bibsonomy.svg)](http://badge.fury.io/rb/bibsonomy)
6
6
  [![Build Status](https://travis-ci.org/rjoberon/bibsonomy-ruby.svg?branch=master)](https://travis-ci.org/rjoberon/bibsonomy-ruby)
@@ -51,7 +51,7 @@ print BibSonomy::main(ARGV)
51
51
 
52
52
  ## Testing
53
53
 
54
- Get an API-Key from <http://www.bibsonomy.org/settings?selTab=1> and
54
+ Get an API-Key from <https://www.bibsonomy.org/settings?selTab=1> and
55
55
  then run the following commands:
56
56
 
57
57
  ```shell
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "citeproc-ruby", "~> 1.0", '>= 1.1.10'
35
35
  spec.add_dependency "csl-styles", "~> 1.0"
36
36
  spec.add_dependency "csl", "~> 1.5"
37
+ spec.add_dependency 'addressable', '~> 2.5'
37
38
  # required by citeproc-ruby when Ruby version <= 2.4
38
39
  spec.add_dependency "unicode", "~> 0.4", ">=0.4.4.4"
39
40
 
@@ -1,3 +1,10 @@
1
+ require 'optparse'
2
+ require 'citeproc'
3
+ require 'csl/styles'
4
+ require 'json'
5
+ require 'faraday'
6
+ require 'addressable/template'
7
+
1
8
  require_relative "bibsonomy/version"
2
9
  require_relative "bibsonomy/post"
3
10
  require_relative "bibsonomy/api"
@@ -1,6 +1,4 @@
1
1
  # coding: utf-8
2
- require 'faraday'
3
- require 'json'
4
2
 
5
3
  # configuration options
6
4
  $API_URL = "https://www.bibsonomy.org/"
@@ -21,6 +19,8 @@ $resource_types_bibtex = ['bibtex', 'pub', 'publication', 'publications', 'publ'
21
19
  # @author Robert Jäschke
22
20
  #
23
21
  # Changes:
22
+ # 2018-10-09 (rja)
23
+ # - migrated URL handling to addressable library
24
24
  # 2017-05-31 (rja)
25
25
  # - refactored get_posts_for_group and get_posts_for_user into get_posts
26
26
  # 2017-05-30 (rja)
@@ -59,6 +59,10 @@ module BibSonomy
59
59
 
60
60
  @conn.basic_auth(user_name, api_key)
61
61
 
62
+ # initialise URLs
63
+ @url_post = Addressable::Template.new("/api/users/{user_name}/posts/{intra_hash}?format={format}")
64
+ @url_posts = Addressable::Template.new("/api/posts{?format,resourcetype,start,end,user,group,tags}")
65
+ @url_doc = Addressable::Template.new("/api/users/{user_name}/posts/{intra_hash}/documents/{file_name}")
62
66
  end
63
67
 
64
68
 
@@ -69,7 +73,11 @@ module BibSonomy
69
73
  # @param intra_hash [String] the intrag hash of the post
70
74
  # @return [BibSonomy::Post, String] the requested post
71
75
  def get_post(user_name, intra_hash)
72
- response = @conn.get "/api/users/" + CGI.escape(user_name) + "/posts/" + CGI.escape(intra_hash), { :format => @format }
76
+ response = @conn.get @url_post.expand({
77
+ :user_name => user_name,
78
+ :intra_hash => intra_hash,
79
+ :format => @format
80
+ })
73
81
 
74
82
  if @parse
75
83
  attributes = JSON.parse(response.body)
@@ -115,24 +123,24 @@ module BibSonomy
115
123
  # @param endc [Integer] number of last post to download
116
124
  # @return [Array<BibSonomy::Post>, String] the requested posts
117
125
  def get_posts(grouping, 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
- }
126
+ url = @url_posts.partial_expand({
127
+ :format => @format,
128
+ :resourcetype => get_resource_type(resource_type),
129
+ :start => start,
130
+ :end => endc
131
+ })
124
132
  # decide what to get
125
133
  if grouping == "user"
126
- params[:user] = name
134
+ url = url.partial_expand({:user => name})
127
135
  elsif grouping == "group"
128
- params[:group] = name
136
+ url = url.partial_expand({:group => name})
129
137
  end
130
138
  # add tags, if requested
131
139
  if tags != nil
132
- params[:tags] = tags.join(" ")
140
+ url = url.partial_expand({:tags => tags.join(" ")})
133
141
  end
134
142
 
135
- response = @conn.get "/api/posts", params
143
+ response = @conn.get url.expand({})
136
144
 
137
145
  if @parse
138
146
  posts = JSON.parse(response.body)["posts"]["post"]
@@ -143,7 +151,11 @@ module BibSonomy
143
151
 
144
152
 
145
153
  def get_document_href(user_name, intra_hash, file_name)
146
- return "/api/users/" + CGI.escape(user_name) + "/posts/" + CGI.escape(intra_hash) + "/documents/" + CGI.escape(file_name)
154
+ return @url_doc.expand({
155
+ :user_name => user_name,
156
+ :intra_hash => intra_hash,
157
+ :file_name => file_name
158
+ })
147
159
  end
148
160
 
149
161
  #
@@ -1,11 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'optparse'
4
- require 'citeproc'
5
- require 'csl/styles'
6
- require 'json'
7
- require 'bibsonomy'
8
-
9
3
  #
10
4
  # Generates a list of publication posts from BibSonomy
11
5
  #
@@ -1,3 +1,3 @@
1
1
  module BibSonomy
2
- VERSION = "0.4.13"
2
+ VERSION = "0.4.14"
3
3
  end
@@ -5,17 +5,17 @@ class BibSonomyPostTest < Minitest::Test
5
5
  def setup
6
6
  @api = BibSonomy::API.new(ENV['BIBSONOMY_USER_NAME'], ENV['BIBSONOMY_API_KEY'], 'ruby')
7
7
  end
8
-
8
+
9
9
  def test_exists
10
10
  assert BibSonomy::Post
11
11
  assert BibSonomy::API
12
12
  end
13
-
13
+
14
14
  def test_get_post
15
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
+
19
19
  # Check that the fields are accessible by our model
20
20
  assert_equal "bibsonomy-ruby", post.user_name
21
21
  assert_equal "c9437d5ec56ba949f533aeec00f571e3", post.intra_hash
@@ -27,58 +27,58 @@ class BibSonomyPostTest < Minitest::Test
27
27
  def test_get_posts_for_user
28
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
32
32
  assert_equal 2, result.length
33
-
33
+
34
34
  # Make sure that the JSON was parsed
35
35
  assert result.kind_of?(Array)
36
36
  assert result.first.kind_of?(BibSonomy::Post)
37
- end
37
+ end
38
38
  end
39
39
 
40
40
  def test_get_posts_for_group
41
41
  VCR.use_cassette('get_posts_for_group') do
42
42
  result = @api.get_posts_for_group("iccs", "publication", ["test"], 0, 10)
43
-
43
+
44
44
  # Make sure we got all the posts
45
45
  assert_equal 2, result.length
46
-
46
+
47
47
  # Make sure that the JSON was parsed
48
48
  assert result.kind_of?(Array)
49
49
  assert result.first.kind_of?(BibSonomy::Post)
50
- end
50
+ end
51
51
  end
52
52
 
53
53
  def test_get_posts_user
54
54
  VCR.use_cassette('get_posts_user') do
55
55
  result = @api.get_posts("user", "bibsonomy-ruby", "publication", ["test"], 0, 10)
56
-
56
+
57
57
  # Make sure we got all the posts
58
58
  assert_equal 2, result.length
59
-
59
+
60
60
  # Make sure that the JSON was parsed
61
61
  assert result.kind_of?(Array)
62
62
  assert result.first.kind_of?(BibSonomy::Post)
63
- end
63
+ end
64
64
  end
65
65
 
66
66
  def test_get_posts_group
67
67
  VCR.use_cassette('get_posts_group') do
68
68
  result = @api.get_posts("group", "iccs", "publication", ["test"], 0, 10)
69
-
69
+
70
70
  # Make sure we got all the posts
71
71
  assert_equal 2, result.length
72
-
72
+
73
73
  # Make sure that the JSON was parsed
74
74
  assert result.kind_of?(Array)
75
75
  assert result.first.kind_of?(BibSonomy::Post)
76
- end
76
+ end
77
77
  end
78
78
 
79
79
 
80
80
  def test_get_document_href
81
- assert_equal "/api/users/bibsonomy-ruby/posts/c9437d5ec56ba949f533aeec00f571e3/documents/paper.pdf", @api.get_document_href("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "paper.pdf")
81
+ assert_equal Addressable::URI.parse("/api/users/bibsonomy-ruby/posts/c9437d5ec56ba949f533aeec00f571e3/documents/paper%202.pdf"), @api.get_document_href("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "paper 2.pdf")
82
82
  end
83
83
 
84
84
  def test_get_document
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.13
4
+ version: 0.4.14
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: 2018-08-09 00:00:00.000000000 Z
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,6 +204,20 @@ dependencies:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
206
  version: '1.5'
207
+ - !ruby/object:Gem::Dependency
208
+ name: addressable
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '2.5'
214
+ type: :runtime
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - "~>"
219
+ - !ruby/object:Gem::Version
220
+ version: '2.5'
207
221
  - !ruby/object:Gem::Dependency
208
222
  name: unicode
209
223
  requirement: !ruby/object:Gem::Requirement