pandadoc-api 0.1.3 → 0.1.4

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
- SHA256:
3
- metadata.gz: 61692462d6fb1acc26ec5e85df32b4ac9e70967180aff6fea6a8a1a0194fe5f1
4
- data.tar.gz: d9c88b82dcc3fb14051b0eb736043baf1976b890c7c26fcd5d7a3c05962b32fb
2
+ SHA1:
3
+ metadata.gz: 10a86d130a08c5c79a6c1b02d152b4f2d754cfc8
4
+ data.tar.gz: 465fce230f81e9fa134f7e20d09f39987d10371f
5
5
  SHA512:
6
- metadata.gz: d49e7e155f81b4c6350ef2c904fdefe7bf3d96accfed367f0370992da9dbaf15c74ab2df5c49c3cbec22f37a7b595156be52f4784b0c280f180ef1e8fd73d41d
7
- data.tar.gz: 982828af5c1ca819dfe5e877e7b0404350c3d5b028b40d50713ca258dfdfdf68a79cfe5ee0b80d8dae27d0ee4cdc12aa04ad3c72b9a1aa472413e19cc9747ce6
6
+ metadata.gz: b87a992ae237c8e433defdddb2fea5e2796cab50c6332aad3b63356df51a0d27421eaa841d3e3f14bf26e65e20042067a49bcdfedee8c6af4612da62c07e2c16
7
+ data.tar.gz: eecc463b78d67bf4d21441eb42b2a06149f0a12df8e58cdf030f0bc37f9403e6a53c079bc84b66e07ca30c16453efdd53fdea1cd1c00b54ad17e4e18b0833c72
@@ -1,3 +1,5 @@
1
+ require 'pandadoc/api/client'
2
+ require 'pandadoc/api/params_validator'
1
3
  require 'pandadoc/api/version'
2
4
  require 'pandadoc/api/document'
3
5
  require 'pandadoc/api/template'
@@ -0,0 +1,31 @@
1
+ require 'httparty'
2
+
3
+ module Pandadoc
4
+ module Api
5
+ class Client
6
+ def get(path, token, params = {})
7
+ uri = build_uri(path)
8
+ HTTParty.get(uri, headers: default_headers(token), query: params)
9
+ end
10
+
11
+ def post_json(path, token, params = {})
12
+ uri = build_uri(path)
13
+ headers = default_headers(token).merge('Content-Type' => 'application/json')
14
+
15
+ HTTParty.post(uri, headers: headers, body: params.to_json)
16
+ end
17
+
18
+ private
19
+
20
+ def default_headers(token)
21
+ {
22
+ 'Authorization' => "Bearer #{token}"
23
+ }
24
+ end
25
+
26
+ def build_uri(path)
27
+ File.join(Pandadoc::Api::API_ROOT, path)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,31 +1,3 @@
1
- require 'httparty'
2
-
3
- class RequiredParameterError < StandardError
4
- attr_reader :parameter
5
-
6
- def initialize(message, parameter)
7
- # Call the parent's constructor to set the message
8
- super(message)
9
-
10
- # Store the action in an instance variable
11
- @parameter = parameter
12
- end
13
- end
14
-
15
- class ParameterTypeError < StandardError
16
- attr_reader :received
17
- attr_reader :requested
18
-
19
- def initialize(message, received, requested)
20
- # Call the parent's constructor to set the message
21
- super(message)
22
-
23
- # Store the action in an instance variable
24
- @received = received
25
- @requested = requested
26
- end
27
- end
28
-
29
1
  module Pandadoc
30
2
  module Api
31
3
  class Document
@@ -52,9 +24,7 @@ module Pandadoc
52
24
  metadata: { required: false, type: Hash }
53
25
  }
54
26
 
55
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/documents",
56
- headers: { 'Authorization' => auth_header(token) },
57
- query: validated_params(params, validations))
27
+ client.get '/documents', token, validated_params(params, validations)
58
28
  end
59
29
 
60
30
  def create(token, params = {})
@@ -62,25 +32,21 @@ module Pandadoc
62
32
  name: { required: true, type: String },
63
33
  template_uuid: { required: true, type: String },
64
34
  recipients: { required: true, type: Array },
65
- tokens: { required: false, type: Hash },
35
+ tokens: { required: false, type: Array },
66
36
  fields: { required: false, type: Hash },
