Class: SidekoClient

Inherits:
Object
  • Object
show all
Defined in:
lib/one_doc.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key_auth: nil, base_url: 'https://app.onedoclabs.com') ⇒ SidekoClient

Returns a new instance of SidekoClient.



131
132
133
134
135
136
# File 'lib/one_doc.rb', line 131

def initialize(api_key_auth: nil, base_url: 'https://app.onedoclabs.com')
  @_base_url = base_url
  # register auth providers
  @_auth = {}
  @_auth[:"ApiKeyAuth"] = AuthKeyHeader.new(header_name: "x-api-key", val: api_key_auth)
end

Instance Method Details

#_client_with_auth(auth_names, **req_kwargs) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/one_doc.rb', line 138

def _client_with_auth(auth_names, **req_kwargs)
  http_client = HTTP
  auth_names.each do |auth_name|
    provider = @_auth[auth_name]
    http_client, req_kwargs = provider.add_auth(http_client, req_kwargs) if provider
  end
  
  return http_client, req_kwargs
end

#post_api_docs_generate(data) ⇒ Object

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/one_doc.rb', line 150

def post_api_docs_generate(data)
  _url = @_base_url + "/api/docs/generate"
  _kwargs = {
    params: {}
  }
  _http_client, _req_kwargs = self._client_with_auth(
    [:"ApiKeyAuth", ],
    **_kwargs
  )

  
  _response = _http_client.post(
    _url,
    json: data,
    **_req_kwargs
  )

  # Raise if not expected success code
  if _response.status != 200
    raise RequestError.new(
      method="post",
      url=_url,
      response=_response
    )
  end

  return _response
end

#post_api_docs_initiate(data) ⇒ Object

This endpoint creates a bucket for the html and all specified assets. It returns signed urls to the buckets.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/one_doc.rb', line 180

def post_api_docs_initiate(data)
  _url = @_base_url + "/api/docs/initiate"
  _kwargs = {
    params: {}
  }
  _http_client, _req_kwargs = self._client_with_auth(
    [:"ApiKeyAuth", ],
    **_kwargs
  )

  
  _response = _http_client.post(
    _url,
    json: data,
    **_req_kwargs
  )

  # Raise if not expected success code
  if _response.status != 200
    raise RequestError.new(
      method="post",
      url=_url,
      response=_response
    )
  end

  return _response.body.empty? ? '' : _response.parse
end