Skip to content

Commit

Permalink
Merge pull request #14 from datopian/feature/action
Browse files Browse the repository at this point in the history
#4 Add support for generic action request to CKAN
  • Loading branch information
rufuspollock committed Sep 14, 2020
2 parents 1010a85 + 573529f commit c3605f4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mapper = require('frictionless-ckan-mapper-js')
const axios = require('axios')

const CkanAuthApi = require('./util/ckan-auth-api')
const CkanUploadAPI = require('./util/ckan-upload-api')
Expand Down Expand Up @@ -36,6 +37,29 @@ class Client {
throw 'invalid URL argument'
}

/**
* Make action request CKAN. For more info check
* https://docs.ckan.org/en/latest/api/index.html#action-api-reference
* @param {string} actionName - The action name, e.g. site_read, package_show ...
* @param {object} payload - The payload being sent to CKAN
*/
async action(actionName, payload) {
const path = `/api/3/action/${actionName}`
const config = {
headers: {
'Content-Type': 'application/json;charset=utf-8',
Authorization: this.authToken,
},
}

const response = await axios.post(`${this.api}${path}`, payload, config)
if (!response.data.success) {
throw `Action response: ${response.statusText}`
}

return response.data
}

put(actionType, data) {
return ActionApi.action(this.api, this.authToken, actionType, data)
}
Expand Down

0 comments on commit c3605f4

Please sign in to comment.