#!/usr/bin/env python

"""
Step 3
======
In this step, we'll create a new history named 'Step 3' and get details on it.
"""
import os
import sys
import pprint

import users_1
# note: that we're using the new histories module for this step
import histories_3

# we'll store the name the new history here
# if it ever changes, we can easily modify it once here no matter how many times we reference it in the code
NEW_HISTORY_NAME = 'Step 3'

# ----------------------------------------------------------------------------- main
if __name__ == '__main__':
    try:
        # we don't need some of the code from the previous steps - they were for demonstration
        # we'll comment them out here and remove them entirely from following steps
        #histories = histories_1.get_histories()
        #current_history_summary = histories[0]
        #current_history_id = current_history_summary[ 'id' ]
        #current_history_details = histories_2.get_history( current_history_id )

        # (we'll keep the call to users as it provides a good check to see if we connected and have access)
        users = users_1.get_users()

        new_history = histories_3.create_history( NEW_HISTORY_NAME )
        # it's never a bad idea to output what's going on in your script if you can
        print 'created history!', new_history[ 'name' ]
        new_history_id = new_history[ 'id' ]
        new_history_details = histories_3.get_history( new_history_id )
        
    except Exception, exc:
        print 'Error creating history:', str( exc )
        sys.exit( 1 )

    print 'new history:'
    pprint.pprint( new_history_details, indent=2 )
