diff --git a/Gemfile.lock b/Gemfile.lock index 1fb7e6e..0971daf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,39 +1,39 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.3) - actionpack (= 5.0.3) + actioncable (5.0.6) + actionpack (= 5.0.6) nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.3) - actionpack (= 5.0.3) - actionview (= 5.0.3) - activejob (= 5.0.3) + actionmailer (5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.3) - actionview (= 5.0.3) - activesupport (= 5.0.3) + actionpack (5.0.6) + actionview (= 5.0.6) + activesupport (= 5.0.6) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.3) - activesupport (= 5.0.3) + actionview (5.0.6) + activesupport (= 5.0.6) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.3) - activesupport (= 5.0.3) + activejob (5.0.6) + activesupport (= 5.0.6) globalid (>= 0.3.6) - activemodel (5.0.3) - activesupport (= 5.0.3) - activerecord (5.0.3) - activemodel (= 5.0.3) - activesupport (= 5.0.3) + activemodel (5.0.6) + activesupport (= 5.0.6) + activerecord (5.0.6) + activemodel (= 5.0.6) + activesupport (= 5.0.6) arel (~> 7.0) - activesupport (5.0.3) + activesupport (5.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) @@ -41,7 +41,7 @@ GEM arel (7.1.4) bindex (0.5.0) builder (3.2.3) - byebug (9.0.6) + byebug (9.1.0) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -56,18 +56,18 @@ GEM railties (>= 3.2, < 5.2) erubis (2.7.0) execjs (2.7.0) - faraday (0.12.1) + faraday (0.13.1) multipart-post (>= 1.2, < 3) ffi (1.9.18) globalid (0.4.0) activesupport (>= 4.2.0) - hellosign-ruby-sdk (3.2.15) + hellosign-ruby-sdk (3.5.0) faraday mime-types multi_json - i18n (0.8.4) - jbuilder (2.6.4) - activesupport (>= 3.0.0) + i18n (0.8.6) + jbuilder (2.7.0) + activesupport (>= 4.2.0) multi_json (>= 1.2) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) @@ -78,52 +78,56 @@ GEM rb-inotify (~> 0.9, >= 0.9.7) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.5) + mail (2.6.6) mime-types (>= 1.16, < 4) method_source (0.8.2) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.10.2) - multi_json (1.12.1) + mini_portile2 (2.2.0) + minitest (5.10.3) + multi_json (1.12.2) multipart-post (2.0.0) nio4r (2.1.0) - nokogiri (1.7.2) - mini_portile2 (~> 2.1.0) + nokogiri (1.8.0) + mini_portile2 (~> 2.2.0) pg (0.21.0) - puma (3.9.0) + puma (3.10.0) rack (2.0.3) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.3) - actioncable (= 5.0.3) - actionmailer (= 5.0.3) - actionpack (= 5.0.3) - actionview (= 5.0.3) - activejob (= 5.0.3) - activemodel (= 5.0.3) - activerecord (= 5.0.3) - activesupport (= 5.0.3) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.3) + rails (5.0.6) + actioncable (= 5.0.6) + actionmailer (= 5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) + activemodel (= 5.0.6) + activerecord (= 5.0.6) + activesupport (= 5.0.6) + bundler (>= 1.3.0) + railties (= 5.0.6) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (5.0.3) - actionpack (= 5.0.3) - activesupport (= 5.0.3) + railties (5.0.6) + actionpack (= 5.0.6) + activesupport (= 5.0.6) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) - rb-fsevent (0.9.8) - rb-inotify (0.9.8) - ffi (>= 0.5.0) - sass (3.4.24) + rake (12.1.0) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + sass (3.5.1) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) @@ -138,14 +142,14 @@ GEM sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - thor (0.19.4) + thor (0.20.0) thread_safe (0.3.6) - tilt (2.0.7) + tilt (2.0.8) turbolinks (5.0.1) turbolinks-source (~> 5) turbolinks-source (5.0.3) @@ -186,4 +190,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.15.1 + 1.16.0.pre.2 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694..9f66846 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,11 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + before_action :client + + private + + def client + client = ApplicationRecord.initiate_client + end end diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb new file mode 100644 index 0000000..51b9a68 --- /dev/null +++ b/app/controllers/apps_controller.rb @@ -0,0 +1,47 @@ +class AppsController < ApplicationController + skip_before_action :verify_authenticity_token + + def info + app = client.get_api_app :client_id => params[:client_id] + + render json: app + end + + def list + app_list = client.get_api_apps :page => 2 + + render json: app_list + end + + def create + + white_labeling = { + "primary_button_color":"#778899", + "primary_button_text_color":"#ffffff" + } + + app = client.create_api_app( + :name => params[:app_name], + :domain => 'www.rubyonrails.com', + :white_labeling_options => white_labeling.to_json + ) + + render json: app + end + + def update + app = client.update_api_app( + :name => params[:app_name], + :client_id => params[:client_id] + ) + + render json: app + end + + def delete + client.delete_api_app :client_id => params[:client_id] + + flash[:notice] = "App deleted!" + redirect_to root_path + end +end diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb index d9d8284..deb810b 100644 --- a/app/controllers/callbacks_controller.rb +++ b/app/controllers/callbacks_controller.rb @@ -7,10 +7,26 @@ def index def create event = JSON.parse(params["json"], symbolize_names: true) + p event event_type = event[:event][:event_type] return "Hello API event received" if event_type == "callback_test" + p "******" + p "event type: #{event_type}" - id = event[:signature_request][:signature_request_id] + if event_type.include? "signature" + id = event[:signature_request][:signature_request_id] + elsif event_type.include? "template" + id = event[:template][:template_id] + end + + # if !event[:signature_request][:signature_request_id].nil? + # id = event[:signature_request][:signature_request_id] + # elsif !event[:template][:template_id].nil? + # id = event[:template][:template_id] + # end + + p "******" + p id case event_type when "signature_request_sent" @@ -25,6 +41,10 @@ def create when "signature_request_declined" Sign.find_by(signature_request_id: id, status: 'Declined') + when "template_created" + p "TEMPLATE CREATED" + when "template_error" + p "TEMPLATE ERROR" end end end diff --git a/app/controllers/embeddeds_controller.rb b/app/controllers/embeddeds_controller.rb index 2ceb230..0cb2c20 100644 --- a/app/controllers/embeddeds_controller.rb +++ b/app/controllers/embeddeds_controller.rb @@ -1,132 +1,30 @@ class EmbeddedsController < ApplicationController - skip_before_action :verify_authenticity_token + def index + end def template - client = Embedded.initiate_client - signature_event = client.create_embedded_signature_request_with_template( - test_mode: 1, - client_id: ENV['CLIENT_ID'], - template_id: 'e918bf31ce40b1a66b593992a9ebfcfde2c72648', - signers: [ - { - email_address: 'jen.young+1@hellosign.com', - name: 'Jen Test', - role: 'Client' - } - ] - ) - - @sign_url = render_url(signature_event) end def file_request - client = Embedded.initiate_client - - signature_event = client.create_embedded_signature_request( - test_mode: 1, - client_id: ENV['CLIENT_ID'], - subject: 'Embedded Signature Request with File', - message: 'Hey!', - signers: [ - { - email_address: 'jen.young+1@hellosign.com', - name: 'Jen Test' - } - ], - file_url: 'http://www.pdf995.com/samples/pdf.pdf', - ) - - @sign_url = render_url(signature_event) end def unclaimed_draft - client = Embedded.initiate_client - - signature_event = client.create_embedded_unclaimed_draft( - test_mode: 1, - client_id: ENV['CLIENT_ID'], - type: 'request_signature', - subject: 'Embedded Unclaimed Draft', - requester_email_address: 'jen.young@hellosign.com', - file_url: 'http://www.pdf995.com/samples/pdf.pdf', - is_for_embedded_signing: 1 - ) - - @sign_url = render_url(signature_event) end def unclaimed_draft_template - client = Embedded.initiate_client - - signature_event = client.create_embedded_unclaimed_draft_with_template( - test_mode: 1, - client_id: ENV['CLIENT_ID'], - template_id: 'e918bf31ce40b1a66b593992a9ebfcfde2c72648', - requester_email_address: 'jen.young@hellosign.com', - signing_redirect_url: 'http://www.google.com', - requesting_redirect_url: 'http://www.google.com', - signers: [ - { - email_address: 'jen.young+1@hellosign.com', - name: 'Jen Test', - role: 'Client' - } - ] - ) - - response = JSON.parse(signature_event.to_json, symbolize_names: true) - @sign_url = response[:raw_data][:claim_url] end def template_draft - client = Embedded.initiate_client - file = params[:file] + end - request = client.create_embedded_template_draft( - test_mode: 1, - client_id: ENV['CLIENT_ID'], - file_url: 'http://www.pdf995.com/samples/pdf.pdf', - title: 'Test title', - subject: 'test subject', - message: 'test message', - signer_roles: [ - { - name: 'Client', - order: 0 - }, - { - name: 'Client 2', - order: 1 - } - ], - merge_fields: '[ - { - "name":"Test Merge", - "type":"text" - }, - { - "name":"Test Merge 2", - "type":"text" - }]' + def edit_unclaimed_draft + @draft = client.edit_and_resend_unclaimed_draft( + :signature_request_id => '596e1b9288c7c726c603fc3080689e6c89c1a397', + :client_id => ENV['CLIENT_ID'], + :test_mode => true ) - - p request - p "*****" - p request.data['template_id'] - @sign_url = request.data['edit_url'] + p "***" + p @draft.claim_url end - private - - def render_url(response) - client = Embedded.initiate_client - - response_object = JSON.parse(response.to_json, symbolize_names: true) - signature_id = response_object[:raw_data][:signatures][0][:signature_id] - - get_url = client.get_embedded_sign_url :signature_id => signature_id - - url_response = JSON.parse(get_url.to_json, symbolize_names: true) - url_response[:raw_data][:sign_url] - end end diff --git a/app/controllers/signs_controller.rb b/app/controllers/signs_controller.rb index b2c7341..4239510 100644 --- a/app/controllers/signs_controller.rb +++ b/app/controllers/signs_controller.rb @@ -1,5 +1,6 @@ class SignsController < ApplicationController skip_before_action :verify_authenticity_token + before_action :client def index @@ -14,24 +15,21 @@ def index def account - client = Sign.initiate_client @account = client.get_account end def signature_request - client = Sign.initiate_client - request = client.get_signature_request :signature_request_id => params[:request_id] render json: request end def all_requests - client = Sign.initiate_client - @signatures = client.get_signature_requests :page_size => 2 + @signatures = client.get_signature_requests + + render json: @signatures end def send_request - client = Sign.initiate_client response = client.send_signature_request( :test_mode => 1, :title => 'Test Contract', @@ -43,7 +41,7 @@ def send_request :name => 'Jen', :order => 0 } - ], + ], # :form_fields_per_document => [ # [ # { @@ -78,10 +76,11 @@ def send_request data = JSON.parse(response.to_json, symbolize_names: true) id = data[:raw_data][:signatures][0][:signature_id] + + render json: response end def template_request - client = Sign.initiate_client client.send_signature_request_with_template( :test_mode => 1, :template_id => 'feb796545f869222c6bd67a6eb276a7573700704', @@ -109,36 +108,30 @@ def template_request end def reminder - client = Sign.initiate_client client.remind_signature_request :signature_request_id => params[:signature_id], :email_address => params[:email] redirect_to root_path end def update_email - # client = Sign.initiate_client - # client.update_signature_request( - # :signature_request_id => params[:signature_request_id], - # :signature_id => params[:signature_id], - # :email_address => params[:email] - # ) + client.update_signature_request( + :signature_request_id => '33e7a1d839e98797d633fb8b47247c4aa9a5936d', + :signature_id => '5064ca698bde9581ad75f6d62450eb4b', + :email_address => 'jen.young+1@hellosign.com' + ) end def cancel - client = Sign.initiate_client client.cancel_signature_request :signature_request_id => params[:request_id] redirect_to root_path end def file - client = Sign.initiate_client file_bin = client.signature_request_files :signature_request_id => params[:request_id], :get_url => true File.open("files.zip", "wb") do |file| file.write(file_bin) end end - - end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb new file mode 100644 index 0000000..90ae984 --- /dev/null +++ b/app/controllers/templates_controller.rb @@ -0,0 +1,7 @@ +class TemplatesController < ApplicationController + skip_before_action :verify_authenticity_token + + def update + @template = client.update_template_files :template_id =>'74cb63b17da0bc1541dbb6c4f6b2f10004ef0492', :file_url => 'http://che.org.il/wp-content/uploads/2016/12/pdf-sample.pdf', :message => 'updated using new endpoint!' + end +end diff --git a/app/models/app.rb b/app/models/app.rb new file mode 100644 index 0000000..cc6dc36 --- /dev/null +++ b/app/models/app.rb @@ -0,0 +1,2 @@ +class App < ApplicationRecord +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..a394fee 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,7 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + + def self.initiate_client + HelloSign::Client.new :api_key => ENV['HS_KEY'] + end end diff --git a/app/models/embedded.rb b/app/models/embedded.rb index 9085dab..3aa49f1 100644 --- a/app/models/embedded.rb +++ b/app/models/embedded.rb @@ -1,5 +1,2 @@ class Embedded < ApplicationRecord - def self.initiate_client - HelloSign::Client.new :api_key => ENV['HS_KEY'] - end end diff --git a/app/models/sign.rb b/app/models/sign.rb index 3a525f1..51ee28b 100644 --- a/app/models/sign.rb +++ b/app/models/sign.rb @@ -1,7 +1,2 @@ class Sign < ApplicationRecord - - def self.initiate_client - HelloSign::Client.new :api_key => ENV['HS_KEY'] - end - end diff --git a/app/models/template.rb b/app/models/template.rb new file mode 100644 index 0000000..8cffc45 --- /dev/null +++ b/app/models/template.rb @@ -0,0 +1,2 @@ +class Template < ApplicationRecord +end diff --git a/app/views/apps/create.html.erb b/app/views/apps/create.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/apps/info.html.erb b/app/views/apps/info.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/apps/list.html.erb b/app/views/apps/list.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/apps/update.html.erb b/app/views/apps/update.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/embeddeds/_iframe.html.erb b/app/views/embeddeds/_iframe.html.erb index 65f50ce..b48b4d3 100644 --- a/app/views/embeddeds/_iframe.html.erb +++ b/app/views/embeddeds/_iframe.html.erb @@ -15,6 +15,9 @@ messageListener: function(eventData){ if (eventData.event == 'signature_request_canceled') { document.getElementById("event").innerHTML = "SIGNATURE CANCELLED" + } else if (eventData.event == 'signature_request_signed') { + HelloSign.close() + document.location = "http://www.reuters.com" } } }) diff --git a/app/views/embeddeds/edit_unclaimed_draft.html.erb b/app/views/embeddeds/edit_unclaimed_draft.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/embeddeds/index.html.erb b/app/views/embeddeds/index.html.erb index 87f38ad..04667bf 100644 --- a/app/views/embeddeds/index.html.erb +++ b/app/views/embeddeds/index.html.erb @@ -16,4 +16,7 @@