groupdocs 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  source :rubygems
2
2
 
3
3
  gem 'sinatra'
4
- gem 'groupdocs', :git => 'git://github.com/p0deje/groupdocs-ruby.git'
4
+ gem 'groupdocs', "1.2"
5
5
  gem 'haml'
@@ -1,3 +1,35 @@
1
1
  get '/sample6' do
2
2
  haml :sample6
3
3
  end
4
+
5
+ post '/sample6' do
6
+ set :client_id, params[:client_id]
7
+ set :private_key, params[:private_key]
8
+
9
+ begin
10
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
11
+
12
+ file_one_path = "#{Dir.tmpdir}/#{params[:document][:filename]}"
13
+ File.open(file_one_path, 'wb') { |f| f.write(params[:document][:tempfile].read) }
14
+
15
+
16
+ file_one = GroupDocs::Storage::File.new(name: params[:document][:filename], local_path: file_one_path)
17
+ document_one = file_one.to_document
18
+
19
+ signature_one_path = "#{Dir.tmpdir}/#{params[:signature][:filename]}"
20
+ File.open(signature_one_path, 'wb') { |f| f.write(params[:signature][:tempfile].read) }
21
+
22
+ signature_one = GroupDocs::Signature.new(name: 'Test', image_path: signature_one_path)
23
+ signature_one.position = { top: 0.1, left: 0.07, width: 50, height: 50}
24
+
25
+ signed_documents = GroupDocs::Document.sign_documents!([document_one], [signature_one], {}, { :client_id => settings.client_id, :private_key => settings.private_key })
26
+ if signed_documents
27
+ iframe = "<iframe src='https://apps.groupdocs.com/document-viewer/Embed/#{signed_documents}' frameborder='0' width='720' height='600'></iframe>"
28
+ end
29
+ rescue Exception => e
30
+ pp e
31
+ err = e.message
32
+ end
33
+
34
+ haml :sample6, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :err => err }
35
+ end
@@ -1,41 +1,47 @@
1
- %script{:src => "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", :type => "text/javascript"}
2
- %script{:src => "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js", :type => "text/javascript"}
3
- %script{:src => "http://dev-apps.groupdocs.com/content/signaturewidgets/groupdocs.sign.js", :type => "text/javascript"}
4
-
5
1
  %h3{:style => "text-align:center;"}
6
2
  %a{:href => "/"} GroupDocs Ruby SDK Samples
7
3
  \- Sample6
8
4
  .samplecontent{:style => "padding:10px;"}
9
5
  %i This sample will show how to add provided signature to provided document using Ruby SDK. Signed file will be uploaded to GroupDocs account and its GUID will be returned and embed into webpage with GroupDocs Ebedded Viewer.
10
6
  %br/
7
+ %br/
8
+ %p
9
+ You entered:
10
+ %p
11
+ UserId = #{(defined? userId) ? userId : ""}
12
+ %p
13
+ PrivateKey = #{(defined? privateKey) ? privateKey : ""}
14
+ %p
15
+ %font{:color => "red"} #{(defined? err) ? err : ""}
11
16
  #files_form
12
- %form{:action => "#", :onsubmit => "return false;"}
17
+ %form{:action => "/sample6", :enctype => "multipart/form-data", :method => "post"}
13
18
  %br/
14
19
  %label{:for => "client_id"} GroupDocs ClientID
15
20
  %br/
16
- %input{:type=>'text', :id=>'client_id'}
21
+ %input{:type=>'text', :id=>'client_id', :name => "client_id"}
17
22
  %br/
18
23
  %label{:for => "private_key"} GroupDocs PrivateKey
19
24
  %br/
20
- %input{:type=>'text', :id=>'private_key'}
25
+ %input{:type=>'text', :id=>'private_key', :name => "private_key"}
21
26
  %br/
22
27
  %label{:for => "file_document"} Document to sign
23
28
  %br/
24
- %input#fi_document{:type => "file"}/
29
+ %input#fi_document{:type => "file", :name => "document"}/
25
30
  %br/
26
31
  %label{:for => "file_signature"} Signature
27
32
  %br/
28
- %input#fi_signature{:type => "file"}/
33
+ %input#fi_signature{:type => "file", :name => "signature"}/
29
34
  %br/
30
35
  %br/
