panda_doc 0.4.3 → 0.5.0

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: 002d94c7fb8aeb4356526f31c51616103804cbc5204c6cbd5a9c0139de80e69e
4
- data.tar.gz: f256f702257465cb6ab027a0cc327a44bf3c0413565413c44d826845f649dbe1
3
+ metadata.gz: c4dd2d6ef5bbab06ca01e6f77e93630d0aa88aa56f21a6568ee6039c44fb75aa
4
+ data.tar.gz: 3046fec26dd0ab07fa5831d5c43081b915bc3b5021a70765c1e05481692d4f95
5
5
  SHA512:
6
- metadata.gz: e233f412fce3a98634a6a01dc7c410813b63b390e7b51ccfc4ac4c49bbcbafdee637671dbfb64e6f5777add1e68c8e0f102cfdc40200b6654bf04602f3c7cad1
7
- data.tar.gz: 58877fbc856fb7c153a12a12300aae02633d12d0e9201bd6eae00daca89628b65421e711b6cc779ef9493187c44636b24bd6ec037e650ea713087055f466175a
6
+ metadata.gz: 5bcfa0020c545ac0ff332fb532cf27df6cea7b6e645fe67182a4209d89ebcd80a0ca49b3568d43a920657dd2a6ff9c77f808dbe4064349a4752c7b6367653a14
7
+ data.tar.gz: 72726843bb0d147c50bfb8ada65eba7c45d60f7a0d93790019bb1d2b3fcc18b616c191159caa74752bd6aaa2f98e92847702d5901a567e6d8bedafd449b3c326
@@ -1,14 +1,15 @@
1
- sudo: false
2
1
  language: ruby
2
+ os: linux
3
+ dist: xenial
3
4
 
4
5
  cache:
5
6
  - bundler
6
7
 
7
8
  rvm:
8
- - 2.3
9
- - 2.4
10
9
  - 2.5
11
10
  - 2.6
11
+ - 2.7
12
+ - 3.0
12
13
 
13
14
  env:
14
15
  global:
