Created
February 20, 2016 01:24
-
-
Save PatrickatPaperlessPCS/24c39edbd25a3a30d5c2 to your computer and use it in GitHub Desktop.
Updated Templates.rb 2/19 1900 CST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Template < ActiveRecord::Base | |
require 'blitline' | |
has_attached_file :attachment1, default_url: "/images/missing.png" | |
validates_attachment_content_type :attachment1, content_type: [/image/, "application/pdf"], path: '/templates', url: '/templates' | |
belongs_to :user | |
has_one :signature_position | |
accepts_nested_attributes_for :signature_position | |
after_create :creation_email, :blitline_job | |
after_update :update_email | |
def creation_email | |
UserMailer.creation_email(user_id).deliver_later | |
end | |
def update_email | |
UserMailer.update_email(user_id).deliver_later | |
end | |
validate :template_count_within_limit, :on => :create | |
def template_count_within_limit | |
if self.user.templates(:reload).count >= 100 | |
errors.add(:base, "Exceeded template limit contact us at [email protected] to upgrade") | |
end | |
def blitline_job | |
job_data = { | |
"application_id": "0gy-omTDaj-kfNJ4QHV_rQg", | |
"src" => attachment1.url, | |
"src_type": "smart_image", | |
"wait_retry_delay" => 3, | |
"retry_postback" => true, | |
"v": 1.22, | |
"functions": [ | |
{ | |
"name": "resize_to_fit", | |
"params": { | |
"width": 1500, | |
}, | |
"save": { | |
"image_identifier": "external_sample_1", | |
"png_quant": true, | |
"extension": "png", | |
"s3_destination" => { "key" => "testing", "bucket" => "esignhealthdocumentimages" } # push to your S3 bucket | |
} | |
} | |
] | |
} | |
http = Net::HTTP.new("api.blitline.com", 80) | |
request = Net::HTTP::Post.new("http://api.blitline.com/job") | |
request.set_form_data({"json" => JSON.dump(job_data)}) | |
http.request(request) do |response| | |
if response.is_a?(Net::HTTPSuccess) | |
output = response.read_body | |
else | |
output = "Error #{response.read_body}" | |
end | |
puts "result of blitline job" | |
puts output | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment