springcm-sdk 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: c626238746aa02cfd403653085370636c99af119aa8881ae0b46173af1f06c8e
4
- data.tar.gz: 9c1c8f3fef1867d2eac0fbfca2859d30d700de0ca14834c411b761d053cc854b
3
+ metadata.gz: 70227f140ad8a68e84bd32aec03aeb899633107045e5c851e40f8b7d73068ede
4
+ data.tar.gz: bdc7c10bea0a4d8325816b55252d585a3d1898b53a040978023498e6f19cfb93
5
5
  SHA512:
6
- metadata.gz: 151e2a843f61d1e9363cb1e821423a09b8f8205e45818853be4daf57268cbfbf81ea11f171d4ef2d0876ab7d543bc5dbf065279f02f65f905ae00e910f699b59
7
- data.tar.gz: de8e1e91215603118cd19f467447bc28daa99dfb4e0cc6b5a95d7fc15a6a6e44318d465b3ed0d8aedc255080a8f231e6523483a831df82cadb7583c4f65ed03a
6
+ metadata.gz: 43a96d2cebb32bd566e90336517e0826bb21bf261a8c7b29e8c990ab087146fa530011d6086ef580691d01e3c065a0f5c85b52ad2d60e5ee0d66ebfbae836e6b
7
+ data.tar.gz: cc362d457fd602088481a9f4de399f670f1ffc6f50992447be13084470c6d081eab94dbd4834b45429520743edd406b7d50ae215ae0c28bce0392129fbb45a0c
data/README.md CHANGED
@@ -48,6 +48,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/paulho
48
48
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
49
 
50
50
  [SpringCM REST API Guide]: https://developer.springcm.com/guides/rest-api-guide
