hellosign-ruby-sdk 3.0.18 → 3.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29643cd2407c931729cfa222edf5bda0adb6a6bb
4
- data.tar.gz: cb307966b0355ef27cc475ffeca1b203a6d80d5c
3
+ metadata.gz: c422e4abbd97f92563383ee0e5355f4485c4b297
4
+ data.tar.gz: eedf437c54a440c11a561484b2062325a0f9ac95
5
5
  SHA512:
6
- metadata.gz: 514b1b19d22bd8402a7d1724920bc0bb3b61b563da9a18f519057e0dabcc50735f37be28a23174dd03dfb3a6de78dbaa0f09b631f57c1a85d2431891f552b994
7
- data.tar.gz: 97599fb900e28a83fef212cd34922d430d5f0a6bdc07b7cafa0793f14463c81b4325d530ac925768c958aef44f3707f96e155a3a2f878b42c13caa2d7b2f0d29
6
+ metadata.gz: 17b9f71f60fe5e8533d83654289582cf46988cb92bf976e97733048078747247e662ce4fa1bbbef4ffe0f90456f44e61c506e65bce32f25f32153785fe3e831d
7
+ data.tar.gz: 93188013bbcb4a47dcca7886eb3ec377c38c190404a4e6b069acc700c070c5eb5ff196f7576d8d1defd8c096828bd77bb98f0f1b28b1a0d696b76a46428a2fb6
data/README.md CHANGED
@@ -48,6 +48,12 @@ If you need to authenticate for multiple users and you want a separated client f
48
48
  client2 = HelloSign::Client.new :api_key => 'your_user_api_key'
49
49
  user_account = client2.get_account
