Skip to content

Instantly share code, notes, and snippets.

@mbailey
Created May 26, 2011 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbailey/993252 to your computer and use it in GitHub Desktop.
Save mbailey/993252 to your computer and use it in GitHub Desktop.
Download all your blinksale invoices as PDFs
#!/usr/bin/env ruby
require 'rubygems'
require 'highline/import'
require 'mechanize'
require 'uri'
# Get details
domain = ask("your blinksale domain prefix") { |q| q.default = 'mikebailey'} + '.blinksale.com'
login_page_url = "https://#{domain}/sessions/new"
invoice_list_url = "https://#{domain}/invoices/all/date/2001-01-01/2015-12-31"
agent = Mechanize.new
# agent.user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)"
agent.pluggable_parser.pdf = Mechanize::FileSaver
# Login to BlinkSale
page = agent.get(login_page_url)
form = page.forms.first
form.username = ask("your blinksale username") { |q| q.default = 'mbailey' }
form.password = ask("your blinksale password") { |q| q.echo = false; }
page = agent.submit form
# Grab list of your invoices
invoice_list = agent.get(invoice_list_url)
# Download all the PDF's
links = invoice_list.links_with(:href => /invoices\/\d+/).collect { |link|
link.uri.to_s + '.pdf'
}.compact
links.each {|link| agent.get(link) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment