docu_sign 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +20 -0
  7. data/Rakefile +1 -0
  8. data/docu_sign.example.yml +4 -0
  9. data/docu_sign.gemspec +36 -0
  10. data/lib/docu_sign/anchor_tab.rb +29 -0
  11. data/lib/docu_sign/authentication_status.rb +16 -0
  12. data/lib/docu_sign/builder/anchor_builder.rb +17 -0
  13. data/lib/docu_sign/builder/base.rb +27 -0
  14. data/lib/docu_sign/builder/document_builder.rb +16 -0
  15. data/lib/docu_sign/builder/notification_builder.rb +16 -0
  16. data/lib/docu_sign/builder/recipient_builder.rb +17 -0
  17. data/lib/docu_sign/builder/tab_builder.rb +30 -0
  18. data/lib/docu_sign/cacert.pem +3390 -0
  19. data/lib/docu_sign/client.rb +98 -0
  20. data/lib/docu_sign/docu_sign_model.rb +23 -0
  21. data/lib/docu_sign/docu_sign_response.rb +33 -0
  22. data/lib/docu_sign/document.rb +57 -0
  23. data/lib/docu_sign/document_pdf.rb +14 -0
  24. data/lib/docu_sign/document_status.rb +15 -0
  25. data/lib/docu_sign/envelope.rb +136 -0
  26. data/lib/docu_sign/envelope_status.rb +33 -0
  27. data/lib/docu_sign/error.rb +7 -0
  28. data/lib/docu_sign/extensions.rb +81 -0
  29. data/lib/docu_sign/notification.rb +21 -0
  30. data/lib/docu_sign/railtie.rb +7 -0
  31. data/lib/docu_sign/recipient.rb +61 -0
  32. data/lib/docu_sign/recipient_status.rb +25 -0
  33. data/lib/docu_sign/tab.rb +96 -0
  34. data/lib/docu_sign/tab_status.rb +17 -0
  35. data/lib/docu_sign/version.rb +3 -0
  36. data/lib/docu_sign/void_envelope_status.rb +14 -0
  37. data/lib/docu_sign.rb +37 -0
  38. data/spec/docu_sign/client_spec.rb +8 -0
  39. data/spec/docu_sign/document_spec.rb +51 -0
  40. data/spec/docu_sign/envelope_spec.rb +132 -0
  41. data/spec/docu_sign/post_processing_spec.rb +85 -0
  42. data/spec/docu_sign/sending_spec.rb +96 -0
  43. data/spec/docu_sign/status_spec.rb +146 -0
  44. data/spec/docu_sign/tab_spec.rb +32 -0
  45. data/spec/docu_sign.yml.example +4 -0
  46. data/spec/docu_sign_spec.rb +28 -0
  47. data/spec/dummy/Rakefile +7 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  49. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/spec/dummy/config/application.rb +45 -0
  52. data/spec/dummy/config/boot.rb +10 -0
  53. data/spec/dummy/config/database.yml +22 -0
  54. data/spec/dummy/config/environment.rb +5 -0
  55. data/spec/dummy/config/environments/development.rb +26 -0
  56. data/spec/dummy/config/environments/production.rb +49 -0
  57. data/spec/dummy/config/environments/test.rb +35 -0
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/dummy/config/initializers/inflections.rb +10 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  62. data/spec/dummy/config/initializers/session_store.rb +8 -0
  63. data/spec/dummy/config/locales/en.yml +2 -0
  64. data/spec/dummy/config/routes.rb +58 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/db/test.sqlite3 +0 -0
  67. data/spec/dummy/log/development.log +0 -0
  68. data/spec/dummy/log/production.log +0 -0
  69. data/spec/dummy/log/server.log +0 -0
  70. data/spec/dummy/log/test.log +331 -0
  71. data/spec/dummy/public/404.html +26 -0
  72. data/spec/dummy/public/422.html +26 -0
  73. data/spec/dummy/public/500.html +26 -0
  74. data/spec/dummy/public/favicon.ico +0 -0
  75. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  76. data/spec/dummy/script/rails +6 -0
  77. data/spec/fixtures/document.pdf +0 -0
  78. data/spec/fixtures/vcr_cassettes/create_and_send_envelope.yml +553 -0
  79. data/spec/fixtures/vcr_cassettes/invalid_request.yml +52 -0
  80. data/spec/fixtures/vcr_cassettes/ping.yml +50 -0
  81. data/spec/fixtures/vcr_cassettes/request_document_pdfs_ex.yml +603 -0
  82. data/spec/fixtures/vcr_cassettes/request_envelope.yml +608 -0
  83. data/spec/fixtures/vcr_cassettes/request_status.yml +609 -0
  84. data/spec/fixtures/vcr_cassettes/request_status_ex.yml +614 -0
  85. data/spec/fixtures/vcr_cassettes/request_statuses.yml +1176 -0
  86. data/spec/fixtures/vcr_cassettes/void_envelope.yml +603 -0
  87. data/spec/spec_helper.rb +37 -0
  88. data/spec/support/vcr.rb +6 -0
  89. data/wsdl/dsapi.wsdl +3735 -0
  90. data/wsdl/dsapi.wsdl.old +3131 -0
  91. metadata +347 -0
