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 metadata_delete(): """Create a bundle with metadata, print it, delete it, print it.""" # Create a bundle with some metadata. print '*** Creating a bundle with mythical metadata...' data = {'wife': 'Medea', 'husband': 'Jason'} bundle_ref = clarify.create_bundle(name='metadata update test', metadata=data) # Retrieve the metadata and print it. print '*** Retrieving metadata...' metadata_href = bundle_ref['_links']['clarify:metadata']['href'] metadata = clarify.get_metadata(metadata_href) print_metadata_info_quiet(metadata) # Delete the metadata and print it. print '*** Deleting metadata...' clarify.delete_metadata(metadata['_links']['self']['href']) # Retrieve the metadata and print it. print '*** Retrieving metadata...' metadata = clarify.get_metadata(metadata_href) print_metadata_info_quiet(metadata)
def create_and_update(): """Create a bundle with metadata, print it, update it, and print it.""" # Create a bundle with some metadata. print '*** Creating a bundle with mythical metadata...' data = {'wife': 'Medea', 'husband': 'Jason'} bundle_ref = clarify.create_bundle(name='metadata update test', metadata=data) # Retrieve the metadata and print it. print '*** Retrieving metadata...' href = bundle_ref['_links']['clarify:metadata']['href'] metadata = clarify.get_metadata(href) print_metadata_info_quiet(metadata) # Change the metadata print '*** Changing metadata...' data2 = {'wife': 'Clytemnestra', 'husband': ['Agamemnon', 'Aegisthus']} clarify.update_metadata(href, data2) # Retrieve the metadata and print it. print '*** Retrieving metadata...' metadata = clarify.get_metadata(href) print_metadata_info_quiet(metadata)