Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit e928221

Browse files
Merge pull request #82 from HelloFax/Headers
Headers
2 parents 9e37255 + 85bdc14 commit e928221

18 files changed

+216
-64
lines changed

lib/hello_sign/api/signature_request.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def get_signature_requests(opts={})
6868
query = create_query_string(opts, [:page, :page_size, :ux_version, :query])
6969
path += query
7070
HelloSign::Resource::ResourceArray.new get(path, opts), 'signature_requests', HelloSign::Resource::SignatureRequest
71-
7271
end
7372

7473
#
@@ -125,7 +124,7 @@ def send_signature_request(opts)
125124
prepare_form_fields opts
126125
prepare_custom_fields opts
127126

128-
HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
127+
request = HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
129128
end
130129

131130
#

lib/hello_sign/client.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def initialize(opts={})
9090
def get(path, options={})
9191
response = request(path, :get, options)
9292
validate response
93-
parse response
93+
parsed_response = parse response
94+
data = { headers: response.headers, body: parsed_response }
9495
end
9596

9697
#
@@ -102,7 +103,8 @@ def get(path, options={})
102103
def post(path, options={})
103104
response = request(path, :post, options)
104105
validate response
105-
parse response
106+
parsed_response = parse response
107+
data = { headers: response.headers, body: parsed_response }
106108
end
107109

108110
#
@@ -114,7 +116,8 @@ def post(path, options={})
114116
def put(path, options={})
115117
response = request(path, :put, options)
116118
validate response
117-
parse response
119+
responsed_response = parse response
120+
data = { headers: response.headers, body: parsed_response }
118121
end
119122

120123
#
@@ -125,7 +128,8 @@ def put(path, options={})
125128
def delete(path, options={})
126129
response = request(path, :delete, options)
127130
validate response
128-
parse response
131+
parsed_response = parse response
132+
data = { headers: response.headers, body: parsed_response }
129133
end
130134

131135
private

lib/hello_sign/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22
# The MIT License (MIT)
3-
#
3+
#
44
# Copyright (C) 2014 hellosign.com
5-
#
5+
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
88
# in the Software without restriction, including without limitation the rights

lib/hello_sign/resource/base_resource.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module Resource
3232
#
3333
class BaseResource
3434

35+
attr_reader :data, :raw_data, :warnings, :headers
36+
3537
#
3638
# recursively convert hash data into BaseResource.
3739
#
@@ -40,8 +42,12 @@ class BaseResource
4042
#
4143
# @return [HelloSign::Resource::BaseResource] a new BaseResource
4244
def initialize(hash, key=nil)
43-
@raw_data = key ? hash[key] : hash
44-
@warnings = hash['warnings'] ? hash['warnings'] : nil
45+
@headers = hash[:headers]
46+
@raw_data = key ? hash[:body][key] : hash
47+
if hash[:body]
48+
@warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil
49+
end
50+
4551
@data = @raw_data.inject({}) do |data, (key, value)|
4652
data[key.to_s] = if value.is_a? Hash
4753
value = BaseResource.new(value)
@@ -70,22 +76,6 @@ def initialize(hash, key=nil)
7076
def method_missing(method)
7177
@data.key?(method.to_s) ? @data[method.to_s] : nil
7278
end
73-
74-
#
75-
# raw response data from the server in json
76-
#
77-
# @return [type] [description]
78-
def data
79-
@raw_data
80-
end
81-
82-
#
83-
# shows any warnings returned with the api response, if present
84-
#
85-
# @return [Array<Hash>, nil] Array of warning hashes in format {'warning_msg' => val, 'warning_name' => val} or nil
86-
def warnings
87-
@warnings
88-
end
8979
end
9080
end
9181
end

lib/hello_sign/resource/resource_array.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Resource
3131
# @author [hellosign]
3232
#
3333
class ResourceArray < Array
34-
attr_reader :page, :num_pages, :num_results, :page_size, :warnings
34+
attr_reader :page, :num_pages, :num_results, :page_size, :warnings, :headers, :list_info
3535

3636
#
3737
# create a new ResourceArray from a hash
@@ -42,18 +42,18 @@ class ResourceArray < Array
4242
#
4343
# @return [type] [description]
4444
def initialize(hash, key, resource_class)
45-
@page = hash['list_info']['page']
46-
@num_pages = hash['list_info']['num_pages']
47-
@num_results = hash['list_info']['num_results']
48-
@page_size = hash['list_info']['page_size']
49-
@warnings = hash['warnings'] ? hash['warnings'] : nil
50-
51-
self << resource_class.new(hash, nil)
45+
@headers = hash[:headers]
46+
@list_info = hash[:body]['list_info']
47+
@page = @list_info['page']
48+
@num_pages = @list_info['num_pages']
49+
@num_results = @list_info['num_results']
50+
@page_size = @list_info['page_size']
51+
@warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil
52+
self << resource_class.new(hash[:body], nil)
5253

5354
hash[key] && hash[key].each do |resource|
5455
self << resource_class.new(resource, nil)
5556
end
56-
5757
end
5858
end
5959
end

lib/hello_sign/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
#
2424

2525
module HelloSign
26-
VERSION = '3.6.4'
26+
VERSION = '3.7.0'
2727
end

spec/fixtures/account.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"callback_url": "https://example.com",
1313
"role_code": ""
1414
}
15-
}
15+
}

spec/fixtures/headers.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"date": "Wed, 28 Feb 2018 21:17:07 GMT",
3+
"content-type": "application/json",
4+
"content-length": "529",
5+
"connection": "close",
6+
"set-cookie": "AWSALB=DQqaS5np0cXpMMcb1IanILXEmtw8XOZBceauEE76KNzGzua1fJXaht/7XAaqSTiIQMBIzcTTeq2IJ0/jRmt8iWjVVwlY5JWmgyUV8r3vJaSBjcZ4fMbPNhS8SPmH; Expires=Wed, 07 Mar 2018 21:17:04 GMT; Path=/",
7+
"server": "Apache",
8+
"strict-transport-security": "max-age=15768000",
9+
"x-ratelimit-limit": "2000",
10+
"x-ratelimit-limit-remaining": "1998",
11+
"x-ratelimit-reset": "1519852625",
12+
"access-control-allow-origin": "*",
13+
"access-control-allow-headers": "Authorization, Origin, X-Requested-With, Content-Type, Accept",
14+
"access-control-allow-methods": "GET, POST, OPTIONS",
15+
"user-agent": "HelloSign API",
16+
"vary": "Accept-Encoding",
17+
"p3p": "CP='NOP3PPOLICY'"
18+
}

spec/fixtures/signature_request.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@
3434
"last_reminded_at": 1393389852
3535
}],
3636
"cc_email_addresses": []
37-
}
38-
}
37+
},
38+
39+
"warnings": [
40+
{
41+
"warning_msg": "No data provided for custom field checkbox, will default to false.",
42+
"warning_name": "parameter_missing"
43+
}
44+
]
45+
}

spec/hello_sign/api/account_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
expect(a_get('/account')).to have_been_made
1212
end
1313

14+
it 'should have response headers' do
15+
expect(@account.headers).to_not be_nil
16+
end
17+
1418
it 'should return current user account' do
1519
expect(@account).to be_an HelloSign::Resource::Account
1620
end
@@ -27,6 +31,10 @@
2731
expect(a_post('/account/create')).to have_been_made
2832
end
2933

34+
it 'should return response headers' do
35+
expect(@account.headers).to_not be_nil
36+
end
37+
3038
it 'should return information about a created account' do
3139
expect(@account.email_address).to eql('test@example.com')
3240
end

0 commit comments

Comments
 (0)