@@ -0,0 +1,96 @@
1
+ module DocuSign
2
+ class Tab < DocuSignModel
3
+ ATTRIBUTES = [:document_id, :recipient_id, :page_number, :x_position, :y_position, :scale_value, :anchor_tab_item,
4
+ :type, :name, :tab_label, :value, :custom_tab_type, :custom_tab_width, :custom_tab_height, :custom_tab_required,
5
+ :conceal_value_on_document, :custom_tab_locked, :custom_tab_disable_auto_size, :custom_tab_list_items,
6
+ :custom_tab_list_values, :custom_tab_list_selected_value, :custom_tab_radio_group_name,
7
+ :custom_tab_validation_pattern, :custom_tab_validation_message, :template_locked, :template_required,
8
+ :conditional_parent_label, :conditional_parent_value, :shared_tab, :require_initial_on_shared_tab_change,
9
+ :font, :bold, :italic, :underline, :font_color, :font_size, :merge_field_xml, :include_note_in_email]
10
+ ATTRIBUTES.each do |attr|
11
+ self.send(:attr_accessor, attr)
12
+ end
13
+
14
+ alias_attribute :page, :page_number
15
+ alias_attribute :x, :x_position
16
+ alias_attribute :y, :y_position
17
+
18
+ def initialize(attributes = {})
19
+ ATTRIBUTES.each do |attr|
20
+ self.send("#{attr}=", attributes[attr])
21
+ end
22
+ end
23
+
24
+ def anchor(options = {}, &block)
25
+ anchor_builder.build(options, &block).tap do |a|
26
+ yield a if block_given?
27
+ self.anchor_tab_item = a
28
+ end
29
+ end
30
+
31
+ def anchor=(options = {})
32
+ anchor options
33
+ end
34
+
35
+ def anchor_builder
36
+ @anchor_builder ||= DocuSign::Builder::AnchorBuilder.new
37
+ end
38
+
39
+ %w(recipient document).each do |attr|
40
+ class_eval %Q{
41
+ def #{attr}=(value)
42
+ self.#{attr}_id = value.id
43
+ end
44
+ }
45
+ end
46
+
47
+ def to_savon
48
+ {
49
+ "DocumentID" => self.document_id,
50
+ "RecipientID" => self.recipient_id,
51
+ "PageNumber" => self.page_number,
52
+ "XPosition" => self.x_position,
53
+ "YPosition" => self.y_position,
54
+ "ScaleValue" => self.scale_value,
55
+ "AnchorTabItem" => self.anchor_tab_item.try(:to_savon),
56
+ "Type" => self.type,
57
+ "Name" => self.name,
58
+ "TabLabel" => self.tab_label,
59
+ "Value" => self.value,
60
+ "CustomTabType" => self.custom_tab_type,
61
+ "CustomTabWidth" => self.custom_tab_width,
62
+ "CustomTabHeight" => self.custom_tab_height,
63
+ "CustomTabRequired" => self.custom_tab_required?,
64
+ "ConcealValueOnDocument" => self.conceal_value_on_document?,
65
+ "CustomTabLocked" => self.custom_tab_locked?,
66
+ "CustomTabDisableAutoSize" => self.custom_tab_disable_auto_size?,
67
+ "CustomTabListItems" => self.custom_tab_list_items,
68
+ "CustomTabListValues" => self.custom_tab_list_values,
69
+ "CustomTabListSelectedValue" => self.custom_tab_list_selected_value,
70
+ "CustomTabRadioGroupName" => self.custom_tab_radio_group_name,
71
+ "CustomTabValidationPattern" => self.custom_tab_validation_pattern,
72
+ "CustomTabValidationMessage" => self.custom_tab_validation_message,
73
+ "TemplateLocked" => self.template_locked?,
74
+ "TemplateRequired" => self.template_required?,
75
+ "ConditionalParentLabel" => self.conditional_parent_label,
76
+ "ConditionalParentValue" => self.conditional_parent_value,
77
+ "SharedTab" => self.shared_tab?,
78
+ "RequireInitialOnSharedTabChange" => self.require_initial_on_shared_tab_change?,
79
+ "Font" => self.font,
80
+ "Bold" => self.bold,
81
+ "Italic" => self.italic,
82
+ "Underline" => self.underline,
83
+ "FontColor" => self.font_color,
84
+ "FontSize" => self.font_size,
85
+ "MergeFieldXml" => self.merge_field_xml,
86
+ "IncludeNoteInEmail" => self.include_note_in_email?
87
+ }.delete_if{|key, value| value.nil?}
88
+ end
89
+ end
90
+ end
91
+
92
+ # {http://www.docusign.net/API/3.0}ArrayOfTab
93
+ module DocuSign
94
+ class ArrayOfTab < ::Array
95
+ end
96
+ end
@@ -0,0 +1,17 @@
1
+ module DocuSign
2
+ class TabStatus < DocuSignModel
3
+ ATTRIBUTES = [:tab_type, :status, :x_position, :y_position, :signed, :tab_label, :tab_name, :tab_value,
4
+ :document_id, :page_number, :original_value, :validation_pattern, :role_name, :list_values, :list_selected_value,
5
+ :scale_value]
6
+ ATTRIBUTES.each do |attr|
7
+ self.send(:attr_accessor, attr)
8
+ end
9
+
10
+ def initialize(attributes = {})
11
+ ATTRIBUTES.each do |attr|
12
+ self.send("#{attr}=", attributes[attr])
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module DocuSign
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,14 @@
1
+ module DocuSign
2
+ class VoidEnvelopeStatus < DocuSignModel
3
+ ATTRIBUTES = [:void_success]
4
+ ATTRIBUTES.each do |attr|
5
+ self.send(:attr_accessor, attr)
6
+ end
7
+
8
+ def initialize(attributes = {})
9
+ ATTRIBUTES.each do |attr|
10
+ self.send("#{attr}=", attributes[attr])
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/docu_sign.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "docu_sign/version"
2
+
3
+ require 'docu_sign/extensions'
4
+
5
+ require 'savon'
6
+ require 'builder'
7
+
8
+ require 'docu_sign/client'
9
+ require 'docu_sign/docu_sign_model'
10
+ require 'docu_sign/docu_sign_response'
11
+ require 'docu_sign/anchor_tab'
12
+ require 'docu_sign/authentication_status'
13
+ require 'docu_sign/document'
14
+ require 'docu_sign/document_pdf'
15
+ require 'docu_sign/document_status'
16
+ require 'docu_sign/envelope'
17
+ require 'docu_sign/envelope_status'
18
+ require 'docu_sign/error'
19
+ require 'docu_sign/notification'
20
+ require 'docu_sign/recipient'
21
+ require 'docu_sign/recipient_status'
22
+ require 'docu_sign/tab'
23
+ require 'docu_sign/tab_status'
24
+ require 'docu_sign/void_envelope_status'
25
+
26
+ require 'docu_sign/builder/base'
27
+ require 'docu_sign/builder/document_builder'
28
+ require 'docu_sign/builder/recipient_builder'
29
+ require 'docu_sign/builder/tab_builder'
30
+ require 'docu_sign/builder/anchor_builder'
31
+ require 'docu_sign/builder/notification_builder'
32
+
33
+ require 'docu_sign/railtie' if defined?(Rails)
34
+
35
+ module DocuSign
36
+ # Your code goes here...
37
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DocuSign::Client do
4
+ before do
5
+ @client = DocuSign::Client.new(DOCU_SIGN_CONFIG)
6
+ end
7
+
8
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DocuSign::Document do
4
+ before(:each) do
5
+ @d = DocuSign::Document.new
6
+ end
7
+
8
+ it "should create a new document" do
9
+ @d.should be_an_instance_of(DocuSign::Document)
10
+ end
11
+
12
+ it "should respond to tabs" do
13
+ @d.should respond_to(:tabs)
14
+ end
15
+
16
+ describe "#tabs" do
17
+ context "with no arguments" do
18
+ it "should return an empty tab array" do
19
+ @d.tabs.should == []
20
+ end
21
+ end
22
+
23
+ context "with arguments" do
24
+ before(:each) do
25
+ @tabs = @d.tabs stub(:id => 1) do |d|
26
+ d.tab :name => 'tab_1', :value => 'foo'
27
+ d.tab :name => 'tab_2', :value => 'bar'
28
+ end
29
+ end
30
+
31
+ it "should build tabs" do
32
+ @tabs.all? { |t| t.is_a?(DocuSign::Tab) }.should be_true
33
+ end
34
+
35
+ it "should build the appropriate number of tabs" do
36
+ @tabs.size.should == 2
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#tab" do
42
+ it "should build a tab" do
43
+ @d.tab.should be_an_instance_of(DocuSign::Tab)
44
+ end
45
+
46
+ it "should pass in arguments" do
47
+ tab = @d.tab :document_id => 1
48
+ tab.document_id.should == 1
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,132 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DocuSign::Envelope do
4
+ before(:each) do
5
+ @e = DocuSign::Envelope.new
6
+ end
7
+
8
+ it "should create a new envelope" do
9
+ @e.should be_an_instance_of(DocuSign::Envelope)
10
+ end
11
+
12
+ it "should respond to documents" do
13
+ @e.should respond_to(:documents)
14
+ end
15
+
16
+ describe "#documents" do
17
+ context "with no arguments" do
18
+ it "should return an empty document array" do
19
+ @e.documents.should == []
20
+ end
21
+ end
22
+
23
+ context "with arguments" do
24
+ before(:each) do
25
+ @documents = @e.documents do |e|
26
+ e.document :name => 'Document 1'
27
+ e.document :name => 'Document 2'
28
+ end
29
+ end
30
+
31
+ it "should build documents" do
32
+ @documents.all? { |t| t.is_a?(DocuSign::Document) }.should be_true
33
+ end
34
+
35
+ it "should build the appropriate number of tabs" do
36
+ @documents.size.should == 2
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#document" do
42
+ it "should build a document" do
43
+ @e.document.should be_an_instance_of(DocuSign::Document)
44
+ end
45
+
46
+ it "should pass in arguments" do
47
+ document = @e.document :name => "Document 1"
48
+ document.name.should == "Document 1"
49
+ end
50
+ end
51
+
52
+ it "should respond to recipients" do
53
+ @e.should respond_to(:recipients)
54
+ end
55
+
56
+ describe "#recipients" do
57
+ context "with no arguments" do
58
+ it "should return an empty recipient array" do
59
+ @e.recipients.should == []
60
+ end
61
+ end
62
+
63
+ context "with arguments" do
64
+ before(:each) do
65
+ @recipients = @e.recipients do |e|
66
+ e.recipient :id => 1
67
+ e.recipient :id => 2
68
+ end
69
+ end
70
+
71
+ it "should build recipients" do
72
+ @recipients.all? { |r| r.is_a?(DocuSign::Recipient) }.should be_true
73
+ end
74
+
75
+ it "should build the appropriate number of recipients" do
76
+ @recipients.size.should == 2
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#recipient" do
82
+ it "should build a recipient" do
83
+ @e.recipient.should be_an_instance_of(DocuSign::Recipient)
84
+ end
85
+
86
+ it "should pass in arguments" do
87
+ recipient = @e.recipient :id => 1
88
+ recipient.id.should == 1
89
+ end
90
+ end
91
+
92
+ it "should respond to tabs" do
93
+ @e.should respond_to(:tabs)
94
+ end
95
+
96
+ describe "#tabs" do
97
+ context "with no arguments" do
98
+ it "should return an empty tab array" do
99
+ @e.tabs.should == []
100
+ end
101
+ end
102
+
103
+ context "with arguments" do
104
+ before(:each) do
105
+ @tabs = @e.tabs stub(:id => 1) do |e|
106
+ e.tab :name => 'tab_1', :value => 'foo'
107
+ e.tab :name => 'tab_2', :value => 'bar'
108
+ end
109
+ end
110
+
111
+ it "should build tabs" do
112
+ @tabs.all? { |t| t.is_a?(DocuSign::Tab) }.should be_true
113
+ end
114
+
115
+ it "should build the appropriate number of tabs" do
116
+ @tabs.size.should == 2
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#tab" do
122
+ it "should build a tab" do
123
+ @e.tab.should be_an_instance_of(DocuSign::Tab)
124
+ end
125
+
126
+ it "should pass in arguments" do
127
+ tab = @e.tab :document_id => 1
128
+ tab.document_id.should == 1
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Post Processing Group" do
4
+ before do
5
+ @client = DocuSign::Client.new(DOCU_SIGN_CONFIG)
6
+ end
7
+
8
+ describe "request_document_pdfs_ex" do
9
+ use_vcr_cassette :request_document_pdfs_ex, :record => :new_episodes
10
+ before do
11
+ envelope = DocuSign::Envelope.new.tap do |e|
12
+ e.transaction_id = "Test#{Time.now.to_i.to_s}"
13
+ e.account_id = "678cce00-95a7-4279-9101-557b3868d7aa"
14
+ e.asynchronous = false
15
+ e.subject = "Test Envelope"
16
+ e.notification do |n|
17
+ n.use_account_defaults = false
18
+ n.reminders = {
19
+ :reminder_enabled => true,
20
+ :reminder_delay => 2,
21
+ :reminder_frequency => 2
22
+ }
23
+ n.expirations = {
24
+ :expire_enabled => true,
25
+ :expire_after => 10,
26
+ :expire_warn => 2
27
+ }
28
+ end
29
+ end
30
+ # Documents
31
+ envelope.documents do |e|
32
+ file = File.open(File.dirname(__FILE__) + '/../fixtures/document.pdf', "rb")
33
+ contents = file.read
34
+ e.document :id => 1,
35
+ :name => "Document",
36
+ :pdf_bytes => Base64.encode64(contents),
37
+ :file_extension => 'pdf'
38
+ end
39
+ # Recipients
40
+ envelope.recipients do |e|
41
+ e.recipient :id => 1,
42
+ :user_name => "Recipient 1",
43
+ :email => "donald@donaldpiret.com",
44
+ :type => "Signer",
45
+ :require_id_lookup => false
46
+ end
47
+ # Tabs
48
+ envelope.tabs do |e|
49
+ e.tab :document_id => 1,
50
+ :recipient_id => 1,
51
+ :page_number => 1,
52
+ :x_position => 100,
53
+ :y_position => 200,
54
+ :type => "SignHere",
55
+ :anchor => {
56
+ :string => "blank",
57
+ :x => "200",
58
+ :y => 0,
59
+ :unit => "Pixels",
60
+ :ignore_if_not_present => false
61
+ }
62
+ e.tab :document_id => 1,
63
+ :recipient_id => 1,
64
+ :page_number => 1,
65
+ :x_position => 100,
66
+ :y_position => 200,
67
+ :type => "SignerAttachment",
68
+ :anchor => {
69
+ :string => "blank",
70
+ :x => "200",
71
+ :y => 0,
72
+ :unit => "Pixels",
73
+ :ignore_if_not_present => false
74
+ }
75
+ end
76
+ @envelope_id = @client.create_and_send_envelope(envelope).envelope_id
77
+ end
78
+
79
+ it "should successfully get an arry of document pdfs" do
80
+ response = @client.request_document_pd_fs_ex({"EnvelopeID" => @envelope_id})
81
+ response.should be_a_kind_of(Array)
82
+ response.first.should be_a_kind_of(DocuSign::DocumentPDF)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Sending Function Group" do
4
+ before do
5
+ @client = DocuSign::Client.new(DOCU_SIGN_CONFIG)
6
+ end
7
+
8
+ describe "create_and_send_envelope" do
9
+ use_vcr_cassette :create_and_send_envelope, :record => :new_episodes
10
+ it "should successfully create and send a simple envelope" do
11
+ envelope = DocuSign::Envelope.new.tap do |e|
12
+ e.transaction_id = "Test#{Time.now.to_i.to_s}"
13
+ e.account_id = "678cce00-95a7-4279-9101-557b3868d7aa"
14
+ e.asynchronous = false
15
+ e.subject = "Test Envelope"
16
+ e.notification do |n|
17
+ n.use_account_defaults = false
18
+ n.reminders = {
19
+ :reminder_enabled => true,
20
+ :reminder_delay => 2,
21
+ :reminder_frequency => 2
22
+ }
23
+ n.expirations = {
24
+ :expire_enabled => true,
25
+ :expire_after => 10,
26
+ :expire_warn => 2
27
+ }
28
+ end
29
+ end
30
+ # Documents
31
+ envelope.documents do |e|
32
+ file = File.open(File.dirname(__FILE__) + '/../fixtures/document.pdf', "rb")
33
+ contents = file.read
34
+ e.document :id => 1,
35
+ :name => "Document",
36
+ :pdf_bytes => Base64.encode64(contents),
37
+ :file_extension => 'pdf'
38
+ end
39
+ # Recipients
40
+ envelope.recipients do |e|
41
+ e.recipient :id => 1,
42
+ :user_name => "Recipient 1",
43
+ :email => "donald@donaldpiret.com",
44
+ :type => "Signer",
45
+ :require_id_lookup => false
46
+ end
47
+ # Tabs
48
+ envelope.tabs do |e|
49
+ e.tab :document_id => 1,
50
+ :recipient_id => 1,
51
+ :page_number => 1,
52
+ :x_position => 100,
53
+ :y_position => 200,
54
+ :type => "SignHere",
55
+ :anchor => {
56
+ :string => "blank",
57
+ :x => "200",
58
+ :y => 0,
59
+ :unit => "Pixels",
60
+ :ignore_if_not_present => false
61
+ }
62
+ e.tab :document_id => 1,
63
+ :recipient_id => 1,
64
+ :page_number => 1,
65
+ :x_position => 100,
66
+ :y_position => 200,
67
+ :type => "SignerAttachment",
68
+ :anchor => {
69
+ :string => "blank",
70
+ :x => "200",
71
+ :y => 0,
72
+ :unit => "Pixels",
73
+ :ignore_if_not_present => false
74
+ }
75
+ end
76
+ result = @client.create_and_send_envelope(envelope)
77
+ result.should be_an_instance_of(DocuSign::EnvelopeStatus)
78
+ end
79
+ end
80
+
81
+ describe "invalid requests" do
82
+ use_vcr_cassette :invalid_request
83
+
84
+ before do
85
+ @envelope = DocuSign::Envelope.new.tap do |e|
86
+ e.transaction_id = "Test#{Time.now.to_i.to_s}"
87
+ e.account_id = "678cce00-95a7-4279-9101-557b3868d7aa"
88
+ e.asynchronous = false
89
+ end
90
+ end
91
+
92
+ it "should successfully raise an error" do
93
+ lambda{ @client.create_and_send_envelope(@envelope) }.should raise_exception(DocuSign::Error)
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Status and Managing functions" do
4
+ before do
5
+ @client = DocuSign::Client.new(DOCU_SIGN_CONFIG)
6
+ end
7
+
8
+ describe "request_envelope" do
9
+ use_vcr_cassette :request_envelope
10
+ before do
11
+ @envelope = create_docusign_envelope
12
+ end
13
+
14
+ it "should correctly retrieve an envelope given an envelope id" do
15
+ envelope = @client.request_envelope({"EnvelopeID" => @envelope.envelope_id, "IncludeDocumentBytes" => "false"})
16
+ envelope.should be_an_instance_of(DocuSign::Envelope)
17
+ end
18
+ end
19
+
20
+ describe "request_status" do
21
+ use_vcr_cassette :request_status
22
+ before do
23
+ @envelope = create_docusign_envelope
24
+ end
25
+
26
+ it "should correctly retrieve an envelope status given an envelope id" do
27
+ @envelope_status = @client.request_status(:envelope_id => @envelope.envelope_id)
28
+ @envelope_status.recipient_statuses.first.status.should eq("Sent")
29
+ end
30
+ end
31
+
32
+ describe "request_status_ex" do
33
+ use_vcr_cassette :request_status_ex
34
+ before do
35
+ @envelope = create_docusign_envelope
36
+ end
37
+
38
+ it "should correctly retrieve the extended status given an envelope id" do
39
+ @envelope_status = @client.request_status_ex(:envelope_id => @envelope.envelope_id)
40
+ @envelope_status.recipient_statuses.first.status.should eq("Sent")
41
+ end
42
+ end
43
+
44
+ describe "request_statuses" do
45
+ use_vcr_cassette :request_statuses, :record => :new_episodes
46
+ before do
47
+ @envelope = create_docusign_envelope
48
+ @envelope2 = create_docusign_envelope
49
+ end
50
+
51
+ it "should correctly retrieve both envelope statuses" do
52
+ @envelope_statuses = @client.request_statuses(:envelope_status_filter => {"AccountId" => "678cce00-95a7-4279-9101-557b3868d7aa", "EnvelopeIds" => {"EnvelopeId" => [@envelope.envelope_id, @envelope2.envelope_id]}})
53
+ puts @envelope_statuses.inspect
54
+ end
55
+ end
56
+
57
+
58
+ describe "void_envelope" do
59
+ use_vcr_cassette :void_envelope
60
+ before do
61
+ @envelope_id = create_docusign_envelope
62
+ end
63
+
64
+ it "should correctly void an envelope given an envelope id" do
65
+ @void = @client.void_envelope({"EnvelopeID" => @envelope_id, "Reason" => "Booking Cancelled"})
66
+ @void.should be_an_instance_of(DocuSign::VoidEnvelopeStatus)
67
+ @void.void_success.should be_true
68
+ end
69
+
70
+ it "should work with snake case input parameters" do
71
+ @void = @client.void_envelope(:envelope_id => @envelope_id, :reason => "Booking Cancelled")
72
+ @void.should be_an_instance_of(DocuSign::VoidEnvelopeStatus)
73
+ @void.void_success.should be_true
74
+ end
75
+ end
76
+
77
+ def create_docusign_envelope
78
+ envelope = DocuSign::Envelope.new.tap do |e|
79
+ e.transaction_id = "Test#{Time.now.to_i.to_s}"
80
+ e.account_id = "678cce00-95a7-4279-9101-557b3868d7aa"
81
+ e.asynchronous = false
82
+ e.subject = "Test Envelope"
83
+ e.notification do |n|
84
+ n.use_account_defaults = false
85
+ n.reminders = {
86
+ :reminder_enabled => true,
87
+ :reminder_delay => 2,
88
+ :reminder_frequency => 2
89
+ }
90
+ n.expirations = {
91
+ :expire_enabled => true,
92
+ :expire_after => 10,
93
+ :expire_warn => 2
94
+ }
95
+ end
96
+ end
97
+ # Documents
98
+ envelope.documents do |e|
99
+ file = File.open(File.dirname(__FILE__) + '/../fixtures/document.pdf', "rb")
100
+ contents = file.read
101
+ e.document :id => 1,
102
+ :name => "Document",
103
+ :pdf_bytes => Base64.encode64(contents),
104
+ :file_extension => 'pdf'
105
+ end
106
+ # Recipients
107
+ envelope.recipients do |e|
108
+ e.recipient :id => 1,
109
+ :user_name => "Recipient 1",
110
+ :email => "donald@donaldpiret.com",
111
+ :type => "Signer",
112
+ :require_id_lookup => false
113
+ end
114
+ # Tabs
115
+ envelope.tabs do |e|
116
+ e.tab :document_id => 1,
117
+ :recipient_id => 1,
118
+ :page_number => 1,
119
+ :x_position => 100,
120
+ :y_position => 200,
121
+ :type => "SignHere",
122
+ :anchor => {
123
+ :string => "blank",
124
+ :x => "200",
125
+ :y => 0,
126
+ :unit => "Pixels",
127
+ :ignore_if_not_present => false
128
+ }
129
+ e.tab :document_id => 1,
130
+ :recipient_id => 1,
131
+ :page_number => 1,
132
+ :x_position => 100,
133
+ :y_position => 200,
134
+ :type => "SignerAttachment",
135
+ :anchor => {
136
+ :string => "blank",
137
+ :x => "200",
138
+ :y => 0,
139
+ :unit => "Pixels",
140
+ :ignore_if_not_present => false
141
+ }
142
+ end
143
+ return @client.create_and_send_envelope(envelope)
144
+ end
145
+
146
+ end