Code Monkey home page Code Monkey logo

ckan-client-js's Introduction

CKAN Client: Javascript SDK

contributions welcome build The MIT License

CKAN SDK for interacting with CKAN instances with CKAN v3 style cloud storage. It covers the whole action API as well as convenience methods for uploading files, updating the metastore etc. Tutorial on use at https://tech.datopian.com/ckan-client-guide/. API documentation below.

Frictionless Formats

The client uses Frictionless formats by default for describing dataset and resource objects passed to client methods. Internally we then use the CKAN<=>Frictionless Mapper to convert to CKAN formats before calling the API. Thus, you can use Frictionless Formats by default with the client. (As CKAN moves to Frictionless to default this will gradually become unnecessary).

Install

Node

Prerequisites

Then clone the repo via git:

$ npm install https://github.com/datopian/ckan-client-js.git

or

$ yarn add https://github.com/datopian/ckan-client-js.git

Now you can use the code:

const { Client } = require('ckanClient')
...

Browser

If you want to use it as a script in the browser, then follow the steps below:

$ git clone [email protected]:datopian/ckan-client-js.git
$ cd ckan-client-js
$ npm install
$ npm run build

The last command will create /dist/index.js bundle which can be used in the browser like:

<head>
  <script src="./ckan-client-js/dist/index.js"></script>
  <script>
    // Global ckanClient variable is available here...
    const { Client } = ckanClient;
    ...
  </script>
</head>
<body></body>

Examples

Add a resource to a dataset and save

// pushing some resource to the dataset
dataset.resources.push({
  bytes: 12,
  path: 'https://somecsvonline.com/somecsv.csv',
})

// then saving it, this will return a new dataset with updated fields
const updatedDataset = await client.push(dataset)
console.log(updatedDataset)

Upload resource data and save resource

// to open a file and give a frictionless resource with stream method
// this uses the frictionless js library https://github.com/datopian/data.js
const f11s = require('data.js')

// If it is in Browser you can pass an attached file
const resource = f11s.open('path/to/example.csv')

await client.pushBlob(resource)
// If you are in browser you can also track the progress, in the second argument
// client.pushBlob(resource, (progressEvent) => {
//   let progress = (progressEvent.loaded / progressEvent.total) * 100
//   console.log(progress)
// })

// create a dataset, add resource metadata and save
const dataset = await client.create({
  name: 'dataset-name',
})
dataset.resources.push(resource.descriptor)

const updatedDataset = await client.push(dataset)

API

See API documentation here

Developers

Build

This command will create a bundle in dist

npm run build

Tests

$ npm test

or

$ yarn test

watch the test

$ npm run test:watch

Documentation

We use JSDoc to document the methods we are creating. Those JSDoc comments are being used to generate API docs for README via jsdoc2md.

To generate API markdown docs from JSDoc comments run:

$ npx jsdoc2md example.js

Where example.js is the file where you have implemented new methods. Paste the output in API docs. Make sure you paste only your changes.

Contributing

Please make sure to read the CONTRIBUTING.md Guide before making a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details

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.