Class: Clicksign::API::Document

Inherits:
Object
  • Object
show all
Extended by:
Requests
Defined in:
lib/clicksign/api/document.rb

Constant Summary collapse

REQUEST_PATH =
'/api/v1/documents/'
ATTRIBUTES =
[:path, :deadline_at, :auto_close, :locale, :content_base64]

Class Method Summary collapse

Methods included from Requests

conn, get, post

Class Method Details

.body(params) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/clicksign/api/document.rb', line 19

def body(params)
  params = params.transform_keys(&:to_sym)

  document = ATTRIBUTES.each.with_object({}) do |attribute, hash|
    hash[attribute] = params[attribute] if params.has_key?(attribute)
  end

  if params.has_key?(:file)
    content_base64 = Base64.encode64(File.read(params[:file]))
    document[:content_base64] = "data:application/pdf;base64,#{content_base64}"
  end

  body = { document: document }
end

.create(token:, params: {}) ⇒ Object



10
11
12
# File 'lib/clicksign/api/document.rb', line 10

def create(token:, params: {})
  post(REQUEST_PATH, body(params), token)
end

.find(token:, params:) ⇒ Object



14
15
16
17
# File 'lib/clicksign/api/document.rb', line 14

def find(token:, params:)
  params = params.transform_keys(&:to_sym)
  get(REQUEST_PATH + params[:key], token)
end