67
37
  metadata: { required: false, type: Hash },
68
38
  pricing_tables: { required: false, type: Array }
69
39
  }
70
40
 
71
- HTTParty.post("#{Pandadoc::Api::API_ROOT}/documents",
72
- headers: { 'Authorization' => auth_header(token), 'Content-Type': 'application/json' },
73
- body: validated_params(params, validations).to_json)
41
+ client.post_json '/documents', token, validated_params(params, validations)
74
42
  end
75
43
 
76
44
  def status(token, document_id)
77
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/documents/#{document_id}",
78
- headers: { 'Authorization' => auth_header(token) })
45
+ client.get "/documents/#{document_id}", token
79
46
  end
80
47
 
81
48
  def details(token, document_id)
82
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/documents/#{document_id}/details",
83
- headers: { 'Authorization' => auth_header(token) })
49
+ client.get "/documents/#{document_id}/details", token
84
50
  end
85
51
 
86
52
  # send is already a Ruby thing, overriding it would be bad
@@ -90,9 +56,7 @@ module Pandadoc
90
56
  silent: { required: false, type: [TrueClass, FalseClass] }
91
57
  }
92
58
 
93
- HTTParty.post("#{Pandadoc::Api::API_ROOT}/documents/#{document_id}/send",
94
- headers: { 'Authorization' => auth_header(token), 'Content-Type': 'application/json' },
95
- body: validated_params(params, validations))
59
+ client.post_json "/documents/#{document_id}/send", token, validated_params(params, validations)
96
60
  end
97
61
 
98
62
  def link(token, document_id, params = {})
@@ -101,9 +65,7 @@ module Pandadoc
101
65
  lifetime: { required: false, type: Integer }
102
66
  }
103
67
 
104
- response = HTTParty.post("#{Pandadoc::Api::API_ROOT}/documents/#{document_id}/session",
105
- headers: { 'Authorization' => auth_header(token), 'Content-Type': 'application/json' },
106
- body: validated_params(params, validations))
68
+ response = client.post_json "/documents/#{document_id}/session", token, validated_params(params, validations)
107
69
 
108
70
  json_response = JSON.parse(response.body, symbolize_names: true)
109
71
  session_id = json_response[:id]
@@ -112,30 +74,17 @@ module Pandadoc
112
74
  end
113
75
 
114
76
  def download(token, document_id)
115
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/documents/#{document_id}/download",
116
- headers: { 'Authorization' => auth_header(token) })
77
+ client.get "/documents/#{document_id}/download", token
117
78
  end
118
79
 
119
- def auth_header(token)
120
- "Bearer #{token}"
80
+ private
81
+
82
+ def client
83
+ @client ||= Pandadoc::Api::Client.new
121
84
  end
122
85
 
123
86
  def validated_params(params, validations)
124
- valid_keys = validations.keys
125
- valid_params = params.keep_if { |key| valid_keys.include? key }
126
-
127
- validations.each_pair do |key, validators|
128
- if validators[:required] == true && valid_params[key].nil?
129
- raise RequiredParameterError.new('Missing required parameter', key)
130
- end
131
-
132
- validators_type_array = validators[:type].is_a?(Array) ? validators[:type] : [validators[:type]]
133
- if valid_params[key] && !validators_type_array.include?(valid_params[key].class)
134
- raise ParameterTypeError.new("Invalid parameter type, received #{valid_params[key].class} requested #{validators[:type]}", valid_params[:key].class, validators[:type])
135
- end
136
- end
137
-
138
- valid_params
87
+ Pandadoc::Api::ParamsValidator.validate(params, validations)
139
88
  end
140
89
  end
141
90
  end