50
50
  ```
51
+ ### Specifying files
52
+
53
+ When using request endpoints that send files, such as a signature request, you can specify files either as
54
+ 1. A string representing the path
55
+ 2. A Ruby File Object (File.open, then assign to a variable)
56
+ 3. A Rails ActionDispatch::Http::UploadedFile
51
57
 
52
58
  ##Testing
53
59
 
@@ -56,6 +62,29 @@ from the root of your project run <code>rake spec</code>.
56
62
 
57
63
  ## Additional notes
58
64
 
65
+ ## Warnings
66
+ Any warnings returned from the API can be accessed by using the 'warnings' accessor on a returned object or list:
67
+
68
+ ````ruby
69
+ my_signature_requests = client.get_signature_requests
70
+ puts my_signature_requests.warnings
71
+ ````
72
+
73
+ and will give output of warnings in the following format (as an array of hashes):
74
+
75
+ ````
76
+ [
77
+ [0] {
78
+ "warning_msg" => "Parameter hodor was ignored. Hodor.",
79
+ "warning_name" => "parameter_ignored"
80
+ },
81
+ [1] {
82
+ "warning_msg" => "Email address sirjorah@targarian.org is unconfirmed. Please pledge your allegiance to the queen first.",
83
+ "warning_name" => "unconfirmed"
84
+ }
85
+ ]
86
+ ````
87
+
59
88
  ### Local callbacks
60
89
  We do not allow app callbacks (event or OAuth) to be set to localhost. However it is still possible to test callbacks against a local server. Tunneling services such as ngrok (http://ngrok.com) can help you set this up.
61
90
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  #
4
4
  # The MIT License (MIT)
5
- #
5
+ #
6
6
  # Copyright (C) 2014 hellosign.com
7
- #
7
+ #
8
8
  # Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  # of this software and associated documentation files (the "Software"), to deal
10
10
  # in the Software without restriction, including without limitation the rights
@@ -49,4 +49,5 @@ Gem::Specification.new do |spec|
49
49
  spec.add_development_dependency 'webmock'
50
50
  spec.add_runtime_dependency 'faraday'
51
51
  spec.add_runtime_dependency 'multi_json'
52
+ spec.add_runtime_dependency 'mime-types'
52
53
  end
@@ -24,10 +24,13 @@
24
24
 
25
25
  require 'faraday'
26
26
  require 'multi_json'
27
+ require 'mime/types'
27
28
  require 'hello_sign/error'
28
29
  require 'hello_sign/configuration'
29
30
  require 'hello_sign/resource'
30
31
  require 'hello_sign/api'
32
+ require 'openssl'
33
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
31
34
  require 'logger'
32
35
 
33
36
  module HelloSign
@@ -187,14 +190,44 @@ module HelloSign
187
190
  "Message: #{response.body}"
188
191
  end
189
192
 
193
+ def MIMEfromName(name)
194
+ parts = name.split('.')
195
+ #default to pdf if no extension
196
+ if parts.length < 2
197
+ return 'application/pdf'
198
+ end
199
+ extension = parts[-1]
200
+ types = MIME::Types.type_for(extension)
201
+ types[0]
202
+ end
203
+
204
+ def MIMEfromIO(file)
205
+ begin
206
+ path = File.path file
207
+ MIMEfromName path
208
+ # in case of error in type detection, return default type
209
+ rescue
210
+ return 'application/pdf'
211
+ end
212
+ end
213
+
190
214
  def prepare_files(opts)
191
215
  if opts[:files]
192
216
  opts[:files].each_with_index do |file, index|
193
217
  if file.is_a? String
194
- opts[:"file[#{index}]"] = Faraday::UploadIO.new(StringIO.new(file), 'application/pdf')
218
+ if File.file?(file)
219
+ mime_type = MIMEfromName file
220
+ opts[:"file[#{index}]"] = Faraday::UploadIO.new(file, mime_type)
221
+ else
222
+ raise HelloSign::Error::FileNotFound.new "#{file} was not found on the filesystem"
223
+ end
224
+ elsif file.is_a? File
225
+ mime_type = MIMEfromIO file
226
+ opts[:"file[#{index}]"] = Faraday::UploadIO.new(file, mime_type)
195
227
  elsif defined? ActionDispatch::Http::UploadedFile
196
228
  if file.is_a? ActionDispatch::Http::UploadedFile
197
- opts[:"file[#{index}]"] = UploadIO.new(file.tempfile, 'application/pdf')
229
+ mime_type MIMEfromIO file
230
+ opts[:"file[#{index}]"] = UploadIO.new(file.tempfile, mime_type)
198
231
  end
199
232
  else
200
233
  raise HelloSign::Error::NotSupportedType.new "#{file.class} is not a supported. Must be a string or ActionDispatch::Http::UploadedFile"
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # The MIT License (MIT)
3
- #
3
+ #
4
4
  # Copyright (C) 2014 hellosign.com
5
- #
5
+ #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the "Software"), to deal
8
8
  # in the Software without restriction, including without limitation the rights
@@ -72,6 +72,9 @@ module HelloSign
72
72
  # Raised when API endpoint returns the HTTP status code 503.
73
73
  class NotSupportedType < Error; end
74
74
 
75
+ # Raised when a file attempted to be sent in a request doesn't exist
76
+ class FileNotFound < Error; end
77
+
75
78
  # Raised when API endpoint returns error which is not defined in sdk.
76
79
  class UnknownError < Error; end
77
80
  end
@@ -23,5 +23,5 @@
23
23
  #
24
24
 
25
25
  module HelloSign
26
- VERSION = '3.0.18'
26
+ VERSION = '3.0.19'
27
27
  end
Binary file
@@ -5,15 +5,7 @@ describe 'Uploading File' do
5
5
  before { stub_post('/signature_request/create_embedded', 'signature_request') }
6
6
 
7
7
  it 'works with simple pdf' do
8
- expect(HelloSign.create_embedded_signature_request({files: [load_file('empty.pdf')]}))
9
- end
10
-
11
- it 'works with null byte string' do
12
- expect(HelloSign.create_embedded_signature_request({files: ["\0"]}))
13
- end
14
-
15
- it 'works with empty string' do
16
- expect(HelloSign.create_embedded_signature_request({files: ['']}))
8
+ expect(HelloSign.create_embedded_signature_request({files: ['spec/fixtures/nda.pdf']}))
17
9
  end
18
10
  end
19
11
 
@@ -21,15 +13,7 @@ describe 'Uploading File' do
21
13
  before { stub_post('/unclaimed_draft/create', 'unclaimed_draft') }
22
14
 
23
15
  it 'works with simple pdf' do
24
- expect(HelloSign.create_unclaimed_draft({files: [load_file('empty.pdf')]}))
25
- end
26
-
27
- it 'works with null byte string' do
28
- expect(HelloSign.create_unclaimed_draft({files: ["\0"]}))
29
- end
30
-
31
- it 'works with empty string' do
32
- expect(HelloSign.create_unclaimed_draft({files: ['']}))
16
+ expect(HelloSign.create_unclaimed_draft({files: ['spec/fixtures/nda.pdf']}))
33
17
  end
34
18
  end
35
- end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellosign-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.18
4
+ version: 3.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - HelloSign
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mime-types
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: ''
98
112
  email: support@hellosign.com
99
113
  executables: []
@@ -137,6 +151,7 @@ files:
137
151
  - spec/fixtures/empty.pdf
138
152
  - spec/fixtures/error.json
139
153
  - spec/fixtures/file.json
154
+ - spec/fixtures/nda.pdf
140
155
  - spec/fixtures/signature_request.json
141
156
  - spec/fixtures/signature_requests.json
142
157
  - spec/fixtures/team.json
@@ -186,6 +201,7 @@ test_files:
186
201
  - spec/fixtures/empty.pdf
187
202
  - spec/fixtures/error.json
188
203
  - spec/fixtures/file.json
204
+ - spec/fixtures/nda.pdf
189
205
  - spec/fixtures/signature_request.json
190
206
  - spec/fixtures/signature_requests.json
191
207
  - spec/fixtures/team.json