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

Commit

Permalink
Merge pull request #82 from HelloFax/Headers
Browse files Browse the repository at this point in the history
Headers
  • Loading branch information
michaelnlindsay authored Jul 13, 2018
2 parents 9e37255 + 85bdc14 commit e928221
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 64 deletions.
3 changes: 1 addition & 2 deletions lib/hello_sign/api/signature_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def get_signature_requests(opts={})
query = create_query_string(opts, [:page, :page_size, :ux_version, :query])
path += query
HelloSign::Resource::ResourceArray.new get(path, opts), 'signature_requests', HelloSign::Resource::SignatureRequest

end

#
Expand Down Expand Up @@ -125,7 +124,7 @@ def send_signature_request(opts)
prepare_form_fields opts
prepare_custom_fields opts

HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
request = HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
end

#
Expand Down
12 changes: 8 additions & 4 deletions lib/hello_sign/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def initialize(opts={})
def get(path, options={})
response = request(path, :get, options)
validate response
parse response
parsed_response = parse response
data = { headers: response.headers, body: parsed_response }
end

#
Expand All @@ -102,7 +103,8 @@ def get(path, options={})
def post(path, options={})
response = request(path, :post, options)
validate response
parse response
parsed_response = parse response
data = { headers: response.headers, body: parsed_response }
end

#
Expand All @@ -114,7 +116,8 @@ def post(path, options={})
def put(path, options={})
response = request(path, :put, options)
validate response
parse response
responsed_response = parse response
data = { headers: response.headers, body: parsed_response }
end

#
Expand All @@ -125,7 +128,8 @@ def put(path, options={})
def delete(path, options={})
response = request(path, :delete, options)
validate response
parse response
parsed_response = parse response
data = { headers: response.headers, body: parsed_response }
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/hello_sign/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# The MIT License (MIT)
#
#
# Copyright (C) 2014 hellosign.com
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
Expand Down
26 changes: 8 additions & 18 deletions lib/hello_sign/resource/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module Resource
#
class BaseResource

attr_reader :data, :raw_data, :warnings, :headers

#
# recursively convert hash data into BaseResource.
#
Expand All @@ -40,8 +42,12 @@ class BaseResource
#
# @return [HelloSign::Resource::BaseResource] a new BaseResource
def initialize(hash, key=nil)
@raw_data = key ? hash[key] : hash
@warnings = hash['warnings'] ? hash['warnings'] : nil
@headers = hash[:headers]
@raw_data = key ? hash[:body][key] : hash
if hash[:body]
@warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil
end

@data = @raw_data.inject({}) do |data, (key, value)|
data[key.to_s] = if value.is_a? Hash
value = BaseResource.new(value)
Expand Down Expand Up @@ -70,22 +76,6 @@ def initialize(hash, key=nil)
def method_missing(method)
@data.key?(method.to_s) ? @data[method.to_s] : nil
end

#
# raw response data from the server in json
#
# @return [type] [description]
def data
@raw_data
end

#
# shows any warnings returned with the api response, if present
#
# @return [Array<Hash>, nil] Array of warning hashes in format {'warning_msg' => val, 'warning_name' => val} or nil
def warnings
@warnings
end
end
end
end
18 changes: 9 additions & 9 deletions lib/hello_sign/resource/resource_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Resource
# @author [hellosign]
#
class ResourceArray < Array
attr_reader :page, :num_pages, :num_results, :page_size, :warnings
attr_reader :page, :num_pages, :num_results, :page_size, :warnings, :headers, :list_info

#
# create a new ResourceArray from a hash
Expand All @@ -42,18 +42,18 @@ class ResourceArray < Array
#
# @return [type] [description]
def initialize(hash, key, resource_class)
@page = hash['list_info']['page']
@num_pages = hash['list_info']['num_pages']
@num_results = hash['list_info']['num_results']
@page_size = hash['list_info']['page_size']
@warnings = hash['warnings'] ? hash['warnings'] : nil

self << resource_class.new(hash, nil)
@headers = hash[:headers]
@list_info = hash[:body]['list_info']
@page = @list_info['page']
@num_pages = @list_info['num_pages']
@num_results = @list_info['num_results']
@page_size = @list_info['page_size']
@warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil
self << resource_class.new(hash[:body], nil)

hash[key] && hash[key].each do |resource|
self << resource_class.new(resource, nil)
end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hello_sign/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
#

