Go back to the main page

The modern Ruby QuickBooks client Part 2

 

"Real world" fixtures

The qbo_api gem's specs were built against an official QuickBooks sandbox and then recorded using the VCR gem. Therefore, you have a fantastically quick way to get started with your integration project in that you can see "real world" QBO API transaction without your own sandbox or even a network connection. Allow me to demonstrate.

  1. Clone the qbo_api gem, switch into the new directory, and bundle
  2.   $ git clone git://github.com/minimul/qbo_api && cd qbo_api
      $ bundle
    
  3. Create a .env file If you are just running the specs then at minimum your .env needs to look like the following:
  4. export QBO_API_CONSUMER_KEY=
    export QBO_API_CONSUMER_SECRET=
    export QBO_API_ACCESS_TOKEN=
    export QBO_API_ACCESS_TOKEN_SECRET=
    export QBO_API_COMPANY_ID=12345
    
    This section is at the 2:48 mark.
  5. Now you can run the specs by doing a bundle exec rspec spec/
  6. Let's get some green before we dive in further. Note: the be is a bash alias for bundle exec.
  7. Let's open up the spec/create_update_delete_spec.rb
  8. Then go to the first spec where abouts the VCR cassette is being recorded.
  9. Here you see how the gem is initialized.
  10. The creds method is defined in the spec/spec_helper.rb
  11. The .env file is loaded by the Dotenv gem.
    Minimul says —

    If you want to see an example of an advanced VCR custom matcher keep reading the spec/spec_helper.rb file. The purpose of the matcher is to make VCR more lenient so that any QuickBooks sandbox can be used.

    This section is at the 5:29 mark.
    The qbo_api initialization and many other methods use keyword arguments, which is the primary reason for the Ruby 2.2.2 requirement.
  12. Before the initialize set QboApi.log = true and run the individual spec.
  13. Use the log feature to view the HTTP transaction to QBO API.
    Here is the full (real not a fictional fixture) request and response for creating an invoice.
  14. Now let's mess around with the response by outputing the invoice's customer name
  15. Add a p response['CustomerRef']['name'] and then comment out the QboApi.log = true to isolate the output to only the customer name.
    This section is at the 7:44 mark.
  16. Next, open up the spec/error_spec.rb and goto the spec titled "handles a validation error".
  17. The spec displays how you can detect an error and how to potentially respond.

Conclusion

When getting started with a QuickBooks integration project using the qbo_api gem leverage the "real world" recorded specs to help you get started quickly.

Comment on this article?

New! Get the book!

Get Ruby flavored QuickBooks related articles delivered to your Mailbox.

Your email is safe with me and you can unsubscribe at any time.

 

Do you have an idea for a QuickBooks integrated app? Wanna put it on the Intuit App Store, which receives hundreds of thousands of daily visitors? I can get your idea on the App store for a fixed price that I will stand behind and not go over budget by a single penny.