bibsonomy 0.4.6 → 0.4.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60a51a2bb7d05aefff235013de9cd8cab94ca6c8
4
- data.tar.gz: a89cbb97919dbefb6ceb9c08cc8b9892509c0b24
3
+ metadata.gz: cfc29c3c38865ebf77e49be3e526070ea1c596f9
4
+ data.tar.gz: 9ed678b079893cbe99a7f3cbd1614ebcebef197e
5
5
  SHA512:
6
- metadata.gz: ce0a4005e5b141210c61fbc08a1a2961180c6e70b58cd3f68d3def639ffdf30361af41f944f13aa762e2f451ef803dff2100f23d3cae40fbb8ed8e9d2b26f420
7
- data.tar.gz: dd70c37fddda3115fa62aaaddf383be4b0ec5201c3018417d6a73896f013e8ed82edf20f323b30e136338ab39a63ffe2b6664b3d32cd301b0f234d6322c6785c
6
+ metadata.gz: 9eba9e923dfb6e4c149a741d32513d01f2351ddb3a2a783ee5f79060daa182c5ef6f47c9a560cc876977d61d7e4cb1dcc34f85142924fabdea79899540919f98
7
+ data.tar.gz: 652a1e547c8460df327387b5a9ba27f5320e87b6a3a63bd77a1f5733f18d9d480adbba09e58e1c84d491f6958338be1d848f07537040822e6d0809180c73874b
data/README.md CHANGED
@@ -68,6 +68,7 @@ bundle exec rake test
68
68
  - `get_posts_for_group` : posts for a group (= posts of the group members)
69
69
  - `get_document`: documents for post
70
70
  - `get_document_preview`: preview image for a document
71
+ - `get_posts`: [posts for a user or group](https://bitbucket.org/bibsonomy/bibsonomy/wiki/documentation/api/methods/ListOfAllPosts)
71
72
 
72
73
  ## Jekyll
73
74
 
@@ -21,9 +21,11 @@ $resource_types_bibtex = ['bibtex', 'pub', 'publication', 'publications', 'publ'
21
21
  # @author Robert Jäschke
22
22
  #
23
23
  # Changes:
24
+ # 2017-05-31 (rja)
25
+ # - refactored get_posts_for_group and get_posts_for_user into get_posts
24
26
  # 2017-05-30 (rja)
25
27
  # - added get_posts_for_group
26
- #
28
+ #
27
29
  module BibSonomy
28
30
  class API
29
31
 
@@ -86,23 +88,7 @@ module BibSonomy
86
88
  # @param endc [Integer] number of last post to download
87
89
  # @return [Array<BibSonomy::Post>, String] the requested posts
88
90
  def get_posts_for_user(user_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST)
89
- params = {
90
- :format => @format,
91
- :resourcetype => get_resource_type(resource_type),
92
- :start => start,
93
- :end => endc
94
- }
95
- # add tags, if requested
96
- if tags != nil
97
- params[:tags] = tags.join(" ")
98
- end
99
- response = @conn.get "/api/users/" + CGI.escape(user_name) + "/posts", params
100
-
101
- if @parse
102
- posts = JSON.parse(response.body)["posts"]["post"]
103
- return posts.map { |attributes| Post.new(attributes) }
104
- end
105
- return response.body
91
+ return get_posts("user", user_name, resource_type, tags, start, endc)
106
92
  end
107
93
 
108
94
  #
@@ -115,17 +101,37 @@ module BibSonomy
115
101
  # @param endc [Integer] number of last post to download
116
102
  # @return [Array<BibSonomy::Post>, String] the requested posts
117
103
  def get_posts_for_group(group_name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST)
104
+ return get_posts("group", group_name, resource_type, tags, start, endc)
105
+ end
106
+
107
+ #
108
+ # Get posts for a user or group, optionally filtered by tags.
109
+ #
110
+ # @param grouping [String] the type of the name (either "user" or "group")
111
+ # @param name [String] the name of the group or user
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(grouping, name, resource_type, tags = nil, start = 0, endc = $MAX_POSTS_PER_REQUEST)
118
118
  params = {
119
119
  :format => @format,
120
120
  :resourcetype => get_resource_type(resource_type),
121
121
  :start => start,
122
- :end => endc,
123
- :group => group_name
122
+ :end => endc
124
123
  }
124
+ # decide what to get
125
+ if grouping == "user"
126
+ params[:user] = name
127
+ elsif grouping == "group"
128
+ params[:group] = name
129
+ end
125
130
  # add tags, if requested
126
131
  if tags != nil
127
132
  params[:tags] = tags.join(" ")
128
133
  end
134
+
129
135
  response = @conn.get "/api/posts", params
130
136
 
131
137
  if @parse
@@ -135,7 +141,7 @@ module BibSonomy
135
141
  return response.body
136
142
  end
137
143
 
138
-
144
+
139
145
  def get_document_href(user_name, intra_hash, file_name)
140
146
  return "/api/users/" + CGI.escape(user_name) + "/posts/" + CGI.escape(intra_hash) + "/documents/" + CGI.escape(file_name)
141
147
  end
@@ -172,9 +178,9 @@ module BibSonomy
172
178
  end
173
179
 
174
180
 
175
-
181
+
176
182
  private
177
-
183
+
178
184
  #
179
185
  # Convenience method to allow sloppy specification of the resource
180
186
  # type.
@@ -1,3 +1,3 @@
1
1
  module BibSonomy
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -50,6 +50,33 @@ class BibSonomyPostTest < Minitest::Test
50
50
  end
51
51
  end
52
52
 
53
+ def test_get_posts_user
54
+ VCR.use_cassette('get_posts_user') do
55
+ result = @api.get_posts("user", "bibsonomy-ruby", "publication", ["test"], 0, 10)
56
+
57
+ # Make sure we got all the posts
58
+ assert_equal 1, result.length
59
+
60
+ # Make sure that the JSON was parsed
61
+ assert result.kind_of?(Array)
62
+ assert result.first.kind_of?(BibSonomy::Post)
63
+ end
64
+ end
65
+
66
+ def test_get_posts_group
67
+ VCR.use_cassette('get_posts_group') do
68
+ result = @api.get_posts("group", "iccs", "publication", ["test"], 0, 10)
69
+
70
+ # Make sure we got all the posts
71
+ assert_equal 2, result.length
72
+
73
+ # Make sure that the JSON was parsed
74
+ assert result.kind_of?(Array)
75
+ assert result.first.kind_of?(BibSonomy::Post)
76
+ end
77
+ end
78
+
79
+
53
80
  def test_get_document_href
54
81
  assert_equal "/api/users/bibsonomy-ruby/posts/c9437d5ec56ba949f533aeec00f571e3/documents/paper.pdf", @api.get_document_href("bibsonomy-ruby", "c9437d5ec56ba949f533aeec00f571e3", "paper.pdf")
55
82
  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.6
4
+ version: 0.4.7
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: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler