Skip to content

Instantly share code, notes, and snippets.

@jaredk2g
Created May 26, 2016 22:25
Show Gist options
  • Save jaredk2g/4dce4a2ed9b4e6d5d1ae7573499636b9 to your computer and use it in GitHub Desktop.
Save jaredk2g/4dce4a2ed9b4e6d5d1ae7573499636b9 to your computer and use it in GitHub Desktop.
Lookup accounts with credits on Invoiced
require 'invoiced'
invoiced = Invoiced::Client.new('your_api_key')
more = true
page = 1
while more do
# Fetch a page of customers with a credit balance
customers, metadata = invoiced.Customer.list(
:balance => true,
:page => page)
# Look up the credit balance for each customer
customers.each do |customer|
balance = customer.balance
print "#{customer.name} has $#{balance[:available_credits]} available credits\n"
end
# Check if there is a next page
more = metadata.links.key?(:next)
page += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment