class Py3oFusion

Public Class Methods

new(endpoint, options = {}) click to toggle source
# File lib/py3o_fusion.rb, line 6
def initialize(endpoint, options = {})
  @endpoint = endpoint
  @payload = {}
  @image_mapping = {}
  @options = options
end

Public Instance Methods

data(data) click to toggle source
# File lib/py3o_fusion.rb, line 18
def data(data)
  @data = data
  self
end
generate_pdf(path) click to toggle source
# File lib/py3o_fusion.rb, line 29
def generate_pdf(path)
  response = post
  if response.code == 200
    store path, response.body
  else
    error = JSON.parse(response.body)
    raise Error.new "Error generating PDF: #{error['reasons']}"
  end
end
static_image(name, file) click to toggle source
# File lib/py3o_fusion.rb, line 23
def static_image(name, file)
  @payload[name.to_sym] = File.open(file)
  @image_mapping[name.to_sym] = "staticimage.#{name}"
  self
end
template(template) click to toggle source
# File lib/py3o_fusion.rb, line 13
def template(template)
  @payload[:tmpl_file] = File.open(template)
  self
end

Private Instance Methods

payload() click to toggle source
# File lib/py3o_fusion.rb, line 40
def payload
  @payload.merge({
    targetformat: "pdf",
    datadict: @data.to_json,
    image_mapping: @image_mapping.to_json
  })
end
post() click to toggle source
# File lib/py3o_fusion.rb, line 48
def post
  HTTParty.post @endpoint, @options.merge(body: payload)
end
store(path, content) click to toggle source
# File lib/py3o_fusion.rb, line 52
def store(path, content)
  File.open(path, 'wb') { |file| file.write(content) }
end