Created
May 26, 2016 22:25
-
-
Save jaredk2g/4dce4a2ed9b4e6d5d1ae7573499636b9 to your computer and use it in GitHub Desktop.
Lookup accounts with credits on Invoiced
This file contains 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
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