4. Repositories

adding list_repo

Let’s copy and modify our list_repos definition to list_repo. Paste it after the function list_repos. We’ll be updating the if block too.

In the definition section add

    def list_repo(api_url, auth_token, repo_id):
        '''List all the repositories, return the listing object'''
        req = urllib.request.Request(
            url = api_url+'/repositories/'+str(repo_id),
            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 for list_repo
        repo_id = int(input('Enter repo id (e.g. 2): '))
        repo = list_repo(api_url, auth_token, repo_id)
        print('repository', json.dumps(repo, indent=4))

Are the results what you expected? Are we still getting an array?

Full listing repo.py