1 require 'rubygems' 2 require 'active_resource' 3 4 # Define the ActiveResource class for communication with the API 5 class Contact < ActiveResource::Base 6 self.site = "https://bluetools.moneybird.nl" 7 self.user = "admin" 8 self.password = "testtest" 9 end 10 11 class Invoice < ActiveResource::Base 12 self.site = "https://bluetools.moneybird.nl" 13 self.user = "admin" 14 self.password = "testtest" 15 end 16 17 18 # First, create a new contact 19 contact = Contact.new 20 contact.name = "Example company" 21 contact.email = "test@test.com" 22 23 if contact.save 24 puts "Contact saved" 25 else 26 puts contact.errors.inspect 27 end 28 29 # Then, create a new invoice based on the contact 30 invoice = Invoice.new 31 invoice.contact_id = contact.id 32 invoice.details_attributes = [ 33 { :description => "First line", :price => 1302.50 }, 34 { :description => "Second line", :price => 103.48 } 35 ] 36 37 if invoice.save 38 puts "Invoice saved" 39 else 40 puts invoice.errors.inspect 41 end 42