Class: RightSignature::RailsStyle
- Inherits:
-
Connection
- Object
- Connection
- RightSignature::RailsStyle
- Defined in:
- lib/rightsignature/rails_style.rb
Instance Attribute Summary
Attributes inherited from Connection
#configuration, #oauth_connection, #token_connection
Instance Method Summary collapse
- #document_details(guid) ⇒ Object
- #prepackage_and_send(guid, roles, options) ⇒ Object
-
#template_details(guid) ⇒ Object
TODO: Copy pasta.
Methods inherited from Connection
api_token_keys, #check_credentials, #delete, #get, #has_api_token?, #has_oauth_credentials?, #initialize, oauth_keys, #parse_response, #post, #put, #site
Methods included from Template
#generate_build_url, #prefill, #prepackage, #send_as_embedded_signers, #send_template, #templates_list, #trash_template
Methods included from Helpers
#array_to_acceptable_names_hash
Methods included from Account
#add_user, #usage_report, #user_details
Methods included from Document
#documents_batch_details, #documents_list, #extend_document_expiration, #generate_document_redirect_url, #get_document_signer_links_for, #send_document, #send_document_from_data, #send_document_from_file, #send_document_from_url, #send_reminder, #trash_document, #update_document_tags
Constructor Details
This class inherits a constructor from RightSignature::Connection
Instance Method Details
#document_details(guid) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rightsignature/rails_style.rb', line 55 def document_details guid doc = super(guid)[:document] = doc.delete(:tags) doc[:metadata] = TagsHelper. doc[:tags] = TagsHelper. # Convert a deeply nested array of objects into a normal hash # Note: Must check if it's a deeply nested hash instead, since that is what occurs # for single-item XLM "arrays" # {..., recipients: {recipient: [{...},{...}]}} => {..., recipients: {...: {...}, ...:{...}}} tmp = doc[:recipients] && (doc[:recipients][:recipient].is_a?(Hash) ? [doc[:recipients][:recipient]] : doc[:recipients][:recipient]) doc[:recipients] = tmp.reduce({}){|h, v| h[v[:role_id]] = v and h} if tmp tmp = doc[:audit_trails] && (doc[:audit_trails][:audit_trail].is_a?(Hash) ? [doc[:audit_trails][:audit_trail]] : doc[:audit_trails][:audit_trail]) doc[:audit_trails] = tmp.reduce({}){|h, v| h[v[:timestamp]] = v and h} if tmp tmp = doc[:form_fields] && (doc[:form_fields][:form_field].is_a?(Hash) ? [doc[:form_fields][:form_field]] : doc[:form_fields][:form_field]) doc[:form_fields] = tmp.reduce({}){|h, v| h[v[:name]] = v and h} if tmp # Extract a few fields from a deeply nested array tmp = doc[:pages] && doc[:pages][:page].is_a?(Hash) ? doc[:pages][:page] : doc[:pages][:page].first if tmp %i(original_template_guid original_template_filename).each do |sym| doc[sym] = tmp[sym] end end doc.delete(:pages) %i(original_url pdf_url thumbnail_url large_url signed_pdf_url).each do |sym| doc[sym] = CGI.unescape doc[sym] if doc[sym] end doc end |
#prepackage_and_send(guid, roles, options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rightsignature/rails_style.rb', line 5 def prepackage_and_send guid, roles, # These conversions are basically from Rails-style structures to XML-style structures # Convert hashes to array-of-hashes # {k1: v1, k2: v2} => [{k1: v1}, {k2: v2}] [:merge_fields] = (.delete(:merge_fields)||{}).collect{|k,v| {k => v}} roles = roles.collect{|k,v| {k => v}} [:tags] = ([:tags]||[]) + (.delete(:metadata)||{}).collect{|k,v| {k => v} if v && ! v.to_s.strip.empty?}.select{|h| ! h.nil?} # TODO: Resolve RS choking on anything a HashWithIndifferentAccess super guid, roles, end |
#template_details(guid) ⇒ Object
TODO: Copy pasta
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rightsignature/rails_style.rb', line 24 def template_details guid doc = super(guid)[:template] = doc.delete(:tags) doc[:metadata] = TagsHelper. doc[:tags] = TagsHelper. # Convert a deeply nested array of objects into a normal hash # Note: Must check if it's a deeply nested hash instead, since that is what occurs # for single-item XLM "arrays" # {..., recipients: {recipient: [{...},{...}]}} => {..., recipients: {...: {...}, ...:{...}}} tmp = doc[:roles][:role].is_a?(Hash) ? [doc[:roles][:role]] : doc[:roles][:role] doc[:roles] = tmp.reduce({}){|h, v| h[v[:document_role_id]] = v and h} tmp = doc[:merge_fields][:merge_field].is_a?(Hash) ? [doc[:merge_fields][:merge_field]] : doc[:merge_fields][:merge_field] doc[:merge_fields] = tmp.reduce({}){|h, v| h[v[:name]] = v and h} # Extract a few fields from a deeply nested array tmp = doc[:pages][:page].is_a?(Hash) ? doc[:pages][:page] : doc[:pages][:page].first %i(original_template_guid original_template_filename).each do |sym| doc[sym] = tmp[sym] end doc.delete(:pages) %i(thumbnail_url).each do |sym| doc[sym] = CGI.unescape doc[sym] end doc end |