cloudpdf 1.0.0 → 1.0.1
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 +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/cloudpdf.gemspec +29 -0
- data/lib/cloudpdf/client.rb +169 -0
- data/lib/cloudpdf/version.rb +3 -0
- data/lib/cloudpdf.rb +10 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf33fa66c347e6534f5986b74da2d041a891f74498cb2e17e348ba0fd4176690
|
4
|
+
data.tar.gz: eb37060fb4d00500513f0e34793246501ff2e92fa86122d81d80eefb2be9aba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d7bff3a3167af0751f7d30e481059d135d61bc46988754dcc68fc20e5d05635b5f985979fdf39d1ecd4883617811c581499e2740aee4396061b251d40c0244d
|
7
|
+
data.tar.gz: 95e40f01ae8c2d393f19e382a25a0fea2d6fb2e84f78a931e4ca065926ccd102ce97338425d8c88f67ee3a14107bd4459a218dd7c9976c9bfc9255c2683c7ca0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cloudpdf (1.0.0)
|
5
|
+
httparty
|
6
|
+
jwt
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
httparty (0.20.0)
|
12
|
+
mime-types (~> 3.0)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
jwt (2.3.0)
|
15
|
+
mime-types (3.4.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2022.0105)
|
18
|
+
multi_xml (0.6.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
arm64-darwin-21
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
cloudpdf!
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.3.7
|
data/cloudpdf.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "cloudpdf"
|
3
|
+
spec.version = "1.0.1"
|
4
|
+
spec.authors = ["Bob Singor"]
|
5
|
+
spec.email = ["hello@cloudpdf.io"]
|
6
|
+
|
7
|
+
spec.summary = "Ruby wrapper for the CloudPDF API"
|
8
|
+
spec.homepage = "https://github.com/cloudpdf-io/cloudpdf-ruby"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
11
|
+
|
12
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
# spec.metadata["source_code_uri"] = ""
|
16
|
+
# spec.metadata["changelog_uri"] = ""
|
17
|
+
|
18
|
+
spec.add_dependency "httparty"
|
19
|
+
spec.add_dependency "jwt"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module CloudPDF
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@api_key = config.fetch(:api_key)
|
7
|
+
@cloud_name = config.fetch(:cloud_name, nil)
|
8
|
+
@signing_secret = config.fetch(:signing_secret, nil)
|
9
|
+
@signed = false
|
10
|
+
|
11
|
+
if !@signing_secret.nil? && !@cloud_name.nil?
|
12
|
+
@signed = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def setSigned(enabled)
|
17
|
+
if @signing_secret.nil? || @cloud_name.nil?
|
18
|
+
raise "signing_secret and cloud_name should be set"
|
19
|
+
end
|
20
|
+
|
21
|
+
@signed = enabled
|
22
|
+
end
|
23
|
+
|
24
|
+
def account
|
25
|
+
get_response("APIV2GetAccount", "/account")
|
26
|
+
end
|
27
|
+
|
28
|
+
def auth
|
29
|
+
get_response("APIV2GetAuth", "/account")
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_document(payload)
|
33
|
+
post_response("APIV2CreateDocument", "/documents", payload)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_document(id)
|
37
|
+
get_response("APIV2GetDocument", "/documents/" + id, {id: id})
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_document(id, payload)
|
41
|
+
put_response("APIV2UpdateDocument", "/documents/" + id, {id: id, **payload})
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_document(id)
|
45
|
+
delete_response("APIV2DeleteDocument", "/documents/" + id, {id: id})
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_new_file_version(id, payload)
|
49
|
+
post_response(
|
50
|
+
"APIV2CreateDocumentFile",
|
51
|
+
"/documents/" + id + "/files",
|
52
|
+
{id: id, **payload}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def upload_document_file_complete(id, fileId)
|
57
|
+
patch_response(
|
58
|
+
"APIV2PatchDocumentFile",
|
59
|
+
"/documents/" + id + "/files/" + fileId,
|
60
|
+
{id: id, fileId: fileId, uploadCompleted: true}
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_document_file(documentId, fileId)
|
65
|
+
get_response("APIV2GetDocumentFile", "/documents/" + documentId + "/files/" + fileId, {id: documentId, fileId: fileId})
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_viewer_token(params, expires_in = 60*60)
|
69
|
+
get_signed_token("APIGetDocument", params, expires_in)
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_webhook(payload)
|
73
|
+
post_response("APIV2CreateWebhook", "/webhooks", payload)
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_webhook(id)
|
77
|
+
get_response("APIV2GetWebhook", "/webhooks/" + id, {id: id})
|
78
|
+
end
|
79
|
+
|
80
|
+
def update_webhook(id, payload)
|
81
|
+
put_response("APIV2UpdateWebhook", "/webhooks/" + id, {id: id, **payload})
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_webhook(id)
|
85
|
+
delete_response("APIV2DeleteWebhook", "/webhooks/" + id, {id: id})
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_webhooks()
|
89
|
+
get_response("APIV2GetWebhooks", "/webhooks")
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
CLOUDPDF_API_ENDPOINT = "https://api.cloudpdf.io/v2"
|
95
|
+
|
96
|
+
def get_signed_token(function_name, params, expires_in = 15)
|
97
|
+
exp = Time.now.to_i + expires_in
|
98
|
+
payload = { function: function_name, params: params, exp: exp }
|
99
|
+
token = JWT.encode payload, @signing_secret, 'HS256', { :typ => "JWT", :kid => @cloud_name }
|
100
|
+
|
101
|
+
return token
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_headers(function_name, params)
|
105
|
+
if(@signed)
|
106
|
+
token = get_signed_token(function_name, params)
|
107
|
+
else
|
108
|
+
token = @api_key
|
109
|
+
end
|
110
|
+
|
111
|
+
return { 'Content-Type': 'application/json', 'X-Authorization' => token }
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_response(function_name, url, payload = {})
|
115
|
+
response = HTTParty.get("#{CLOUDPDF_API_ENDPOINT}#{url}",
|
116
|
+
timeout: 5,
|
117
|
+
headers: get_headers(function_name, payload)
|
118
|
+
)
|
119
|
+
body = JSON.parse(response.body)
|
120
|
+
return {"error" => body['errorDescription'], "code" => response.code} if response.code >= 400
|
121
|
+
return body
|
122
|
+
end
|
123
|
+
|
124
|
+
def delete_response(function_name, url, payload = {})
|
125
|
+
response = HTTParty.delete("#{CLOUDPDF_API_ENDPOINT}#{url}",
|
126
|
+
timeout: 5,
|
127
|
+
headers: get_headers(function_name, payload)
|
128
|
+
)
|
129
|
+
body = JSON.parse(response.body)
|
130
|
+
return {"error" => body['errorDescription'], "code" => response.code} if response.code >= 400
|
131
|
+
return body
|
132
|
+
end
|
133
|
+
|
134
|
+
def patch_response(function_name, url, payload)
|
135
|
+
response = HTTParty.patch("#{CLOUDPDF_API_ENDPOINT}#{url}",
|
136
|
+
body: payload.to_json,
|
137
|
+
timeout: 5,
|
138
|
+
headers: get_headers(function_name, payload)
|
139
|
+
)
|
140
|
+
body = JSON.parse(response.body)
|
141
|
+
return {"error" => body['errorDescription'], "code" => response.code} if response.code >= 400
|
142
|
+
return body
|
143
|
+
end
|
144
|
+
|
145
|
+
def put_response(function_name, url, payload)
|
146
|
+
response = HTTParty.put("#{CLOUDPDF_API_ENDPOINT}#{url}",
|
147
|
+
body: payload.to_json,
|
148
|
+
timeout: 5,
|
149
|
+
headers: get_headers(function_name, payload)
|
150
|
+
)
|
151
|
+
body = JSON.parse(response.body)
|
152
|
+
return {"error" => body['errorDescription'], "code" => response.code} if response.code >= 400
|
153
|
+
return body
|
154
|
+
end
|
155
|
+
|
156
|
+
def post_response(function_name, url, payload)
|
157
|
+
response = HTTParty.post("#{CLOUDPDF_API_ENDPOINT}#{url}",
|
158
|
+
body: payload.to_json,
|
159
|
+
timeout: 5,
|
160
|
+
headers: get_headers(function_name, payload)
|
161
|
+
)
|
162
|
+
body = JSON.parse(response.body)
|
163
|
+
return {"error" => body['errorDescription'], "code" => response.code} if response.code >= 400
|
164
|
+
return body
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
data/lib/cloudpdf.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudpdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Singor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: jwt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- hello@cloudpdf.io
|
@@ -45,7 +45,13 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
48
50
|
- LICENSE
|
51
|
+
- cloudpdf.gemspec
|
52
|
+
- lib/cloudpdf.rb
|
53
|
+
- lib/cloudpdf/client.rb
|
54
|
+
- lib/cloudpdf/version.rb
|
49
55
|
homepage: https://github.com/cloudpdf-io/cloudpdf-ruby
|
50
56
|
licenses:
|
51
57
|
- MIT
|