examples/api-samples/samples/sample31.rb in groupdocs-1.5.7 vs examples/api-samples/samples/sample31.rb in groupdocs-1.5.8
- old
+ new
@@ -71,20 +71,21 @@
# POST request
post '/sample31' do
# set variables
- set :client_id, params[:client_id]
- set :private_key, params[:private_key]
- set :template_guid, params[:template_guid]
+ set :client_id, params[:clientId]
+ set :private_key, params[:privateKey]
+ set :template_guid, params[:templateGuid]
set :name, params[:name]
set :country, params[:country]
set :city, params[:city]
set :street, params[:street]
set :email, params[:email]
set :callback, params[:callback]
- set :last_name, params[:last_name]
+ set :last_name, params[:lastName]
+ set :base_path, params[:basePath]
# Set download path
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
# Remove all files from download directory or create folder if it not there
@@ -96,19 +97,31 @@
begin
# check required variables
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
+
+ # Configure your access to API server
+ GroupDocs.configure do |groupdocs|
+ groupdocs.client_id = settings.client_id
+ groupdocs.private_key = settings.private_key
+ # Optionally specify API server and version
+ groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
+ end
+
# Write client and private key to the file for callback job
if settings.callback[0]
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
# white space is required
out_file.write("#{settings.client_id} ")
out_file.write("#{settings.private_key}")
out_file.close
end
-
+ if settings.last_name.empty?
+ settings.last_name = 'test'
+ end
file = nil
# Create instance of File
file = GroupDocs::Storage::File.new({:guid => settings.template_guid})
# Raise exception if something went wrong
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
@@ -125,66 +138,64 @@
# Create Field instance and fill the fields
datasource.fields = enteredData.map { |key, value| GroupDocs::DataSource::Field.new(name: key, type: :text, values: Array.new() << value) }
# Adds datasource.
- datasource.add!({:client_id => settings.client_id, :private_key => settings.private_key})
+ datasource.add!()
# Creates new job to merge datasource into document.
- job = document.datasource!(datasource, {:new_type => "pdf"}, {:client_id => settings.client_id, :private_key => settings.private_key})
+ job = document.datasource!(datasource, {:new_type => "pdf"})
sleep 10 # wait for merge and convert
# Returns an hash of input and output documents associated to job.
- jobInfo = job.documents!({:client_id => settings.client_id, :private_key => settings.private_key})
+ jobInfo = job.documents!()
# Creates new document to envelope
document = jobInfo[:inputs][0].outputs[0].to_document
# Creates envelope using user id and entered by user name
envelope = GroupDocs::Signature::Envelope.new
envelope.name = jobInfo[:inputs][0].outputs[0].name
- envelope.create!({}, {:client_id => settings.client_id, :private_key => settings.private_key})
+ envelope.create!({})
# Adds uploaded document to envelope
- envelope.add_document!(document, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
+ envelope.add_document!(document, {})
# Get role list for current user
- roles = GroupDocs::Signature::Role.get!({}, {client_id: settings.client_id, private_key: settings.private_key})
+ roles = GroupDocs::Signature::Role.get!({})
# Creates new recipient
recipient = GroupDocs::Signature::Recipient.new
- recipient.email = 'test@test.com'
- recipient.first_name = 'test'
- recipient.last_name = 'test'
+ recipient.email = settings.email
+ recipient.first_name = settings.name
+ recipient.last_name = settings.last_name
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
# Adds recipient to envelope
- envelope.add_recipient!(recipient, {client_id: settings.client_id, private_key: settings.private_key})
-
- #Get field
- fieldGet = GroupDocs::Signature::Field.get!({},{client_id: settings.client_id, private_key: settings.private_key}).detect { |f| f.type == :signature }
- fieldGet.location = { location_x: 0.15,
- location_y: 0.73,
- location_width: 150,
- location_height: 50,
- page: 1 }
-
- #Get document
- documentGet = envelope.documents!({}, {client_id: settings.client_id, private_key: settings.private_key}).first
-
+ envelope.add_recipient!(recipient)
#Get recipients
- recipientGet = envelope.recipients!({},{client_id: settings.client_id, private_key: settings.private_key}).first
+ recipientGet = envelope.recipients!({}).first
- # Add field to envelope
- addField = envelope.add_field!(fieldGet, documentGet, recipientGet, {}, {client_id: settings.client_id, private_key: settings.private_key})
+ # Send envelope
+ envelope.send!({:callbackUrl => settings.callback})
+ #Get url from request
+ case settings.base_path
- # Send envelope
- envelope.send!(settings.callback, {client_id: settings.client_id, private_key: settings.private_key})
+ when 'https://stage-api-groupdocs.dynabic.com'
+ url = "http://stage-apps-groupdocs.dynabic.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
+ when 'https://dev-api-groupdocs.dynabic.com'
+ url = "http://dev-apps-groupdocs.dynabic.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
+ else
+ url = "https://apps.groupdocs.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
+ end
+ # Add the signature in url
+ iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
+
# Make iframe
- iframe = "<iframe src='https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipientGet.id}' frameborder='0' width='720' height='600'></iframe>"
+ iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
rescue Exception => e
err = e.message
end