Last active
December 7, 2022 18:54
-
-
Save frobichaud/2357b52c564459e4ea57e95c0474fa42 to your computer and use it in GitHub Desktop.
HelloSign - Download all documents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_KEY = 'YOUR_API_KEY_HERE' | |
def get_total_pages(client) | |
list = client.get_signature_requests(page_size: 100) | |
list.data["list_info"]["num_pages"] | |
end | |
def get_all_requests(client) | |
signature_requests = [] | |
page = 1 | |
total_pages = get_total_pages(client) | |
while page < total_pages + 1 | |
req = client.get_signature_requests(page_size: 100, page: page) | |
signature_requests << req.data["signature_requests"] | |
page += 1 | |
end | |
signature_requests.flatten | |
end | |
def download_requests(client, requests) | |
requests.each do |req| | |
begin | |
puts "-- Downloading #{req['final_copy_uri']}" | |
download = client.get( | |
req["final_copy_uri"].gsub('/v3', '') | |
) | |
rescue StandardError => e | |
puts "-- Failed #{e.message}" | |
next | |
end | |
fname = clear_title(req["title"]) | |
File.open("HelloSign-#{fname}", "wb") do |file| | |
file.write(download[:body]) | |
end | |
end | |
end | |
def clear_title(str) | |
str = str.gsub(/[^\w]/, '_') | |
str += '.pdf' | |
end | |
client = HelloSign::Client.new(api_key: API_KEY) | |
download_requests(client, get_all_requests(client)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did some tweaks after having trouble running this.
What I'm doing
that makes the entire job "resumable"
My job required downloading lots of pdfs, so the ability to resume was crucial.