springcm-sdk 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 62ce246eed8c9903f1a23c83296df864a39b29e7bdfc0dd1351833854ff9b2d4
4
- data.tar.gz: 51bef14dbffb1245439232d41c10eb64d5ce29b31a3e1483aa6973e0be53b4ea
3
+ metadata.gz: dd0b30d78f3a71c434ed1b79d6a8a24d01dc8907bcaacf3b2ddacab12300a865
4
+ data.tar.gz: 42567803347e928ccd0bd19ac7adfb88efa09e6ad8f8ed57be2430ef42b4549b
5
5
  SHA512:
6
- metadata.gz: f09b65c50f48af5ffa74584137bd79b3cb62fcab93f2b11ddca2089ef1815c82a455e23c6fc3591630a5238d29a37f452856d06e5e95bc25d0acd69f01c85d9d
7
- data.tar.gz: d8f334881ad6de05354f696c8738344222750f177b2013e37492e71e1a392f1ce5173d8acd287ebddd768ade0c5d6ee9fe09532c3d911aa1d62469d04d931cd1
6
+ metadata.gz: eb8d8db4db51182ab13c3bb83076861ef6a448b689c842d6f1c88f733db85e63a2997415c384284b969f6cef52815084ecafadab7ad98108d27d7c076c8946bc
7
+ data.tar.gz: 5e6fa0640fda92bfca0910ae59fc6e5639bd59196f4bc332a314f23fc40c67b83319eb77f22f8a87645265714be5aa99c067425344f185c0c53c3a7bfcbd18e5
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  All notable changes to springcm-sdk will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
+ ### Added
7
+ * Folder object and API
8
+
9
+ ### Changed
10
+ * Client no longer accepts credentials with keyword arguments
6
11
 
7
12
  ## [0.1.1] - 2019-07-17
8
13
  ### Added
@@ -17,6 +22,6 @@ All notable changes to springcm-sdk will be documented in this file.
17
22
  ### Added
18
23
  * Initial release to reserve gem name
19
24
 
