Class: PdfMage::Api::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/pdf_mage/api/app.rb

Overview

The PdfMage Sinatra API application, which has /status and /render endpoints that you can call to render PDFs from another server over HTTPS.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#authorize!Object

Since:

  • 0.1.0



39
40
41
42
# File 'lib/pdf_mage/api/app.rb', line 39

def authorize!
  return unless CONFIG.api_secret
  error(401, 'Unauthorized') unless params[:secret] && params[:secret].strip == CONFIG.api_secret
end

#error(code, message) ⇒ Object

Since:

  • 0.1.0



44
45
46
# File 'lib/pdf_mage/api/app.rb', line 44

def error(code, message)
  halt code, { result: 'error', message: message }.to_json
end

#required_param(key) ⇒ Object

Since:

  • 0.1.0



48
49
50
51
52
# File 'lib/pdf_mage/api/app.rb', line 48

def required_param(key)
  value = params[key]
  error(422, "Required parameter '#{key}' is missing") unless value && !value.empty?
  value
end