one_doc 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/one_doc.rb +209 -0
  3. metadata +57 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c3b61eb7ce634a89803c4152ba9caf7d8caae0292d22b77586245e0e5dfdda8
4
+ data.tar.gz: 160026145927a3e9550a8b8a1e99bd3645eff975eba4d253162a382e39f5154b
5
+ SHA512:
6
+ metadata.gz: 831e7b0508c78cb9c9548a2c56d034a1c6f423f281a98d7cc123e32011e2648d4173137d104db738f4ab575927e0ad827ac84b4a660be6e1ea80890d41e0f386
7
+ data.tar.gz: 0ee23781314bc38fcf2e4b448f7c851850258964850be70bdce66a4fff8b189addd3272df937cee712530cfd11fe94be34b924b6dd59df65a52418c2228fdb37
data/lib/one_doc.rb ADDED
@@ -0,0 +1,209 @@
1
+ # Generated by Sideko (sideko.dev)
2
+ # frozen_string_literal: true
3
+ require 'json'
4
+ require 'http'
5
+
6
+ class RequestError < StandardError
7
+ attr_reader :status_code, :method, :url, :data, :response
8
+
9
+ def initialize(method, url, response)
10
+ @status_code = response.status
11
+ @method = method
12
+ @url = url
13
+ begin
14
+ @data = response.parse
15
+ rescue
16
+ @data = nil
17
+ end
18
+ @response = response
19
+
20
+ super("received #{status_code} from #{method} #{url} with #{message}")
21
+ end
22
+ end
23
+
24
+ module AuthProvider
25
+ def add_auth(http_client, req_kwargs)
26
+ raise NotImplementedError, "You must implement the 'add_auth' method"
27
+ end
28
+ end
29
+
30
+ class AuthBasic
31
+ include AuthProvider
32
+
33
+ attr_accessor :username, :password
34
+
35
+ def initialize(username: nil, password: nil)
36
+ @username = username
37
+ @password = password
38
+ end
39
+
40
+ def add_auth(http_client, req_kwargs)
41
+ if !@username.nil? && !@password.nil?
42
+ http_client = http_client.basic_auth(user: @username, pass: @password)
43
+ end
44
+
45
+ return http_client, req_kwargs
46
+ end
47
+ end
48
+
49
+ class AuthBearer
50
+ include AuthProvider
51
+
52
+ attr_accessor :val
53
+
54
+ def initialize(val: nil)
55
+ @val = val
56
+ end
57
+
58
+ def add_auth(http_client, req_kwargs)
59
+ if !@val.nil?
60
+ headers = req_kwargs.fetch(:headers, {})
61
+ headers["Authorization"] = "Bearer " + @val
62
+ req_kwargs[:headers] = headers
63
+ end
64
+
65
+ return http_client, req_kwargs
66
+ end
67
+ end
68
+
69
+ class AuthKeyQuery
70
+ include AuthProvider
71
+
72
+ attr_accessor :query_name, :val
73
+
74
+ def initialize(query_name: nil, val: nil)
75
+ @query_name = query_name
76
+ @val = val
77
+ end
78
+
79
+ def add_auth(http_client, req_kwargs)
80
+ if !val.nil?
81
+ params = req_kwargs.fetch(:params, {})
82
+ params[query_name] = val
83
+ req_kwargs[:params] = params
84
+ end
85
+
86
+ return http_client, req_kwargs
87
+ end
88
+ end
89
+
90
+ class AuthKeyHeader
91
+ include AuthProvider
92
+
93
+ attr_accessor :header_name, :val
94
+
95
+ def initialize(header_name: nil, val: nil)
96
+ @header_name = header_name
97
+ @val = val
98
+ end
99
+
100
+ def add_auth(http_client, req_kwargs)
101
+ if !@val.nil?
102
+ headers = req_kwargs.fetch(:headers, {})
103
+ headers[@header_name] = @val
104
+ req_kwargs[:headers] = headers
105
+ end
106
+
107
+ return http_client, req_kwargs
108
+ end
109
+ end
110
+
111
+ class AuthKeyCookie
112
+ include AuthProvider
113
+
114
+ attr_accessor :cookie_name, :val
115
+
116
+ def initialize(cookie_name: nil, val: nil)
117
+ @cookie_name = cookie_name
118
+ @val = val
119
+ end
120
+
121
+ def add_auth(http_client, req_kwargs)
122
+ if !@val.nil?
123
+ http_client = http_client.cookies(@cookie_name => @val)
124
+ end
125
+
126
+ return http_client, req_kwargs
127
+ end
128
+ end
129
+
130
+ class SidekoClient
131
+ def initialize(api_key_auth: nil, base_url: 'https://app.onedoclabs.com')
132
+ @_base_url = base_url
133
+ # register auth providers
134
+ @_auth = {}
135
+ @_auth[:"ApiKeyAuth"] = AuthKeyHeader.new(header_name: "x-api-key", val: api_key_auth)
136
+ end
137
+
138
+ def _client_with_auth(auth_names, **req_kwargs)
139
+ http_client = HTTP
140
+ auth_names.each do |auth_name|
141
+ provider = @_auth[auth_name]
142
+ http_client, req_kwargs = provider.add_auth(http_client, req_kwargs) if provider
143
+ end
144
+
145
+ return http_client, req_kwargs
146
+ end
147
+
148
+
149
+ # This route is responsible for generating a PDF from a bucket. It expects a JSON body with details of the bucket, user credentials, and PDF generation options.
150
+ def post_api_docs_generate(data)
151
+ _url = @_base_url + "/api/docs/generate"
152
+ _kwargs = {
153
+ params: {}
154
+ }
155
+ _http_client, _req_kwargs = self._client_with_auth(
156
+ [:"ApiKeyAuth", ],
157
+ **_kwargs
158
+ )
159
+
160
+
161
+ _response = _http_client.post(
162
+ _url,
163
+ json: data,
164
+ **_req_kwargs
165
+ )
166
+
167
+ # Raise if not expected success code
168
+ if _response.status != 200
169
+ raise RequestError.new(
170
+ method="post",
171
+ url=_url,
172
+ response=_response
173
+ )
174
+ end
175
+
176
+ return _response
177
+ end
178
+
179
+ # This endpoint creates a bucket for the html and all specified assets. It returns signed urls to the buckets.
180
+ def post_api_docs_initiate(data)
181
+ _url = @_base_url + "/api/docs/initiate"
182
+ _kwargs = {
183
+ params: {}
184
+ }
185
+ _http_client, _req_kwargs = self._client_with_auth(
186
+ [:"ApiKeyAuth", ],
187
+ **_kwargs
188
+ )
189
+
190
+
191
+ _response = _http_client.post(
192
+ _url,
193
+ json: data,
194
+ **_req_kwargs
195
+ )
196
+
197
+ # Raise if not expected success code
198
+ if _response.status != 200
199
+ raise RequestError.new(
200
+ method="post",
201
+ url=_url,
202
+ response=_response
203
+ )
204
+ end
205
+
206
+ return _response.body.empty? ? '' : _response.parse
207
+ end
208
+
209
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: one_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sideko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.1
27
+ description: Onedoc is the document API for developers.
28
+ email: team@sideko.dev
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/one_doc.rb
34
+ homepage:
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.3.5
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: one_doc 0.1.0
57
+ test_files: []