31
- %input#btnLoad{:onclick => "load();", :type => "button", :value => "Upload and sign the document"}
36
+ %input{:type => "submit", :value => "Upload and sign the document"}/
32
37
  %br/
33
38
  %br/
34
39
  %div{:style => "padding:20px; border:1px solid black;"}
35
40
  %p
36
41
  Results:
37
42
  %span#results_status{:style => "color:red;display:none;"} (Please wait for ajax response)
38
- %iframe#viewer{:frameborder => "0", :height => "500", :src => "", :width => "600"}
43
+ #{(defined? iframe) ? iframe : ""}
44
+
39
45
  %div{:style => "padding:10px;"}
40
46
  Choose another one sample:
41
47
  %ul
@@ -58,88 +64,4 @@
58
64
  %li
59
65
  %a{:href => "/sample9"} Sample9 - How to generate an embedded Viewer URL for a Document
60
66
  %li
61
- %a{:href => "/sample10"} Sample10 - How to share a document to other users
62
- :javascript
63
- function load() {
64
- var inputDocument, inputSignature, fileDocument, fileSignature, frDocument, frSignature;
65
-
66
- if (typeof window.FileReader !== 'function') {
67
- $("body").append("p", "The file API isn't supported on this browser yet.");
68
- return;
69
- }
70
-
71
- inputDocument = document.getElementById('fi_document');
72
- if (!inputDocument) {
73
- $("body").append("p", "Um, couldn't find the fileinput element.");
74
- }
75
- else if (!inputDocument.files) {
76
- $("body").append("p", "This browser doesn't seem to support the `files` property of file inputs.");
77
- }
78
- else if (!inputDocument.files[0]) {
79
- $("#files_form").append("Please select a file before clicking 'Load'");
80
- }
81
- else {
82
- $('#results_status').fadeIn("slow");
83
- $('#sample6').fadeOut("slow");
84
-
85
- fileDocument = inputDocument.files[0];
86
- frDocument = new FileReader();
87
- frDocument.onload = receivedDocument;
88
- frDocument.readAsDataURL(fileDocument);
89
- }
90
-
91
- function receivedDocument() {
92
-
93
- inputSignature = document.getElementById('fi_signature');
94
- if (!inputSignature) {
95
- $("body").append("Um, couldn't find the fileinput element.");
96
- }
97
- else if (!inputSignature.files) {
98
- $("body").append("p", "This browser doesn't seem to support the `files` property of file inputs.");
99
- }
100
- else if (!inputSignature.files[0]) {
101
- $("body").append("Please select a file before clicking 'Load'");
102
- }
103
- else {
104
- fileSignature = inputSignature.files[0];
105
- frSignature = new FileReader();
106
- frSignature.onload = receivedSignature;
107
- frSignature.readAsDataURL(fileSignature);
108
- }
109
- }
110
-
111
- function receivedSignature() {
112
- var span = document.createElement('span');
113
- span.innerHTML = [''].join('');
114
- signDocument();
115
- }
116
-
117
- function signDocument() {
118
- $("body").sign({
119
- userId: $('#client_id').val(),
120
- privateKey: $('#private_key').val(),
121
- signMethod: "/sample6",
122
- onerr: function (e, data) {
123
- alert(data);
124
- },
125
- onSigned: function (e, data) {
126
- $("#viewer").attr("src", "https://apps.groupdocs.com/document-viewer/Embed/" + data.documentId);
127
- $('#results_status').fadeOut("slow");
128
- $('#viewer').fadeIn("slow");
129
- }
130
- });
131
- $("body").sign("addDocument", {
132
- name: fileDocument.name,
133
- data: frDocument.result
134
- });
135
- $("body").sign("addSigner", {
136
- name: 'Marketplace Team',
137
- top: 0.03319,
138
- left: 0.52171,
139
- width: 100,
140
- height: 40,
141
- data: frSignature.result
142
- });
143
- $("body").sign("sign");
144
- }
145
- }
67
+ %a{:href => "/sample10"} Sample10 - How to share a document to other users
@@ -41,6 +41,22 @@ module GroupDocs
41
41
  @resource = RestClient::Resource.new(GroupDocs.api_server)
42
42
  end
43
43
 
44
+ #
45
+ # Prepares, signs and returns absolute URL.
46
+ # @return [String]
47
+ #
48
+ def prepare_and_sign_url
49
+ unless @signed
50
+ parse_path
51
+ prepend_version
52
+ url_encode_path
53
+ sign_url
54
+ @signed = true
55
+ end
56
+
57
+ "%s%s" % [GroupDocs.api_server, options[:path]]
58
+ end
59
+
44
60
  #