20
- [Unreleased]: https://github.com/paulholden2/springcm-sdk/compare/v0.1.0...HEAD
21
- [0.1.0]: https://github.com/paulholden2/springcm-sdk/releases/tag/v0.1.0
22
- [0.1.1]: https://github.com/paulholden2/springcm-sdk/releases/tag/v0.1.1
25
+ [Unreleased]: https://github.com/paulholden2/springcm-sdk/compare/0.1.1...HEAD
26
+ [0.1.0]: https://github.com/paulholden2/springcm-sdk/releases/tag/0.1.0
27
+ [0.1.1]: https://github.com/paulholden2/springcm-sdk/releases/tag/0.1.1
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 TODO: Write your name
3
+ Copyright (c) 2019 Paul Holden
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SpringCM
1
+ # SpringCM SDK
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/springcm-sdk.svg)](https://badge.fury.io/rb/springcm-sdk) [![Build Status](https://travis-ci.org/paulholden2/springcm-sdk.svg?branch=master)](https://travis-ci.org/paulholden2/springcm-sdk) [![Maintainability](https://api.codeclimate.com/v1/badges/06e1dd90fde417de15da/maintainability)](https://codeclimate.com/github/paulholden2/springcm-sdk/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/06e1dd90fde417de15da/test_coverage)](https://codeclimate.com/github/paulholden2/springcm-sdk/test_coverage)
4
4
 
@@ -9,7 +9,7 @@ This gem is a library for working with the SpringCM REST API.
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'springcm'
12
+ gem 'springcm-sdk'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -18,22 +18,36 @@ And then execute:
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install springcm
21
+ $ gem install springcm-sdk
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ### Connecting
26
26
 
27
- ## Development
27
+ To begin using the SpringCM REST API, you must first acquire a client ID and
28
+ secret pair. To do so, contact DocuSign Support and request a key pair for
29
+ REST API usage. They require you to be a super administrator in the account
30
+ before they will generate the key pair for you. For more information, see
31
+ the [SpringCM REST API Guide].
28
32
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+ ```ruby
34
+ client = Springcm::Client.new("uatna11", "<your client ID>", "<your client secret>")
35
+ client.connect
36
+ client.authenticated?
37
+ # ...
38
+ ```
30
39
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+ For more information, view the [documentation].
32
41
 
33
42
  ## Contributing
34
43
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/paulholden2/springcm.
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/paulholden2/springcm-sdk.
36
45
 
37
46
  ## License
38
47
 
39
48
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
+
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
data/bin/.gitignore ADDED
@@ -0,0 +1 @@
1
+ livetest
data/exe/springcm ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "springcm"
@@ -0,0 +1,6 @@
1
+ require "springcm/object"
2
+
3
+ module Springcm
4
+ class Account < Object
5
+ end
6
+ end
@@ -1,12 +1,17 @@
1
1
  require "faraday"
2
+ require "springcm/account"
3
+ require "springcm/folder"
4
+ require "springcm/document"
2
5
 
3
6
  module Springcm
4
7
  class Client
8
+ attr_reader :access_token
9
+
5
10
  # @param data_center [String] Data center name, e.g. uatna11
6
11
  # @param client_id [String] Your API client ID
7
12
  # @param client_secret [String] Your API client secret
8
- def initialize(data_center:, client_id:, client_secret:)
9
- if !["na11", "uatna11"].include?(data_center)
13
+ def initialize(data_center, client_id, client_secret)
14
+ if !["na11", "uatna11", "eu11", "eu21", "na21", "us11"].include?(data_center)
10
15
  raise Springcm::ConnectionInfoError.new("Invalid data center '#{data_center.to_s}'")
11
16
  end
12
17
 
@@ -24,7 +29,7 @@ module Springcm
24
29
  def connect(safe=true)
25
30
  conn = Faraday.new(url: auth_url)
26
31
  res = conn.post do |req|
27
- req.url "/"
32
+ req.headers['Content-Type'] = 'application/json'
28
33
  req.body = {
29
34
  client_id: @client_id,
30
35
  client_secret: @client_secret
@@ -34,20 +39,78 @@ module Springcm
34
39
  data = JSON.parse(res.body)
35
40
  @access_token = data.fetch("access_token")
36
41
  @expiry = Time.now + data.fetch("expires_in")
37
- true
38
42
  else
39
43
  @access_token = nil
40
44
  @expiry = nil
41
45
  raise Springcm::InvalidClientIdOrSecretError.new if !safe
46
+ return false
47
+ end
48
+ end
49
+
50
+ def get_account_info
51
+ conn = authorized_connection(url: object_api_url)
52
+ res = conn.get do |req|
53
+ req.headers["Content-Type"] = "application/json"
54
+ req.url "accounts/current"
55
+ end
56
+ if res.success?
57
+ data = JSON.parse(res.body)
58
+ @account = Springcm::Account.new(data, self)
59
+ true
60
+ else
42
61
  false
43
62
  end
44
63
  end
45
64
 
65
+ def account
66
+ if @account.nil?
67
+ get_account_info
68
+ end
69
+ @account
70
+ end
71
+
46
72
  # Shorthand for connecting unsafely
47
73
  def connect!
48
74
  connect(false)
49
75
  end
50
76
 
77
+ # Retrieve the root folder in SpringCM
78
+ # @return [Springcm::Folder] The root folder object.
79
+ def root_folder
80
+ conn = authorized_connection(url: object_api_url)
81
+ res = conn.get do |req|
82
+ req.url "folders"
83
+ req.params["systemfolder"] = "root"
84
+ end
85
+ if res.success?
86
+ data = JSON.parse(res.body)
87
+ return Folder.new(data, self)
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+ def folder(hash = {})
94
+ if hash.keys.size != 1
95
+ raise ArgumentError.new("Specify exactly one of: path, uid")
96
+ end
97
+ conn = authorized_connection(url: object_api_url)
98
+ res = conn.get do |req|
99
+ if !hash[:path].nil?
100
+ req.url "folders"
101
+ req.params["path"] = hash[:path]
102
+ elsif !hash[:uid].nil?
103
+ req.url "folders/#{hash[:uid]}"
104
+ end
105
+ end
106
+ if res.success?
107
+ data = JSON.parse(res.body)
108
+ return Folder.new(data, self)
109
+ else
110
+ nil
111
+ end
112
+ end
113
+
51
114
  # Check if client is successfully authenticated
52
115
  # @return [Boolean] Whether a valid, unexpired access token is held.
53
116
  def authenticated?
@@ -74,6 +137,21 @@ module Springcm
74
137
  "https://auth#{auth_subdomain_suffix}.springcm.com/api/v#{@auth_version}/apiuser"
75
138
  end
76
139
 
140
+ def authorized_connection(*options)
141
+ Faraday.new(*options) do |conn|
142
+ options = [{
143
+ max: 10,
144
+ interval: 1,
145
+ interval_randomness: 0.5,
146
+ backoff_factor: 2,
147
+ retry_statuses: [429]
148
+ }]
149
+ conn.request :retry, *options
150
+ conn.adapter :net_http
151
+ conn.authorization('bearer', @access_token)
152
+ end
153
+ end
154
+
77
155
  private
78
156
 
79
157
  def auth_subdomain_suffix
@@ -0,0 +1,8 @@
1
+ require "springcm/resource"
2
+ require "springcm/mixins/access_level"
3
+
4
+ module Springcm
5
+ class Document < Resource
6
+ include Springcm::AccessLevel
7
+ end
8
+ end
@@ -0,0 +1,61 @@
1
+ require "springcm/resource"
2
+ require "springcm/mixins/access_level"
3
+ require "springcm/mixins/parent_folder"
4
+ require "springcm/mixins/documents"
5
+
6
+ module Springcm
7
+ class Folder < Resource
8
+ include Springcm::AccessLevel
9
+ include Springcm::ParentFolder
10
+ include Springcm::Documents
11
+
12
+ def folders
13
+ conn = @client.authorized_connection(url: @client.object_api_url)
14
+ res = conn.get do |req|
15
+ req.url "folders/#{uid}/folders"
16
+ end
17
+ if res.success?
18
+ data = JSON.parse(res.body)
19
+ items = data["Items"].map { |item|
20
+ Folder.new(item, @client)
21
+ }
22
+ items
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
28
+ def parent_folder
29
+ uri = URI(parent_folder_href)
30
+ url = "#{uri.scheme}://#{uri.host}"
31
+ conn = @client.authorized_connection(url: url)
32
+ res = conn.get do |req|
33
+ req.url uri.path
34
+ end
35
+ if res.success?
36
+ data = JSON.parse(res.body)
37
+ Folder.new(data, @client)
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ def documents
44
+ uri = URI(documents_href)
45
+ url = "#{uri.scheme}://#{uri.host}"
46
+ conn = @client.authorized_connection(url: url)
47
+ res = conn.get do |req|
48
+ req.url uri.path
49
+ end
50
+ if res.success?
51
+ data = JSON.parse(res.body)
52
+ items = data["Items"].map { |item|
53
+ Document.new(item, @client)
54
+ }
55
+ items
56
+ else
57
+ nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,37 @@
1
+ module Springcm
2
+ module AccessLevel
3
+ # @return [Boolean] Does the API user have see permission
4
+ def see?
5
+ !!access_level.dig("See")
6
+ end
7
+
8
+ # @return [Boolean] Does the API user have read permission
9
+ def read?
10
+ !!access_level.dig("Read")
11
+ end
12
+
13
+ # @return [Boolean] Does the API user have write permission
14
+ def write?
15
+ !!access_level.dig("Write")
16
+ end
17
+
18
+ # @return [Boolean] Does the API user have move permission
19
+ def move?
20
+ !!access_level.dig("Move")
21
+ end
22
+
23
+ # @return [Boolean] Does the API user have create permission
24
+ def create?
25
+ !!access_level.dig("Create")
26
+ end
27
+
28
+ # @return [Boolean] Does the API user have set access permission
29
+ def set_access?
30
+ !!access_level.dig("SetAccess")
31
+ end
32
+
33
+ def access_level
34
+ @data.fetch("AccessLevel")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Springcm
2
+ module Documents
3
+ def documents_href
4
+ @data.dig("Documents", "Href")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module Springcm
2
+ module ParentFolder
3
+ def parent_folder_href
4
+ # Root folders won't have ParentFolder key
5
+ @data.dig("ParentFolder", "Href")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Springcm
2
+ class Object
3
+ def initialize(data, client)
4
+ @client = client
5
+ @data = data
6
+ end
7
+
8
+ def method_missing(m, *args, &block)
9
+ key = m.to_s.split("_").map(&:capitalize).join
10
+ if @data.key?(key)
11
+ @data.fetch(key)
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require "springcm/object"
2
+
3
+ module Springcm
4
+ class Resource < Object
5
+ # @return [String] The folder unique identifier (UID)
6
+ def uid
7
+ href[-36..-1]
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Springcm
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/springcm.rb CHANGED
@@ -17,7 +17,7 @@ module Springcm
17
17
 
18
18
  class InvalidClientIdOrSecretError < Error
19
19
  def initialize
20
- super('Invalid Client Id or Client Secret')
20
+ super("Invalid Client Id or Client Secret")
21
21
  end
22
22
  end
23
23
  end
data/springcm-sdk.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
35
  end
36
36
  spec.bindir = "exe"
37
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.executables = ["springcm"]
38
38
  spec.require_paths = ["lib"]
39
39
 
40
40
  spec.add_dependency "faraday", "~> 0.15.4"
@@ -46,4 +46,5 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency "webmock", "~> 3.6"
47
47
  spec.add_development_dependency "simplecov", "~> 0.17"
48
48
  spec.add_development_dependency "yard", "~> 0.9"
49
+ spec.add_development_dependency "uuid", "~> 2.3"
49
50
  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.1.1
4
+ version: 0.1.2
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-07-17 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -122,11 +122,26 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: uuid
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.3'
125
139
  description: A library for working with the SpringCM REST API and associated objects
126
140
  in Ruby applications.
127
141
  email:
128
142
  - pholden@stria.com
129
- executables: []
143
+ executables:
144
+ - springcm
130
145
  extensions: []
131
146
  extra_rdoc_files: []
132
147
  files:
@@ -139,10 +154,20 @@ files:
139
154
  - LICENSE.txt
140
155
  - README.md
141
156
  - Rakefile
157
+ - bin/.gitignore
142
158
  - bin/console
143
159
  - bin/setup
160
+ - exe/springcm
144
161
  - lib/springcm.rb
162
+ - lib/springcm/account.rb
145
163
  - lib/springcm/client.rb
164
+ - lib/springcm/document.rb
165
+ - lib/springcm/folder.rb
166
+ - lib/springcm/mixins/access_level.rb
167
+ - lib/springcm/mixins/documents.rb
168
+ - lib/springcm/mixins/parent_folder.rb
169
+ - lib/springcm/object.rb
170
+ - lib/springcm/resource.rb
146
171
  - lib/springcm/version.rb
147
172
  - springcm-sdk.gemspec
148
173
  homepage: https://github.com/paulholden2/springcm-sdk
@@ -152,7 +177,7 @@ metadata:
152
177
  allowed_push_host: https://rubygems.org
153
178
  homepage_uri: https://github.com/paulholden2/springcm-sdk
154
179
  source_code_uri: https://github.com/paulholden2/springcm-sdk
155
- documentation_uri: https://rubydoc.info/github/paulholden2/springcm-sdk/0.1.1
180
+ documentation_uri: https://rubydoc.info/github/paulholden2/springcm-sdk/0.1.2
156
181
  changelog_uri: https://github.com/paulholden2/springcm-sdk/blob/master/CHANGELOG.md
157
182
  post_install_message:
158
183
  rdoc_options: []