@@ -0,0 +1,49 @@
1
+ module Pandadoc
2
+ module Api
3
+ class ParamsValidator
4
+ class RequiredParameterError < StandardError
5
+ attr_reader :parameter
6
+
7
+ def initialize(message, parameter)
8
+ # Call the parent's constructor to set the message
9
+ super(message)
10
+
11
+ # Store the action in an instance variable
12
+ @parameter = parameter
13
+ end
14
+ end
15
+
16
+ class ParameterTypeError < StandardError
17
+ attr_reader :received
18
+ attr_reader :requested
19
+
20
+ def initialize(message, received, requested)
21
+ # Call the parent's constructor to set the message
22
+ super(message)
23
+
24
+ # Store the action in an instance variable
25
+ @received = received
26
+ @requested = requested
27
+ end
28
+ end
29
+
30
+ def self.validate(params, validations)
31
+ valid_keys = validations.keys
32
+ valid_params = params.keep_if { |key| valid_keys.include? key }
33
+
34
+ validations.each_pair do |key, validators|
35
+ if validators[:required] == true && valid_params[key].nil?
36
+ raise RequiredParameterError.new('Missing required parameter', key)
37
+ end
38
+
39
+ validators_type_array = validators[:type].is_a?(Array) ? validators[:type] : [validators[:type]]
40
+ if valid_params[key] && !validators_type_array.include?(valid_params[key].class)
41
+ raise ParameterTypeError.new("Invalid parameter type, received #{valid_params[key].class} requested #{validators[:type]}", valid_params[:key].class, validators[:type])
42
+ end
43
+ end
44
+
45
+ valid_params
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,3 @@
1
- require 'httparty'
2
-
3
1
  module Pandadoc
4
2
  module Api
5
3
  class Template
@@ -11,36 +9,21 @@ module Pandadoc
11
9
  page: { required: false, type: Integer }
12
10
  }
13
11
 
14
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/templates",
15
- headers: { 'Authorization' => auth_header(token) },
16
- query: validated_params(params, validations))
12
+ client.get '/templates', token, validated_params(params, validations)
17
13
  end
18
14
 
19
15
  def details(token, template_id)
20
- HTTParty.get("#{Pandadoc::Api::API_ROOT}/templates/#{template_id}/details",
21
- headers: { 'Authorization' => auth_header(token) })
16
+ client.get "/templates/#{template_id}/details", token
22
17
  end
23
18
 
24
- def auth_header(token)
25
- "Bearer #{token}"
26
- end
19
+ private
27
20
 
28
21
  def validated_params(params, validations)
29
- valid_keys = validations.keys
30
- valid_params = params.keep_if { |key| valid_keys.include? key }
31
-
32
- validations.each_pair do |key, validators|
33
- if validators[:required] == true && valid_params[key].nil?
34
- raise RequiredParameterError.new('Missing required parameter', key)
35
- end
36
-
37
- validators_type_array = validators[:type].is_a?(Array) ? validators[:type] : [validators[:type]]
38
- if valid_params[key] && !validators_type_array.include?(valid_params[key].class)
39
- raise ParameterTypeError.new("Invalid parameter type, received #{valid_params[key].class} requested #{validators[:type]}", valid_params[:key].class, validators[:type])
40
- end
41
- end
22
+ Pandadoc::Api::ParamsValidator.validate(params, validations)
23
+ end
42
24
 
43
- valid_params
25
+ def client
26
+ @client ||= Pandadoc::Api::Client.new
44
27
  end
45
28
  end
46
29
  end
@@ -1,5 +1,5 @@
1
1
  module Pandadoc
2
2
  module Api
3
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.1.4'.freeze
4
4
  end
5
5
  end
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rspec', '~> 3.0'
30
30
  spec.add_development_dependency 'rubocop', '~> 0.58'
31
31
  spec.add_development_dependency 'webmock', '~> 3.4'
32
+ spec.add_development_dependency 'pry'
32
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandadoc-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Carey
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-08-30 00:00:00.000000000 Z
12
+ date: 2018-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '3.4'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  description: Ruby API Wrapper for the PandaDoc API
99
113
  email:
100
114
  - mike@catchandrelease.com
@@ -114,7 +128,9 @@ files:
114
128
  - bin/console
115
129
  - bin/setup
116
130
  - lib/pandadoc/api.rb
131
+ - lib/pandadoc/api/client.rb
117
132
  - lib/pandadoc/api/document.rb
133
+ - lib/pandadoc/api/params_validator.rb
118
134
  - lib/pandadoc/api/template.rb
119
135
  - lib/pandadoc/api/version.rb
120
136
  - pandadoc-api.gemspec
@@ -138,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
154
  version: '0'
139
155
  requirements: []
140
156
  rubyforge_project:
141
- rubygems_version: 2.7.7
157
+ rubygems_version: 2.6.13
142
158
  signing_key:
143
159
  specification_version: 4
144
160
  summary: Ruby API Wrapper for the PandaDoc API