45
61
  # Executes API request to server.
46
62
  #
@@ -56,10 +72,7 @@ module GroupDocs
56
72
  # @return [Hash, String] Parsed response
57
73
  #
58
74
  def execute!
59
- parse_path
60
- prepend_version
61
- url_encode_path
62
- sign_url
75
+ prepare_and_sign_url
63
76
  prepare_request
64
77
  send_request
65
78
  parse_response
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end # GroupDocs
@@ -35,32 +35,47 @@ describe GroupDocs::Api::Request do
35
35
  end
36
36
  end
37
37
 
38
- describe '#execute!' do
39
- before(:each) do
40
- GroupDocs.stub(private_key: 'private_key')
41
- subject.options[:method] = :get
42
- subject.options[:path] = '/folders'
43
- subject.options[:headers] = {}
44
- mock_api_server('{"status":"Ok"}')
45
- end
46
-
38
+ describe '#prepare_and_sign_url' do
47
39
  it 'parses path' do
48
40
  subject.should_receive(:parse_path)
49
- subject.execute!
41
+ subject.prepare_and_sign_url
50
42
  end
51
43
 
52
44
  it 'prepends path with version' do
53
45
  subject.should_receive(:prepend_version)
54
- subject.execute!
46
+ subject.prepare_and_sign_url
55
47
  end
56
48
 
57
49
  it 'URL encodes path' do
58
50
  subject.should_receive(:url_encode_path)
59
- subject.execute!
51
+ subject.prepare_and_sign_url
60
52
  end
61
53
 
62
54
  it 'signs url' do
63
55
  subject.should_receive(:sign_url)
56
+ subject.prepare_and_sign_url
57
+ end
58
+
59
+ it 'returns prepared and signed url' do
60
+ subject.prepare_and_sign_url.should be_a(String)
61
+ end
62
+
63
+ it 'does nothing if url is already signed' do
64
+ subject.prepare_and_sign_url.should == subject.prepare_and_sign_url
65
+ end
66
+ end
67
+
68
+ describe '#execute!' do
69
+ before(:each) do
70
+ GroupDocs.stub(private_key: 'private_key')
71
+ subject.options[:method] = :get
72
+ subject.options[:path] = '/folders'
73
+ subject.options[:headers] = {}
74
+ mock_api_server('{"status":"Ok"}')
75
+ end
76
+
77
+ it 'prepares and signs url' do
78
+ subject.should_receive(:prepare_and_sign_url)
64
79
  subject.execute!
65
80
  end
66
81
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -168,7 +168,6 @@ files:
168
168
  - Rakefile
169
169
  - examples/README.md
170
170
  - examples/api-samples/Gemfile
171
- - examples/api-samples/Gemfile.lock
172
171
  - examples/api-samples/README.md
173
172
  - examples/api-samples/app.rb
174
173
  - examples/api-samples/public/css/style.css
@@ -423,7 +422,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
423
422
  version: '0'
424
423
  segments:
425
424
  - 0
426
- hash: -3978014780066540379
425
+ hash: -2334837121037252250
427
426
  required_rubygems_version: !ruby/object:Gem::Requirement
428
427
  none: false
429
428
  requirements:
@@ -432,7 +431,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
432
431
  version: '0'
433
432
  segments:
434
433
  - 0
435
- hash: -3978014780066540379
434
+ hash: -2334837121037252250
436
435
  requirements: []
437
436
  rubyforge_project:
438
437
  rubygems_version: 1.8.24
@@ -1,27 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- groupdocs (1.1.0)
5
- json (~> 1.7)
6
- rest-client (~> 1.6)
7
- haml (3.1.7)
8
- json (1.7.5)
9
- mime-types (1.19)
10
- rack (1.4.1)
11
- rack-protection (1.2.0)
12
- rack
13
- rest-client (1.6.7)
14
- mime-types (>= 1.16)
15
- sinatra (1.3.3)
16
- rack (~> 1.3, >= 1.3.6)
17
- rack-protection (~> 1.2)
18
- tilt (~> 1.3, >= 1.3.3)
19
- tilt (1.3.3)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- groupdocs
26
- haml
27
- sinatra