51
-
52
- [//]: # (TODO: Replace version tag below with vX.Y.Z)
53
- [documentation]: https://rubydoc.info/github/paulholden2/springcm-sdk/0.1.1
51
+ [documentation]: https://rubydoc.info/github/paulholden2/springcm-sdk
@@ -90,17 +90,17 @@ module Springcm
90
90
  end
91
91
  end
92
92
 
93
- def folder(hash = {})
94
- if hash.keys.size != 1
93
+ def folder(path: nil, uid: nil)
94
+ if (path.nil? && uid.nil?) || (!path.nil? && !uid.nil?)
95
95
  raise ArgumentError.new("Specify exactly one of: path, uid")
96
96
  end
97
97
  conn = authorized_connection(url: object_api_url)
98
98
  res = conn.get do |req|
99
- if !hash[:path].nil?
99
+ if !path.nil?
100
100
  req.url "folders"
101
- req.params["path"] = hash[:path]
102
- elsif !hash[:uid].nil?
103
- req.url "folders/#{hash[:uid]}"
101
+ req.params["path"] = path
102
+ elsif !uid.nil?
103
+ req.url "folders/#{uid}"
104
104
  end
105
105
  end
106
106
  if res.success?
@@ -1,7 +1,9 @@
1
1
  require "springcm-sdk/resource"
2
+ require "springcm-sdk/resource_list"
2
3
  require "springcm-sdk/mixins/access_level"
3
4
  require "springcm-sdk/mixins/parent_folder"
4
5
  require "springcm-sdk/mixins/documents"
6
+ require "springcm-sdk/helpers"
5
7
 
6
8
  module Springcm
7
9
  class Folder < Resource
@@ -9,17 +11,17 @@ module Springcm
9
11
  include Springcm::ParentFolder
10
12
  include Springcm::Documents
11
13
 
12
- def folders
14
+ def folders(offset: 0, limit: 20)
15
+ Helpers.validate_offset_limit!(offset, limit)
13
16
  conn = @client.authorized_connection(url: @client.object_api_url)
14
17
  res = conn.get do |req|
15
18
  req.url "folders/#{uid}/folders"
19
+ req.params["offset"] = offset
20
+ req.params["limit"] = limit
16
21
  end
17
22
  if res.success?
18
23
  data = JSON.parse(res.body)
19
- items = data["Items"].map { |item|
20
- Folder.new(item, @client)
21
- }
22
- items
24
+ ResourceList.new(data, self, Folder, @client)
23
25
  else
24
26
  nil
25
27
  end
@@ -40,12 +42,15 @@ module Springcm
40
42
  end
41
43
  end
42
44
 
43
- def documents
45
+ def documents(offset: 0, limit: 20)
46
+ Helpers.validate_offset_limit!(offset, limit)
44
47
  uri = URI(documents_href)
45
48
  url = "#{uri.scheme}://#{uri.host}"
46
49
  conn = @client.authorized_connection(url: url)
47
50
  res = conn.get do |req|
48
51
  req.url uri.path
52
+ req.params["offset"] = offset
53
+ req.params["limit"] = limit
49
54
  end
50
55
  if res.success?
51
56
  data = JSON.parse(res.body)
@@ -0,0 +1,13 @@
1
+ module Springcm
2
+ module Helpers
3
+ def self.validate_offset_limit!(offset, limit)
4
+ if !limit.is_a?(Integer) || limit < 1 || limit > 1000
5
+ raise ArgumentError.new("Limit must be an integer between 1 and 1000 (inclusive).")
6
+ end
7
+
8
+ if !offset.is_a?(Integer) || offset < 0
9
+ raise ArgumentError.new("Offset must be a positive, non-zero integer.")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
1
+ module Springcm
2
+ class ResourceList < Object
3
+ def initialize(data, parent_folder, kind, client)
4
+ @parent_folder = parent_folder
5
+ @kind = kind
6
+ super(data, client)
7
+ end
8
+
9
+ def next
10
+ nav_list("Next")
11
+ end
12
+
13
+ def prev
14
+ nav_list("Previous")
15
+ end
16
+
17
+ def first
18
+ nav_list("First")
19
+ end
20
+
21
+ def last
22
+ nav_list("Last")
23
+ end
24
+
25
+ def items
26
+ @data.fetch("Items", []).map { |item|
27
+ @kind.new(item, @client)
28
+ }
29
+ end
30
+
31
+ private
32
+
33
+ def nav_list(mode)
34
+ url = @data.fetch(mode, nil)
35
+ return nil if url.nil?
36
+ method = method_for_kind!(@kind)
37
+ uri = URI(url)
38
+ query = CGI.parse(uri.query || "")
39
+ offset = query.fetch("offset", ["0"]).first.to_i
40
+ limit = query.fetch("limit", ["20"]).first.to_i
41
+ @parent_folder.send(method, offset: offset, limit: limit)
42
+ end
43
+
44
+ def method_for_kind!(kind)
45
+ method = nil
46
+ if kind == Springcm::Folder
47
+ method = :folders
48
+ elsif kind == Springcm::Document
49
+ method = :documents
50
+ else
51
+ raise ArgumentError.new("Resource kind must be one of: Springcm::Document, Springcm::Folder.")
52
+ end
53
+ return method
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Springcm
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: springcm-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Holden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-03 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -163,11 +163,13 @@ files:
163
163
  - lib/springcm-sdk/client.rb
164
164
  - lib/springcm-sdk/document.rb
165
165
  - lib/springcm-sdk/folder.rb
166
+ - lib/springcm-sdk/helpers.rb
166
167
  - lib/springcm-sdk/mixins/access_level.rb
167
168
  - lib/springcm-sdk/mixins/documents.rb
168
169
  - lib/springcm-sdk/mixins/parent_folder.rb
169
170
  - lib/springcm-sdk/object.rb
170
171
  - lib/springcm-sdk/resource.rb
172
+ - lib/springcm-sdk/resource_list.rb
171
173
  - lib/springcm-sdk/version.rb
172
174
  - springcm-sdk.gemspec
173
175
  homepage: https://github.com/paulholden2/springcm-sdk
@@ -177,7 +179,7 @@ metadata:
177
179
  allowed_push_host: https://rubygems.org
178
180
  homepage_uri: https://github.com/paulholden2/springcm-sdk
179
181
  source_code_uri: https://github.com/paulholden2/springcm-sdk
180
- documentation_uri: https://rubydoc.info/github/paulholden2/springcm-sdk/0.2.0
182
+ documentation_uri: https://rubydoc.info/github/paulholden2/springcm-sdk/0.3.0
181
183
  changelog_uri: https://github.com/paulholden2/springcm-sdk/blob/master/CHANGELOG.md
182
184
  post_install_message:
183
185
  rdoc_options: []
@@ -194,8 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
196
  - !ruby/object:Gem::Version
195
197
  version: '0'
196
198
  requirements: []
197
- rubyforge_project:
198
- rubygems_version: 2.7.7
199
+ rubygems_version: 3.0.6
199
200
  signing_key:
200
201
  specification_version: 4
201
202
  summary: A library for working with the SpringCM REST API.