4. Repositories

Time to put this together in a script

Add list_repos function after create_repo and update the testing section at the bottom.

In the definition section add

    def list_repos(api_url, auth_token):
        '''List all the repositories'''
        req = urllib.request.Request(
            url = api_url+'/repositories',
            data = None,
            headers = {'X-ArchivesSpace-Session': auth_token})
        try:
            response = urllib.request.urlopen(req)
        except urllib.error.HTTPError as e:
            print(e.code)
            print(e.read())
            return None
        except urllib.error.URLError as e:
            print(e.reason())
            return None
        src = response.read().decode('utf-8')
        return json.JSONDecoder().decode(src)

In the test if block add

        # Test list_repos()
        repos = list_repos(api_url, auth_token)
        print("repositores list", json.dumps(repos, indent=4))

(note: the “…” that is just a place holder for the previous tests added)

We’ve added our list_repos and changed the tests at the bottom.

Full listing repo.py