@@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.5.0][] (2021-01-06)
8
+
9
+ New:
10
+
11
+ - Replace virtus with dry-struct.
12
+ - Drop support for ruby < 2.5.
13
+ - Add support for API-Key authentication.
14
+ ```ruby
15
+ PandaDoc.configure do |config|
16
+ config.api_key = "API Key"
17
+ end
18
+ ```
19
+
20
+ - Add `id`, `expiration_date` and `version` to the response Document Object.
21
+ - Add [Document details](https://developers.pandadoc.com/reference#document-details) endpoint
22
+ ```ruby
23
+ document = PandaDoc::Document.details("uuid")
24
+ document.tokens.first.name
25
+ => "Token.Name"
26
+
27
+ docuemnt.tokens.first.value
28
+ => "Token Value"
29
+ ```
30
+
31
+ - Add ruby 3.0 to test coverage.
32
+
7
33
  ## [0.4.3][] (2019-03-06)
8
34
 
9
35
  Fixes:
@@ -123,7 +149,8 @@ Fixes:
123
149
 
124
150
  - Initial release
125
151
 
126
- [Unreleased]: https://github.com/opti/panda_doc/compare/v0.4.3...HEAD
152
+ [Unreleased]: https://github.com/opti/panda_doc/compare/v0.5.0...HEAD
153
+ [0.5.0]: https://github.com/opti/panda_doc/compare/v0.4.3...v0.5.0
127
154
  [0.4.3]: https://github.com/opti/panda_doc/compare/v0.4.2...v0.4.3
128
155
  [0.4.2]: https://github.com/opti/panda_doc/compare/v0.4.1...v0.4.2
129
156
  [0.4.1]: https://github.com/opti/panda_doc/compare/v0.4.0...v0.4.1
data/README.md CHANGED
@@ -25,8 +25,13 @@ Or install it yourself as:
25
25
 
26
26
  ## Configuration
27
27
 
28
- Please refer to the [Authentication](https://developers.pandadoc.com/#authentication)
29
- documentation to get the idea how to get an access token.
28
+ Both [API-Key](https://developers.pandadoc.com/reference#api-key-authentication-process) and [oAuth2.0 access token](https://developers.pandadoc.com/reference#authentication-process) authentications are supported.
29
+
30
+ ```ruby
31
+ PandaDoc.configure do |config|
32
+ config.api_key = "api key"
33
+ end
34
+ ```
30
35
 
31
36
  ```ruby
32
37
  PandaDoc.configure do |config|
@@ -1,27 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "forwardable"
4
+ require "json"
2
5
 
3
6
  require "faraday"
4
7
  require "faraday_middleware"
5
- require "virtus"
6
- require "representable/hash"
8
+ require "dry-struct"
9
+ require "dry-configurable"
7
10
 
8
11
  require "panda_doc/api_client"
9
12
  require "panda_doc/configuration"
13
+ require "panda_doc/coercions"
14
+ require "panda_doc/types"
10
15
  require "panda_doc/failure_result"
11
16
  require "panda_doc/success_result"
12
17
  require "panda_doc/document"
13
18
  require "panda_doc/response_factory"
14
- require "panda_doc/objects/status"
19
+ require "panda_doc/objects/base"
15
20
  require "panda_doc/objects/recipient"
21
+ require "panda_doc/objects/token"
16
22
  require "panda_doc/objects/document"
17
23
  require "panda_doc/objects/error"
18
24
  require "panda_doc/objects/session"
19
- require "panda_doc/responses/document"
20
- require "panda_doc/responses/error"
21
- require "panda_doc/responses/session"
22
25
 
23
26
  require "panda_doc/version"
24
27
 
25
28
  module PandaDoc
26
- # Your code goes here...
29
+ class << self
30
+ def configure(&block)
31
+ Configuration.configure(&block)
32
+ end
33
+
34
+ def configuration
35
+ Configuration.config
36
+ end
37
+ end
27
38
  end
@@ -1,15 +1,15 @@
1
- require "json"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module PandaDoc
4
4
  class ApiClient
5
5
 
6
6
  class << self
7
- def request(verb, path, **data)
7
+ def request(verb, path, data = {})
8
8
  if file = data.delete(:file)
9
9
  data = { file: file, data: JSON.generate(data) }
10
10
  end
11
11
 
12
- new(multipart: !!file).public_send(verb, path, data)
12
+ new(multipart: !!file).public_send(verb, path, **data)
13
13
  end
14
14
  end
15
15
 
@@ -21,7 +21,11 @@ module PandaDoc
21
21
  def initialize(multipart: false)
22
22
  @url_prefix = "/public/v1"
23
23
  @connection = Faraday.new(PandaDoc.configuration.endpoint) do |conn|
24
- conn.authorization :Bearer, PandaDoc.configuration.access_token
24
+ if PandaDoc.configuration.api_key
25
+ conn.authorization "API-Key", PandaDoc.configuration.api_key
26
+ else
27
+ conn.authorization :Bearer, PandaDoc.configuration.access_token
28
+ end
25
29
 
26
30
  if multipart
27
31
  conn.request :multipart
@@ -39,12 +43,12 @@ module PandaDoc
39
43
  end
40
44
  end
41
45
 
42
- def post(path, **data)
43
- connection.post(normalized_path(path), data)
46
+ def post(path, data = {})
47
+ connection.post(normalized_path(path), **data)
44
48
  end
45
49
 
46
- def get(path, **data)
47
- connection.get(normalized_path(path), data)
50
+ def get(path, data = {})
51
+ connection.get(normalized_path(path), **data)
48
52
  end
49
53
 
50
54
  private
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PandaDoc
4
+ module Coercions
5
+ def self.to_splitted_string(value)
6
+ value.to_s.split(".").last
7
+ end
8
+ end
9
+ end
@@ -1,24 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  class Configuration
3
- attr_accessor :access_token
4
- attr_accessor :logger
5
-
6
- def endpoint
7
- "https://api.pandadoc.com"
8
- end
9
- end
10
-
11
- class << self
12
- def configuration
13
- @configuration ||= Configuration.new
14
- end
5
+ extend Dry::Configurable
15
6
 
16
- def configuration=(config)
17
- @configuration = config
18
- end
7
+ setting :access_token
8
+ setting :api_key
9
+ setting :logger
19
10
 
20
- def configure
21
- yield configuration
22
- end
11
+ setting :endpoint, "https://api.pandadoc.com"
23
12
  end
24
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  module Document
3
5
  extend self
@@ -14,6 +16,10 @@ module PandaDoc
14
16
  respond(ApiClient.request(:get, "/documents/#{uuid}"))
15
17
  end
16
18
 
19
+ def details(uuid)
20
+ respond(ApiClient.request(:get, "/documents/#{uuid}/details"))
21
+ end
22
+
17
23
  def session(uuid, **data)
18
24
  respond(
19
25
  ApiClient.request(:post, "/documents/#{uuid}/session", data),
@@ -31,7 +37,7 @@ module PandaDoc
31
37
  failure(response)
32
38
 
33
39
  SuccessResult.new(
34
- ResponseFactory.new(type).build.from_hash(response.body)
40
+ ResponseFactory.build(type).new(response.body)
35
41
  )
36
42
  end
37
43
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  class FailureResult < StandardError
3
5
  extend Forwardable
@@ -11,7 +13,7 @@ module PandaDoc
11
13
 
12
14
  def initialize(response)
13
15
  @response = response
14
- @error = Responses::Error.new(Objects::Error.new).from_hash(response.body)
16
+ @error = Objects::Error.new(response.body)
15
17
  end
16
18
 
17
19
  def to_s
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PandaDoc
4
+ module Objects
5
+ class Base < Dry::Struct
6
+ transform_keys(&:to_sym)
7
+ end
8
+ end
9
+ end
@@ -1,14 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  module Objects
3
- class Document
4
- include Virtus.model
5
+ class Document < Base
6
+ attribute :id, Types::String
7
+ attribute? :uuid, Types::String
8
+ attribute :status, Types::Custom::DocumentStatus
9
+ attribute :name, Types::String
10
+ attribute? :recipients, Types::Array.of(Objects::Recipient)
11
+ attribute :date_created, Types::Params::DateTime
12
+ attribute :date_modified, Types::Params::DateTime
13
+ attribute? :expiration_date, Types::Params::DateTime.optional
14
+ attribute :version, Types::String.optional
15
+
16
+ attribute? :tokens, Types::Array.of(Objects::Token)
5
17
 
6
- attribute :uuid, String
7
- attribute :status, Objects::Status
8
- attribute :name, String
9
- attribute :recipients, Array[Objects::Recipient]
10
- attribute :created_at, DateTime
11
- attribute :updated_at, DateTime
18
+ alias_method :created_at, :date_created
19
+ alias_method :updated_at, :date_modified
20
+ alias_method :expires_at, :expiration_date
12
21
  end
13
22
  end
14
23
  end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  module Objects
3
- class Error
4
- include Virtus.model
5
-
6
- attribute :type, String
7
- attribute :detail, String
5
+ class Error < Base
6
+ attribute? :type, Types::Coercible::String.optional
7
+ attribute? :detail, Types::Params::Hash.optional | Types::Coercible::String.optional
8
8
  end
9
9
  end
10
10
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  module Objects
3
- class Recipient
4
- include Virtus.model
5
-
6
- attribute :email, String
7
- attribute :first_name, String
8
- attribute :last_name, String
9
- attribute :recipient_type, String
10
- attribute :has_completed, Axiom::Types::Boolean
5
+ class Recipient < Base
6
+ attribute :email, Types::Coercible::String
7
+ attribute :first_name, Types::Coercible::String.optional
8
+ attribute :last_name, Types::Coercible::String.optional
9
+ attribute :recipient_type, Types::Coercible::String
10
+ attribute :has_completed, Types::Params::Bool
11
11
  end
12
12
  end
13
13
  end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  module Objects
3
- class Session
4
- include Virtus.model
5
-
6
- attribute :id, String
7
- attribute :expires_at, DateTime
5
+ class Session < Base
6
+ attribute :id, Types::Coercible::String
7
+ attribute :expires_at, Types::Params::DateTime
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PandaDoc
4
+ module Objects
5
+ class Token < Base
6
+ attribute :name, Types::Coercible::String
7
+ attribute :value, Types::Coercible::String.optional
8
+ end
9
+ end
10
+ end
@@ -1,28 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  class ResponseFactory
3
5
  attr_reader :type
4
6
  private :type
5
7
 
8
+ def self.build(type)
9
+ new(type).build
10
+ end
11
+
6
12
  def initialize(type)
7
13
  @type = type.capitalize
8
14
  end
9
15
 
10
16
  def build
11
- response_class.new(object_class.new)
12
- end
13
-
14
- private
15
-
16
- def response_class
17
- class_for("Responses")
18
- end
19
-
20
- def object_class
21
- class_for("Objects")
22
- end
23
-
24
- def class_for(namespace)
25
- Object.const_get("PandaDoc::#{namespace}::#{type}")
17
+ PandaDoc::Objects.const_get(type)
26
18
  end
27
19
  end
28
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
4
  class SuccessResult
3
5
  attr_reader :object
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PandaDoc
4
+ module Types
5
+ include Dry.Types()
6
+
7
+ module Custom
8
+ DocumentStatus = Dry::Types["nominal.string"].constructor(
9
+ Coercions.method(:to_splitted_string)
10
+ )
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PandaDoc
2
- VERSION = "0.4.3"
4
+ VERSION = "0.5.0"
3
5
  end
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'panda_doc/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/panda_doc/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "panda_doc"
@@ -16,13 +15,13 @@ Gem::Specification.new do |spec|
16
15
  spec.license = "MIT"
17
16
 
18
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.bindir = "bin"
19
+ spec.executables = []
21
20
  spec.require_paths = ["lib"]
22
21
 
23
- spec.required_ruby_version = "~> 2.2"
24
- spec.add_dependency "faraday", "~> 0.9", ">= 0.9.2"
25
- spec.add_dependency "faraday_middleware", "~> 0.10", ">= 0.10.0"
26
- spec.add_dependency "virtus", "~> 1.0", ">= 1.0.5"
27
- spec.add_dependency "representable", ">= 3.0.0"
22
+ spec.required_ruby_version = ">= 2.5"
23
+ spec.add_dependency "faraday", ">= 0.9.2", "< 2.0"
24
+ spec.add_dependency "faraday_middleware", ">= 0.10.0", "< 2.0"
25
+ spec.add_dependency "dry-configurable", "~> 0.11"
26
+ spec.add_dependency "dry-struct", "~> 1.3"
28
27
  end
metadata CHANGED
@@ -1,89 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Pstyga
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.9'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 0.9.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '0.9'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 0.9.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday_middleware
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '0.10'
40
37
  - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 0.10.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '0.10'
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: 0.10.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
53
  - !ruby/object:Gem::Dependency
54
- name: virtus
54
+ name: dry-configurable
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.0'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.0.5
59
+ version: '0.11'
63
60
  type: :runtime
64
61
  prerelease: false
65
62
  version_requirements: !ruby/object:Gem::Requirement
66
63
  requirements:
67
64
  - - "~>"
68
65
  - !ruby/object:Gem::Version
69
- version: '1.0'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.0.5
66
+ version: '0.11'
73
67
  - !ruby/object:Gem::Dependency
74
- name: representable
68
+ name: dry-struct
75
69
  requirement: !ruby/object:Gem::Requirement
76
70
  requirements:
77
- - - ">="
71
+ - - "~>"
78
72
  - !ruby/object:Gem::Version
79
- version: 3.0.0
73
+ version: '1.3'
80
74
  type: :runtime
81
75
  prerelease: false
82
76
  version_requirements: !ruby/object:Gem::Requirement
83
77
  requirements:
84
- - - ">="
78
+ - - "~>"
85
79
  - !ruby/object:Gem::Version
86
- version: 3.0.0
80
+ version: '1.3'
87
81
  description: Ruby wrapper for PandaDoc.com API
88
82
  email:
89
83
  - igor.pstyga@gmail.com
@@ -105,43 +99,42 @@ files:
105
99
  - bin/setup
106
100
  - lib/panda_doc.rb
107
101
  - lib/panda_doc/api_client.rb
102
+ - lib/panda_doc/coercions.rb
108
103
  - lib/panda_doc/configuration.rb
109
104
  - lib/panda_doc/document.rb
110
105
  - lib/panda_doc/failure_result.rb
106
+ - lib/panda_doc/objects/base.rb
111
107
  - lib/panda_doc/objects/document.rb
112
108
  - lib/panda_doc/objects/error.rb
113
109
  - lib/panda_doc/objects/recipient.rb
114
110
  - lib/panda_doc/objects/session.rb
115
- - lib/panda_doc/objects/status.rb
111
+ - lib/panda_doc/objects/token.rb
116
112
  - lib/panda_doc/response_factory.rb
117
- - lib/panda_doc/responses/document.rb
118
- - lib/panda_doc/responses/error.rb
119
- - lib/panda_doc/responses/session.rb
120
113
  - lib/panda_doc/success_result.rb
114
+ - lib/panda_doc/types.rb
121
115
  - lib/panda_doc/version.rb
122
116
  - panda_doc.gemspec
123
117
  homepage: https://github.com/opti/panda_doc
124
118
  licenses:
125
119
  - MIT
126
120
  metadata: {}
127
- post_install_message:
121
+ post_install_message:
128
122
  rdoc_options: []
129
123
  require_paths:
130
124
  - lib
131
125
  required_ruby_version: !ruby/object:Gem::Requirement
132
126
  requirements:
133
- - - "~>"
127
+ - - ">="
134
128
  - !ruby/object:Gem::Version
135
- version: '2.2'
129
+ version: '2.5'
136
130
  required_rubygems_version: !ruby/object:Gem::Requirement
137
131
  requirements:
138
132
  - - ">="
139
133
  - !ruby/object:Gem::Version
140
134
  version: '0'
141
135
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.6
144
- signing_key:
136
+ rubygems_version: 3.2.3
137
+ signing_key:
145
138
  specification_version: 4
146
139
  summary: Ruby wrapper for PandaDoc.com API
147
140
  test_files: []
@@ -1,9 +0,0 @@
1
- module PandaDoc
2
- module Objects
3
- class Status < Virtus::Attribute
4
- def coerce(value)
5
- value.to_s.split(".").last
6
- end
7
- end
8
- end
9
- end
@@ -1,21 +0,0 @@
1
- module PandaDoc
2
- module Responses
3
- class Document < Representable::Decorator
4
- include Representable::Hash
5
-
6
- property :uuid
7
- property :status
8
- property :name
9
- property :created_at, as: :date_created
10
- property :updated_at, as: :date_modified
11
-
12
- collection :recipients, class: PandaDoc::Objects::Recipient do
13
- property :email
14
- property :first_name
15
- property :last_name
16
- property :recipient_type
17
- property :has_completed
18
- end
19
- end
20
- end
21
- end
@@ -1,10 +0,0 @@
1
- module PandaDoc
2
- module Responses
3
- class Error < Representable::Decorator
4
- include Representable::Hash
5
-
6
- property :type
7
- property :detail
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module PandaDoc
2
- module Responses
3
- class Session < Representable::Decorator
4
- include Representable::Hash
5
-
6
- property :id
7
- property :expires_at
8
- end
9
- end
10
- end