Code Monkey home page Code Monkey logo

Comments (3)

mariorodeghiero avatar mariorodeghiero commented on May 25, 2024

Use in Datapub:

await client.put('resource_create', resource.descriptor)

The SDK implemented:

index.js

const ActionApi = require('./util/action-api')

class Client {
  constructor(authToken, organizationId, datasetId, api) {
    this.authToken = authToken
    this.organizationId = organizationId
    this.datasetId = datasetId
    this.api = api
  }

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

module.exports = {
  Client,
}

Action function:

const ActionApi = {

  // Call the ckan api actions ie. 'package_create'
  action: async (baseUrl, authToken, actionType, data) => {
    const path = `/api/3/action/${actionType}`
    const config = {
      headers: {
        'Content-Type': 'application/json;charset=utf-8',
        Authorization: authToken,
      }
    }
    const body = JSON.stringify(data)

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

    return response.data
  },
}

from ckan-client-js.

rufuspollock avatar rufuspollock commented on May 25, 2024

The action method should be part of Client class

class Client {

  // Call the ckan api actions ie. 'package_create'
  action: async(actionType, payload, forceHttpGet=false) => {
    const path = `/api/3/action/${actionType}`
    const config = {
      headers: {
        'Content-Type': 'application/json;charset=utf-8',
        Authorization: this.authToken,
      }
    }

    const body = JSON.stringify(data)
    
    // TODO: if forceHttpGet then ...
    
    const response = await axios.post(`${baseUrl}${path}`, data, config)
    if (!response.data.success) {
      throw `Action response: ${response.statusText}`
    }
    return response.data
  },
}

from ckan-client-js.

kmanaseryan avatar kmanaseryan commented on May 25, 2024

Covered in #14

from ckan-client-js.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.