Last active
August 29, 2015 14:27
-
-
Save Chadh13/3ba612a4bbf0c0e64f39 to your computer and use it in GitHub Desktop.
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 HellosignController < ApplicationController | |
skip_before_action :verify_authenticity_token, only: [:callbacks] | |
def callbacks | |
respond_to do |format| | |
format.json { render json: 'Hello API Event Received', status: 200 } | |
end | |
end | |
def create_embedded_template | |
client = HelloSign::Client.new :api_key => ENV['HELLOSIGN_API_KEY'] | |
request = client.create_embedded_template_draft( | |
:test_mode => 1, | |
:client_id => ENV['HELLOSIGN_CLIENT_ID'], | |
:files => @template.file, | |
:title => @template.title, | |
:subject => @template.subject, | |
:message => @template.message, | |
:signer_roles => [ | |
{ | |
:name => 'Test Role', | |
:order => 1 | |
}, | |
{ | |
:name => 'Test Role 2', | |
:order => 1 | |
} | |
], | |
:cc_roles => ['Test CC Role'], | |
:merge_fields => '[{"name":"Test Merge","type":"text"},{"name":"Test Merge 2","type":"text"}]' | |
) | |
new_template_id = request.data['template_id'] | |
edit_url = request.data['edit_url'] | |
is_embedded_draft = request.data['is_embedded_draft'] | |
end | |
end |
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
<%= form_for(@template, html: {class: 'signup_form well template_form col-md-4 col-md-offset-4'}, multipart: true) do |f| %> | |
<% if @template.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@template.errors.count, "error") %> prohibited this template from being saved:</h2> | |
<ul> | |
<% @template.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :title %><br> | |
<%= f.text_field :title %> | |
</div> | |
<div class="field"> | |
<%= f.label :subject %><br> | |
<%= f.text_field :subject %> | |
</div> | |
<div class="field"> | |
<%= f.label :message %><br> | |
<%= f.text_area :message %> | |
</div> | |
<div class="field"> | |
<%= f.label :file %><br> | |
<%= f.file_field :file %> | |
</div> | |
<div class="actions"> | |
<%= f.submit 'Start Template', class: 'btn btn-primary' %> | |
</div> | |
<br> | |
<%= link_to 'Back', templates_path %> | |
<% end %> |
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 TemplatesController < ApplicationController | |
before_action :set_template, only: [:show, :edit, :update, :destroy] | |
# GET /templates | |
# GET /templates.json | |
def index | |
@templates = Template.all | |
end | |
# GET /templates/1 | |
# GET /templates/1.json | |
def show | |
end | |
# GET /templates/new | |
def new | |
@template = Template.new | |
end | |
# GET /templates/1/edit | |
def edit | |
end | |
# POST /templates | |
# POST /templates.json | |
def create | |
@template = Template.new(template_params) | |
respond_to do |format| | |
if @template.save | |
format.html { redirect_to @template, notice: 'Template was successfully created.' } | |
format.json { render :show, status: :created, location: @template } | |
else | |
format.html { render :new } | |
format.json { render json: @template.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /templates/1 | |
# PATCH/PUT /templates/1.json | |
def update | |
respond_to do |format| | |
if @template.update(template_params) | |
format.html { redirect_to @template, notice: 'Template was successfully updated.' } | |
format.json { render :show, status: :ok, location: @template } | |
else | |
format.html { render :edit } | |
format.json { render json: @template.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /templates/1 | |
# DELETE /templates/1.json | |
def destroy | |
@template.destroy | |
respond_to do |format| | |
format.html { redirect_to templates_url, notice: 'Template was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_template | |
@template = Template.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def template_params | |
params.require(:template).permit(:title, :subject, :message, :file) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment