Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 Add support for generic action request to CKAN #14

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
kmanaseryan marked this conversation as resolved.
Show resolved Hide resolved
const path = `/api/3/action/${actionName}`
const config = {
headers: {
'Content-Type': 'application/json;charset=utf-8',
Authorization: this.authToken,
kmanaseryan marked this conversation as resolved.
Show resolved Hide resolved
},
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd probably want to include a bit more info but that is good ...

}

return response.data
}

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