module HelloSign
VERSION = '3.6.4'
VERSION = '3.7.0'
end
2 changes: 1 addition & 1 deletion spec/fixtures/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"callback_url": "https://example.com",
"role_code": ""
}
}
}
18 changes: 18 additions & 0 deletions spec/fixtures/headers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"date": "Wed, 28 Feb 2018 21:17:07 GMT",
"content-type": "application/json",
"content-length": "529",
"connection": "close",
"set-cookie": "AWSALB=DQqaS5np0cXpMMcb1IanILXEmtw8XOZBceauEE76KNzGzua1fJXaht/7XAaqSTiIQMBIzcTTeq2IJ0/jRmt8iWjVVwlY5JWmgyUV8r3vJaSBjcZ4fMbPNhS8SPmH; Expires=Wed, 07 Mar 2018 21:17:04 GMT; Path=/",
"server": "Apache",
"strict-transport-security": "max-age=15768000",
"x-ratelimit-limit": "2000",
"x-ratelimit-limit-remaining": "1998",
"x-ratelimit-reset": "1519852625",
"access-control-allow-origin": "*",
"access-control-allow-headers": "Authorization, Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods": "GET, POST, OPTIONS",
"user-agent": "HelloSign API",
"vary": "Accept-Encoding",
"p3p": "CP='NOP3PPOLICY'"
}
11 changes: 9 additions & 2 deletions spec/fixtures/signature_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,12 @@
"last_reminded_at": 1393389852
}],
"cc_email_addresses": []
}
}
},

"warnings": [
{
"warning_msg": "No data provided for custom field checkbox, will default to false.",
"warning_name": "parameter_missing"
}
]
}
8 changes: 8 additions & 0 deletions spec/hello_sign/api/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
expect(a_get('/account')).to have_been_made
end

it 'should have response headers' do
expect(@account.headers).to_not be_nil
end

it 'should return current user account' do
expect(@account).to be_an HelloSign::Resource::Account
end
Expand All @@ -27,6 +31,10 @@
expect(a_post('/account/create')).to have_been_made
end

it 'should return response headers' do
expect(@account.headers).to_not be_nil
end

it 'should return information about a created account' do
expect(@account.email_address).to eql('[email protected]')
end
Expand Down
16 changes: 16 additions & 0 deletions spec/hello_sign/api/api_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
expect(a_get('/api_app/5e365c014bea2e9a05a9d0834f3e7ca4')).to have_been_made
end

it 'should return response headers' do
expect(@api_app.headers).to_not be_nil
end

it 'should return current user account' do
expect(@api_app).to be_an HelloSign::Resource::ApiApp
end
Expand All @@ -27,6 +31,10 @@
expect(a_get('/api_app/list')).to have_been_made
end

it 'should return response headers' do
expect(@api_apps.headers).to_not be_nil
end

it 'should return a Resource Array' do
expect(@api_apps).to be_an HelloSign::Resource::ResourceArray
end
Expand All @@ -50,6 +58,10 @@
expect(a_post('/api_app')).to have_been_made
end

it 'should return response headers' do
expect(@api_app.headers).to_not be_nil
end

it 'should return an ApiApp' do
expect(@api_app).to be_an HelloSign::Resource::ApiApp
end
Expand All @@ -69,6 +81,10 @@
expect(a_post('/api_app/5e365c014bea2e9a05a9d0834f3e7ca4')).to have_been_made
end

it 'should return response headers' do
expect(@api_app.headers).to_not be_nil
end

it 'should return an ApiApp' do
expect(@api_app).to be_an HelloSign::Resource::ApiApp
end
Expand Down
4 changes: 4 additions & 0 deletions spec/hello_sign/api/embedded_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
expect(a_get("/embedded/sign_url/#{signature_id}")).to have_been_made
end

it 'should return response headers' do
expect(@embedded.headers).to_not be_nil
end

it 'should return a UnclaimedDraft' do
expect(@embedded).to be_an HelloSign::Resource::Embedded
end
Expand Down
32 changes: 32 additions & 0 deletions spec/hello_sign/api/signature_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
expect(a_get('/signature_request/1')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end

it 'should return a SignatureRequest' do
expect(@signature_request).to be_an HelloSign::Resource::SignatureRequest
end
Expand All @@ -26,6 +30,10 @@
expect(a_get('/signature_request/list')).to have_been_made
end

it 'should return response headers' do
expect(@signature_requests.headers).to_not be_nil
end

it 'should return a SignatureRequestArray' do
expect(@signature_requests).to be_an HelloSign::Resource::ResourceArray
end
Expand Down Expand Up @@ -71,6 +79,14 @@
expect(a_post('/signature_request/remind/1')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end

it 'should return response warnings' do
expect(@signature_request.warnings).to_not be_nil
end

it 'should return a SignatureRequest' do
expect(@signature_request).to be_an HelloSign::Resource::SignatureRequest
end
Expand Down Expand Up @@ -153,6 +169,10 @@
it 'should get the correct resource' do
expect(a_post('/signature_request/send_with_template')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end
end

describe '#create_embedded_signature_request' do
Expand All @@ -164,6 +184,10 @@
it 'should get the correct resource' do
expect(a_post('/signature_request/create_embedded')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end
end

describe '#create_embedded_signature_request_with_template' do
Expand All @@ -175,6 +199,10 @@
it 'should get the correct resource' do
expect(a_post('/signature_request/create_embedded_with_template')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end
end

describe '#update_signature_request' do
Expand All @@ -191,6 +219,10 @@
expect(a_post('/signature_request/update/1')).to have_been_made
end

it 'should return response headers' do
expect(@signature_request.headers).to_not be_nil
end

it 'should return a Signature Request' do
expect(@signature_request).to be_a HelloSign::Resource::SignatureRequest
end
Expand Down
Loading

0 comments on commit e928221

Please sign in to comment.