def metadata_create(): """Create metadata and create a bundle with it.""" # Create a bundle with metadata. # Note that all examples below are valid. print '*** Creating a bundle with mythical metadata...' data = {'wife': 'Medea', 'husband': 'Jason'} # data = {'wife': 'Medea', 'lovers': ['Aegisthus', 'Pancreon']} # data = {'daughters': 1, 'sons': 3} # data = {'hot': True, 'cold': False, 'tepid': None} bundle_ref = clarify.create_bundle(name='md test', metadata=data) # # 3 different ways to retrieve our metadata! # # (1) Retrieve the metadata from bundle reference. Print it. print '*** Retrieving metadata from bundle reference...' href = bundle_ref['_links']['clarify:metadata']['href'] metadata = clarify.get_metadata(href) print_metadata_info_quiet(metadata) # (2) Retrieve the bundle, then retrieve the metadata. Print it. print '*** Retrieving the bundle then the metadata...' href = clarify.get_bundle(bundle_ref['_links']['self']['href']) metadata = clarify.get_metadata(href['_links']['clarify:metadata']['href']) print_metadata_info_quiet(metadata) # (3) Retrieve the bundle with the metadata embedded. Print it. print '*** Retrieving the bundle with embedded metadata...' href = clarify.get_bundle(bundle_ref['_links']['self']['href'], embed_metadata=True) metadata = href['_embedded']['clarify:metadata'] print_metadata_info_quiet(metadata)
def metadata_create(): """Create metadata and create a bundle with it.""" # Create a bundle with metadata. # Note that all examples below are valid. print "*** Creating a bundle with mythical metadata..." data = {"wife": "Medea", "husband": "Jason"} # data = {'wife': 'Medea', 'lovers': ['Aegisthus', 'Pancreon']} # data = {'daughters': 1, 'sons': 3} # data = {'hot': True, 'cold': False, 'tepid': None} bundle_ref = clarify.create_bundle(name="md test", metadata=data) # # 3 different ways to retrieve our metadata! # # (1) Retrieve the metadata from bundle reference. Print it. print "*** Retrieving metadata from bundle reference..." href = bundle_ref["_links"]["clarify:metadata"]["href"] metadata = clarify.get_metadata(href) print_metadata_info_quiet(metadata) # (2) Retrieve the bundle, then retrieve the metadata. Print it. print "*** Retrieving the bundle then the metadata..." href = clarify.get_bundle(bundle_ref["_links"]["self"]["href"]) metadata = clarify.get_metadata(href["_links"]["clarify:metadata"]["href"]) print_metadata_info_quiet(metadata) # (3) Retrieve the bundle with the metadata embedded. Print it. print "*** Retrieving the bundle with embedded metadata..." href = clarify.get_bundle(bundle_ref["_links"]["self"]["href"], embed_metadata=True) metadata = href["_embedded"]["clarify:metadata"] print_metadata_info_quiet(metadata)
def process_exception(): """Create an exception, capture it, print it.""" try: print '*** Generating an error...' bad_href = '/' + __api_version__ + '/' + \ clarify.BUNDLES_PATH + '/' + 'bozo' clarify.get_bundle(href=bad_href) except clarify.APIException, exception: print '*** Caught APIException' print 'code = ' + str(exception.get_code()) print 'status = ' + exception.get_status() print 'message = ' + exception.get_message()
def create_15_bundles(): """Create 15 bundles without any media.""" for i in range(0, 15): bundle_ref = clarify.create_bundle(str(i)) href = bundle_ref['_links']['self']['href'] bundle = clarify.get_bundle(href) print '*** Created bundle ' + href + ' with name: ' + bundle['name']
def update_name(href): """Update the name of the bundle at href.""" bundle = clarify.get_bundle(href) name = bundle.get('name') if name is None: name = 'no name updated' else: name = name + ' updated' print '*** Updating name for ' + href clarify.update_bundle(href, name)
def print_bundle(href): """Function to print an bundle from an href.""" bundle = clarify.get_bundle(href) print '* Bundle ' + bundle['id'] + '...' if 'name' in bundle: print 'name: ' + bundle['name'] if 'external_id' in bundle: print 'external_id: ' + bundle['external_id'] if 'notify_url' in bundle: print 'notify_url: ' + bundle['notify_url'] print 'created: ' + bundle['created'] print 'updated: ' + bundle['updated']
def print_name(href): """Print the name of the bundle at href.""" bundle = clarify.get_bundle(href) print '*** ' + href + ' is now named "' + bundle['name'] + '"'