Skip to content

Commit 53b1909

Browse files
authored
Merge pull request #33 from joenio/get-dataset-files
added `getDatasetFiles($datasetId)` to download files
2 parents 5aac40f + 5943ad6 commit 53b1909

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ http://demo.dataverse.org/api/datasets/389608/versions/1
6565

6666
`public async deleteDataset(datasetId: string): Promise<AxiosResponse> {`
6767

68+
`public async getDatasetFiles(datasetId: string): Promise<AxiosResponse> {`
69+
6870
## Build project
6971

7072
In order to build the project, we need to run the following command:

src/dataverseClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ export class DataverseClient {
190190
return this.deleteRequest(url)
191191
}
192192

193+
public async getDatasetFiles(datasetId: string): Promise<AxiosResponse> {
194+
const url = `${this.host}/api/access/dataset/:persistentId/?persistentId=${datasetId}`
195+
return this.getRequest(url, {
196+
headers: this.getHeaders(),
197+
responseType: 'arraybuffer'
198+
})
199+
}
200+
193201
private async getRequest(url: string, options: { params?: object, headers?: DataverseHeaders, responseType?: ResponseType } = { headers: this.getHeaders() }): Promise<AxiosResponse> {
194202
return await axios.get(url, options).catch(error => {
195203
throw new DataverseException(error.response.status, error.response.data ? error.response.data.message : '')

test/dataverseClient.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,4 +1526,18 @@ describe('DataverseClient', () => {
15261526
})
15271527
})
15281528

1529+
describe('getDatasetFiles()', () => {
1530+
it('should call axios with expected url', async () => {
1531+
const datasetId: string = random.number.toString()
1532+
1533+
await client.getDatasetFiles(datasetId)
1534+
1535+
assert.calledOnce(axiosGetStub)
1536+
assert.calledWithExactly(axiosGetStub, `${host}/api/access/dataset/:persistentId/?persistentId=${datasetId}`, {
1537+
headers: { 'X-Dataverse-key': apiToken },
1538+
responseType: 'arraybuffer'
1539+
})
1540+
})
1541+
})
1542+
15291543
})

0 commit comments

Comments
 (0)