rightsignature 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2Q2MTU5ZGRiMjIwMGYyNTk1NWQzZjhhNWZhMDlkZjQxYWFiOTgzYw==
5
+ data.tar.gz: !binary |-
6
+ NWU3Y2UxOTE1MzAyYjY5Yzc0MmU5NTk4ZmYxNTg0ZjcwMWUxNWZhMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGYwM2RmZjFhMDcyMjM5ZDhkMTg2OGY3MzA5OTE1YTY5ODU4N2UyODYxNjU3
10
+ NWFjOWFkZTk1ZWUwM2YxM2I5YTdiODZjMTZlMjMwZTZlOTc4YmUyYmQ4Yjky
11
+ ZjQ4MDJiNjkxZDlmNjQxMmQ5ZjljZjc0NzcyYTJjNzU0NzlmNjU=
12
+ data.tar.gz: !binary |-
13
+ MmFiMTAzMGMwY2M4M2FjZDIyMzM1OTA5NzE3NGE5Yzg4YjFhN2QwYTlmNzYw
14
+ ZjVjZTllM2EwMGEyMjc3ZTQ2ZWE0YjMyODAzNzI0NGQ5MGExMWU3M2Y4M2Qw
15
+ NWMwYTQyZDhkMTI1ZTdlNTgzMjY3ZWY0YTBlMWE3YjcyM2E2MGM=
data/README.md CHANGED
@@ -414,13 +414,30 @@ request_hash= {
414
414
  @rs_connection.post('/api/documents.xml', request_hash, {'custom_header' => 'headerValue'})
415
415
  ```
416
416
 
417
+ Getting API Error Messages
418
+ --------------------------
419
+ If a request does not return a success response (200), a RightSignature::ResponseError is raised. You can rescue the error and inspect the response object or call detailed_message. detailed_message only returns if the response from the server contains an error message in the XML.
420
+ #####Ex. Trying to parse the error message response from API
421
+ ```
422
+ begin
423
+ @rs_connection.post('/api/documents.xml', {:bad => 'params'})
424
+ rescue RightSignature::ResponseError => error
425
+ puts error.detailed_message
426
+ end
427
+ ```
428
+
429
+ #####Ex. Trying to inspect the response object for more information
430
+ ```
431
+ begin
432
+ @rs_connection.post('/api/documents.xml', {:bad => 'params'})
433
+ rescue RightSignature::ResponseError => error
434
+ puts error.response.inspect
435
+ end
436
+ ```
437
+
417
438
  Development Notes
418
439
  -----------------
419
440
  To load in irb from project root:
420
441
  ```
421
442
  $:.push File.expand_path("../lib", __FILE__); require "rightsignature"; RightSignature::Connection.new(MY_KEYS)
422
443
  ```
423
-
424
- TODO:
425
- -----
426
- * Parse error message from response body on unsuccessful requests
@@ -190,14 +190,12 @@ module RightSignature
190
190
  def parse_response(response)
191
191
  if response.is_a? Net::HTTPResponse
192
192
  unless response.is_a? Net::HTTPSuccess
193
- puts response.body
194
193
  raise RightSignature::ResponseError.new(response)
195
194
  end
196
195
 
197
196
  MultiXml.parse(response.body)
198
197
  else
199
198
  unless response.success?
200
- puts response.body
201
199
  raise RightSignature::ResponseError.new(response)
202
200
  end
203
201
 
@@ -2,6 +2,10 @@ module RightSignature
2
2
  class ResponseError < Exception
3
3
  attr_reader :response
4
4
 
5
+ # Creates new instance of RightSignature::ResponseError to make API calls
6
+ # * <b>response</b>: Net::HTTP response or HTTParty response
7
+ # * <b>message</b>: (Optional) Custom error message
8
+ #
5
9
  def initialize(response, message=nil)
6
10
  self.set_backtrace(caller[1..-1]) if self.backtrace.nil?
7
11
  @response = response
@@ -23,6 +27,21 @@ module RightSignature
23
27
  "Check the format of your xml or json"
24
28
  end
25
29
  end
30
+
31
+ # Attempts to parse an error message from the response body
32
+ def detailed_message
33
+ if @response.is_a? Net::HTTPResponse
34
+ parsed_response = MultiXml.parse(@response.body)
35
+
36
+ parsed_response["error"]["message"] if parsed_response && parsed_response["error"]
37
+ else
38
+ if @response.parsed_response.is_a? Hash
39
+ @response.parsed_response["error"]["message"] if @response.parsed_response["error"]
40
+ end
41
+ end
42
+ end
43
+
44
+
26
45
  end
27
46
 
28
47
  class TokenResponseError < ResponseError # :nodoc:
@@ -22,9 +22,9 @@ module RightSignature::Helpers #:nodoc:
22
22
  tags_array.map do |t|
23
23
  if t.is_a? Hash
24
24
  name, value = t.first
25
- {:tag => {:name => name, :value => value}}
25
+ {:tag => {:name => name.to_s, :value => value.to_s}}
26
26
  else
27
- {:tag => {:name => t}}
27
+ {:tag => {:name => t.to_s}}
28
28
  end
29
29
  end
30
30
  end
@@ -43,9 +43,9 @@ module RightSignature::Helpers #:nodoc:
43
43
  name, value = role_hash.first
44
44
  raise "Hash '#{role_hash.inspect}' is malformed, should be something like {ROLE_NAME => {:name => \"a\", :email => \"a@a.com\"}}" unless value.is_a? Hash and name.is_a? String
45
45
  if name.match(/^signer_[A-Z]+$/) || name.match(/^cc_[A-Z]+$/)
46
- roles_hash_array << {:role => value.merge({"@role_id" => name})}
46
+ roles_hash_array << {:role => value.merge({"@role_id" => name.to_s})}
47
47
  else
48
- roles_hash_array << {:role => value.merge({"@role_name" => name})}
48
+ roles_hash_array << {:role => value.merge({"@role_name" => name.to_s})}
49
49
  end
50
50
  end
51
51
 
@@ -65,9 +65,9 @@ module RightSignature::Helpers #:nodoc:
65
65
  merge_fields_array.each do |merge_field_hash|
66
66
  name, value = merge_field_hash.first
67
67
  if use_id
68
- merge_fields << { :merge_field => {:value => value, "@merge_field_id" => name}}
68
+ merge_fields << { :merge_field => {:value => value.to_s, "@merge_field_id" => name.to_s}}
69
69
  else
70
- merge_fields << { :merge_field => {:value => value, "@merge_field_name" => name}}
70
+ merge_fields << { :merge_field => {:value => value.to_s, "@merge_field_name" => name.to_s}}
71
71
  end
72
72
  end
73
73
 
@@ -94,7 +94,7 @@ module RightSignature
94
94
  use_merge_field_ids = options.delete(:use_merge_field_ids)
95
95
  xml_hash[:template][:merge_fields] = MergeFieldsHelper.array_to_xml_hash(options[:merge_fields], use_merge_field_ids) if options[:merge_fields]
96
96
  xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
97
- [:expires_in, :description, :callback_location, :redirect_location, :action].each do |other_option|
97
+ [:expires_in, :description, :callback_location, :redirect_location, :action, :document_data].each do |other_option|
98
98
  xml_hash[:template][other_option] = options[other_option] if options[other_option]
99
99
  end
100
100
 
@@ -1,3 +1,3 @@
1
1
  module RightSignature
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/spec/errors_spec.rb CHANGED
@@ -25,6 +25,22 @@ describe RightSignature::ResponseError do
25
25
  error.message.should == 'No Way'
26
26
  end
27
27
  end
28
+
29
+ describe "detailed_message" do
30
+ it "should return error message from xml" do
31
+ response = Net::HTTPNotAcceptable.new('1.1', 406, 'Not Acceptable')
32
+ response.stub(:body).and_return('<error><message>Invalid GUID</message></error>')
33
+ error = RightSignature::ResponseError.new(response)
34
+ error.detailed_message.should == 'Invalid GUID'
35
+ end
36
+
37
+ it "should return nothing if response does not have error message node" do
38
+ response = Net::HTTPNotFound.new('1.1', 404, 'Not Found')
39
+ response.stub(:body).and_return('<html><body>Not Found</body></html>')
40
+ error = RightSignature::ResponseError.new(response)
41
+ error.detailed_message.should be_nil
42
+ end
43
+ end
28
44
 
29
45
  describe "common_solutions" do
30
46
  describe "on 406" do
@@ -82,6 +98,24 @@ describe RightSignature::ResponseError do
82
98
  end
83
99
  end
84
100
 
101
+ describe "detailed_message" do
102
+ it "should return error message from xml" do
103
+ net_http_response = Net::HTTPNotAcceptable.new('1.1', 406, 'Not Acceptable')
104
+ net_http_response.stub(:body).and_return('<error><message>Invalid GUID</message></error>')
105
+ response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), net_http_response, lambda{{"error" => {"message" => "Invalid GUID"}}})
106
+ error = RightSignature::ResponseError.new(response)
107
+ error.detailed_message.should == 'Invalid GUID'
108
+ end
109
+
110
+ it "should return nothing if response does not have error message node" do
111
+ net_http_response = Net::HTTPNotFound.new('1.1', 404, 'Not Found')
112
+ net_http_response.stub(:body).and_return('<html><body>Not Found</body></html>')
113
+ response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), net_http_response, lambda{ {}})
114
+ error = RightSignature::ResponseError.new(response)
115
+ error.detailed_message.should be_nil
116
+ end
117
+ end
118
+
85
119
  describe "common_solutions" do
86
120
  describe "on 406" do
87
121
  it "should suggest to check Content-Type header, url, or Accept header" do
@@ -15,6 +15,13 @@ describe RightSignature::Helpers::TagsHelper do
15
15
  it "should convert array of string and hash of {name => value} into array of :tag => {:name => name, :value => value}" do
16
16
  RightSignature::Helpers::TagsHelper.array_to_xml_hash(['abc', {"taggy" => "tvalue"}]).should == [{:tag => {:name => 'abc'}}, {:tag => {:name => 'taggy', :value => 'tvalue'}}]
17
17
  end
18
+
19
+ it "should convert a symbol to a string for names and values" do
20
+ RightSignature::Helpers::TagsHelper.array_to_xml_hash([:abc, {:taggy => :tvalue}]).should == [
21
+ {:tag => {:name => 'abc'}},
22
+ {:tag => {:name => 'taggy', :value => 'tvalue'}}
23
+ ]
24
+ end
18
25
  end
19
26
  end
20
27
 
@@ -63,5 +70,16 @@ describe RightSignature::Helpers::MergeFieldsHelper do
63
70
  results.include?({:merge_field => {:value => "Santa Barbara", "@merge_field_id" => "1_abc_defg"}})
64
71
  results.include?({:merge_field => {:value => "House", "@merge_field_id" => "2_345_789"}})
65
72
  end
73
+
74
+ it "should convert a symbol to a string for names and values" do
75
+ results = RightSignature::Helpers::MergeFieldsHelper.array_to_xml_hash([
76
+ {:abc_defg => :SomeValue},
77
+ {:higjk => "House"}
78
+ ], true)
79
+ results.size.should == 2
80
+ results.include?({:merge_field => {:value => "SomeValue", "@merge_field_id" => "abc_defg"}})
81
+ results.include?({:merge_field => {:value => "House", "@merge_field_id" => "higjk"}})
82
+ end
83
+
66
84
  end
67
85
  end
@@ -158,7 +158,7 @@ describe RightSignature::Template do
158
158
  @rs.prefill("MYGUID", "sign me", [], {:tags => [{"I_Key" => "I_Value"}, "Alone"]})
159
159
  end
160
160
 
161
- it "should include options :expires_in, :description, :redirect_location, and :callback_location" do
161
+ it "should include options :expires_in, :description, :redirect_location, :document_data, and :callback_location" do
162
162
  @rs.should_receive(:post).with('/api/templates.xml', {
163
163
  :template => {
164
164
  :guid => "MYGUID",
@@ -168,10 +168,11 @@ describe RightSignature::Template do
168
168
  :expires_in => 15,
169
169
  :description => "Hey, I'm a description",
170
170
  :redirect_location => 'http://example.com/redirectme',
171
+ :document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
171
172
  :callback_location => 'http://example.com/callie'
172
173
  }
173
174
  })
174
- @rs.prefill("MYGUID", "sign me", [], {:expires_in => 15, :description => "Hey, I'm a description", :redirect_location => 'http://example.com/redirectme', :callback_location => "http://example.com/callie"})
175
+ @rs.prefill("MYGUID", "sign me", [], {:expires_in => 15, :description => "Hey, I'm a description", :redirect_location => 'http://example.com/redirectme', :callback_location => "http://example.com/callie", :document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}})
175
176
  end
176
177
  end
177
178
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightsignature
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
5
- prerelease:
4
+ version: 1.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Chee
@@ -11,12 +10,11 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-03-04 00:00:00.000000000 Z
13
+ date: 2013-04-10 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: bundler
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
19
  - - ! '>='
22
20
  - !ruby/object:Gem::Version
@@ -24,7 +22,6 @@ dependencies:
24
22
  type: :development
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
26
  - - ! '>='
30
27
  - !ruby/object:Gem::Version
@@ -32,7 +29,6 @@ dependencies:
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: rspec
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
33
  - - ! '>='
38
34
  - !ruby/object:Gem::Version
@@ -40,7 +36,6 @@ dependencies:
40
36
  type: :development
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
40
  - - ! '>='
46
41
  - !ruby/object:Gem::Version
@@ -48,7 +43,6 @@ dependencies:
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: bundler
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
47
  - - ! '>='
54
48
  - !ruby/object:Gem::Version
@@ -56,7 +50,6 @@ dependencies:
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
54
  - - ! '>='
62
55
  - !ruby/object:Gem::Version
@@ -64,7 +57,6 @@ dependencies:
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: oauth
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
61
  - - ! '>='
70
62
  - !ruby/object:Gem::Version
@@ -72,7 +64,6 @@ dependencies:
72
64
  type: :runtime
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
68
  - - ! '>='
78
69
  - !ruby/object:Gem::Version
@@ -80,7 +71,6 @@ dependencies:
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: httparty
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
75
  - - ! '>='
86
76
  - !ruby/object:Gem::Version
@@ -88,7 +78,6 @@ dependencies:
88
78
  type: :runtime
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
82
  - - ! '>='
94
83
  - !ruby/object:Gem::Version
@@ -96,7 +85,6 @@ dependencies:
96
85
  - !ruby/object:Gem::Dependency
97
86
  name: xml-fu
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
89
  - - ! '>='
102
90
  - !ruby/object:Gem::Version
@@ -104,7 +92,6 @@ dependencies:
104
92
  type: :runtime
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
96
  - - ! '>='
110
97
  - !ruby/object:Gem::Version
@@ -143,27 +130,26 @@ files:
143
130
  - spec/template_spec.rb
144
131
  homepage: http://github.com/rightsignature/rightsignature-api
145
132
  licenses: []
133
+ metadata: {}
146
134
  post_install_message:
147
135
  rdoc_options: []
148
136
  require_paths:
149
137
  - lib
150
138
  required_ruby_version: !ruby/object:Gem::Requirement
151
- none: false
152
139
  requirements:
153
140
  - - ! '>='
154
141
  - !ruby/object:Gem::Version
155
142
  version: '0'
156
143
  required_rubygems_version: !ruby/object:Gem::Requirement
157
- none: false
158
144
  requirements:
159
145
  - - ! '>='
160
146
  - !ruby/object:Gem::Version
161
147
  version: '0'
162
148
  requirements: []
163
149
  rubyforge_project:
164
- rubygems_version: 1.8.23
150
+ rubygems_version: 2.0.3
165
151
  signing_key:
166
- specification_version: 3
152
+ specification_version: 4
167
153
  summary: API wrapper for RightSignature
168
154
  test_files: []
169
155
  has_rdoc: