{"_id":"ckan","_rev":"25-ac34572b55c13d8e82320ef5c7e3a1bf","name":"ckan","description":"A Javascript client library for [CKAN][] designed for both the browser and NodeJS.","dist-tags":{"latest":"0.2.3"},"versions":{"0.1.0":{"name":"ckan","version":"0.1.0","author":{"name":"Open Knowledge Foundation","email":"labs@okfn.org"},"repository":{"type":"git","url":"https://github.com/okfn/ckan.js"},"license":"MIT","dependencies":{"request":"","underscore":""},"devDependencies":{},"description":"A Javascript client library for [CKAN][] designed for both the browser and NodeJS.","bugs":{"url":"https://github.com/okfn/ckan.js/issues"},"_id":"ckan@0.1.0","dist":{"shasum":"a087cba0f78fe0f158ef2f1056d2a24ef7f03a70","tarball":"https://registry.npmjs.org/ckan/-/ckan-0.1.0.tgz","integrity":"sha512-/WNze+Ts2TYTF5LXidgxacFxeo+pcxEDli51IqC0Mqh4ZP2msy3KncnccJyeFPepkPonaCFEWoGZpkfRSYu1lA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCjwwH/wiGIYPP73XeimIJS/9ip3b58Ef205pP00xr2BgIhAJC5DPhOlFG8BvklMnfyEIspNvZPFQzeUPdcgOX1nBfh"}]},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"rufuspollock","email":"rufus.pollock@okfn.org"},"maintainers":[{"name":"rufuspollock","email":"rufus.pollock@okfn.org"}]},"0.2.1":{"name":"ckan","version":"0.2.1","author":{"name":"Open Knowledge Foundation","email":"labs@okfn.org"},"main":"ckan.js","repository":{"type":"git","url":"https://github.com/okfn/ckan.js"},"license":"MIT","dependencies":{"request":"","underscore":""},"devDependencies":{},"description":"A Javascript client library for [CKAN][] designed for both the browser and NodeJS.","bugs":{"url":"https://github.com/okfn/ckan.js/issues"},"_id":"ckan@0.2.1","dist":{"shasum":"89e3c18e8e9455a8d771730dc0b20e57cacaecae","tarball":"https://registry.npmjs.org/ckan/-/ckan-0.2.1.tgz","integrity":"sha512-HUPEM5D8zsgM9Z6/sMnSZFyVLoK0cKoOhdlBYtOV4WRbzMQODV/9iMpxvMrzgeY46TH3lJg1gKGri+RG0uSvTA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDYgiHjJkydZBDdPdeRAYhvirjxVVAJuei1dwi3rAoMqAiBeBrFQGRNMWWU4EoO4KAJiZJtjdtvqdjnrGUXB6W57kA=="}]},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"rufuspollock","email":"rufus.pollock@okfn.org"},"maintainers":[{"name":"rufuspollock","email":"rufus.pollock@okfn.org"}]},"0.2.2":{"name":"ckan","version":"0.2.2","author":{"name":"Open Knowledge Foundation","email":"labs@okfn.org"},"main":"ckan.js","repository":{"type":"git","url":"https://github.com/okfn/ckan.js"},"license":"MIT","dependencies":{"request":"","underscore":""},"devDependencies":{},"gitHead":"380257db90e2ac91b9f8c8023cf446b905a7d070","description":"A Javascript client library for [CKAN][] designed for both the browser and NodeJS.","bugs":{"url":"https://github.com/okfn/ckan.js/issues"},"homepage":"https://github.com/okfn/ckan.js","_id":"ckan@0.2.2","scripts":{},"_shasum":"d5ac7866aea169652df719bc9da768e2adf47d23","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"rufuspollock","email":"rufus.pollock@okfn.org"},"maintainers":[{"name":"rufuspollock","email":"rufus.pollock@okfn.org"}],"dist":{"shasum":"d5ac7866aea169652df719bc9da768e2adf47d23","tarball":"https://registry.npmjs.org/ckan/-/ckan-0.2.2.tgz","integrity":"sha512-WcQTv8WcGygEbfRXPMdKzYRM6aOEWP8ppb/EBzmP/ksbwLsinnCzJ3PFrGoYsnkpopT+3P3tlFwiEkLyZIAiww==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH7Nbds3w0v3LV+KMxPmKR2rONLzLQ3vBMSSFlIC/1FxAiAjbziFKzehwL4ov5L9Ieq82Xt8k4J0BnMlCbydmaue0A=="}]}},"0.2.3":{"name":"ckan","version":"0.2.3","author":{"name":"Open Knowledge Foundation","email":"labs@okfn.org"},"main":"ckan.js","repository":{"type":"git","url":"https://github.com/okfn/ckan.js"},"license":"MIT","dependencies":{"request":"~= 2.51.0","underscore":"~= 1.7.0"},"devDependencies":{},"gitHead":"baab1ac3d9a09b708b2ebd0ca85f86e0429517a4","description":"A Javascript client library for [CKAN][] designed for both the browser and NodeJS.","bugs":{"url":"https://github.com/okfn/ckan.js/issues"},"homepage":"https://github.com/okfn/ckan.js","_id":"ckan@0.2.3","scripts":{},"_shasum":"0700e8d45f15e736572f320bfa8a1764b12959b5","_from":".","_npmVersion":"2.1.3","_nodeVersion":"0.10.32","_npmUser":{"name":"rufuspollock","email":"rufus.pollock@okfn.org"},"maintainers":[{"name":"rufuspollock","email":"rufus.pollock@okfn.org"}],"dist":{"shasum":"0700e8d45f15e736572f320bfa8a1764b12959b5","tarball":"https://registry.npmjs.org/ckan/-/ckan-0.2.3.tgz","integrity":"sha512-56lEFEpIKr8jLjf2vAydZJosEoVLviniSnzINuLSWGk+pMFwUZ+RDOSq6etVB1ieAeLRQQM9But2Rcn9xofX6Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEuIFaYzzTpgW470kNEXPoZcESaYmDWvNE2yJ+7CP5CnAiEAtDfoXii4VJo9xUwJ9yO2e2MLVEVxlPvm1fVziGY+/Yc="}]}}},"readme":"A Javascript client library for [CKAN][] designed for both the browser and\nNodeJS.\n\nThe library provides full support for accessing both the CKAN Catalog and [CKAN\nDataStore API][ckan-api].\n\nIt also provides a [Recline compatible backend][recline-backend].\n\n[CKAN]: http://ckan.org/\n[ckan-api]: http://docs.ckan.org/en/latest/maintaining/datastore.html#the-datastore-api\n[recline-backend]: http://reclinejs.com/docs/backends.html\n[Recline]: http://reclinejs.com/\n\n## Installing\n\n### Browser\n\nJust add the `ckan.js` to your page.\n\n```\n<script src=\"ckan.js\"></script>\n```\n\nYou can also use our hosted one:\n\n```\n<script src=\"http://okfnlabs.org/ckan.js/ckan.js\"></script>\n```\n\n### Node\n\n```\nnpm install ckan\n```\n\nThen in your code:\n\n```\nvar CKAN = require('ckan')\n```\n\n## Usage\n\nUsage is generally similar across Node and Browser versions.\n\nCallback structure follows Node conventions, that is:\n\n`function(err, data)`\n\n### Catalog\n\nSet it up:\n\n```\nvar client = new CKAN.Client('http://my-ckan-site.com');\n\n// You can also provide an API key (for operations that require one)\nvar client = new CKAN.Client('http://my-ckan-site.com', 'my-api-key');\n```\n\nYou can now use any part of the [action API][]:\n\n[action API]: http://docs.ckan.org/en/latest/api/index.html\n\n```\nclient.action('action_name', data, callback)\n```\n\nFor example, to create a dataset using `dataset_create` action you would do:\n\n```\nclient.action('dataset_create', { name: 'my-dataset' }, function(err, result) {\n  console.log(err);\n  console.log(result);\n})\n```\n\nHere's a more complex example showing several commands to do a Dataset upsert\n(create if not exists, otherwise update):\n\n```\nvar datasetInfo = {\n  name: 'ckan.js-example',\n  title: 'CKAN.JS Example',\n  tags: ['amazing']\n};\nclient.action('dataset_show', { id: datasetInfo.name }, function(err, out) {\n  // dataset exists\n  if (!err) {\n    // TODO: you'd really want to extend the existing dataset object returned\n    // in out with the datasetInfo we have but we are being simple here\n    client.action('dataset_update', datasetInfo, cb);\n  } else {\n    client.action('dataset_create', datasetInfo, cb);\n  }\n});\n```\n\n### DataStore\n\nThe DataStore feature of CKAN allows you to store structured data in CKAN and\nto create a rich API for it. It is also accessible via the action API -\n[details in the docs here][datastore] - and and you can therefore access using\nthe CKAN client. Here are a few examples:\n\n[datastore]: http://docs.ckan.org/en/latest/maintaining/datastore.html\n\n#### Store Data\n\nStore data into the DataStore for an existing resource\n\n```\n// 2 rows or data (with columns/fields named 'A' and 'B'\nvar data = [\n  { A: 1, B: 2 },\n  { A: 10, B: 16}\n];\n// the id of a CKAN DataSet resource (the data that we store will be associated with that resource)\n// this resource will need to already exist\nresourceId = 'abc-efg';\nclient.action('datastore_create', {\n    resource_id: resourceId,\n    records: data\n  },\n  function(err) {\n    if (err) console.log(err);\n    console.log('All done');\n  })\n```\n\nStore data into a new DataStore resource:\n\n```\n// the id of a CKAN dataset that already exists\npackageId = 'the-best-dataset-ever';\nclient.action('datastore_create', {\n    resource: {package_id: packageId},\n    records: data\n  },\n  function(err) {\n    if (err) console.log(err);\n    console.log('All done');\n  })\n```\n\nHere's an example of loading data from a CSV file into the DataStore:\n\n```\n// npm's csv file\nvar csv = require('csv');\ncsv()\n  .from('path/to/csv-file.csv', {columns: true})\n  .to.array(function(data, count) {\n    client.action('datastore_create', {\n        resource_id: resourceId,\n        records: data\n      },\n      function(err) {\n        if (err) console.log(err);\n        console.log('All done');\n      })\n    })\n    ;\n```\n\n#### Search Data\n\nSearch data using the Data API - see [`datastore_search`][ds-search] for\ndetails of options:\n\n[ds-search]: http://docs.ckan.org/en/latest/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_search\n\n```\nclient.action('datastore_search', {\n    resource_id: '...',\n    q: '...'\n  },\n  function(err, out) {\n    if (err) console.log(err);\n    console.log(out);\n  })\n});\n```\n\nOr using SQL support:\n\n```\nclient.action('datastore_search_sql', {\n    sql: '...'\n  },\n  function(err, out) {\n    if (err) console.log(err);\n    console.log(out);\n  })\n});\n```\n\nThere are also a couple of nice wrapper methods:\n\n```\n// queryObj should be like the Recline Query structure\n// http://okfnlabs.org/recline/docs/models.html#query\nclient.datastoreQuery(queryObj, function(err, out) {\n  // out will follow recline structure, viz\n  {\n    total: ..\n    fields: ... (fields will have Recline / JSON Table Schema types)\n    hits: array of results ...\n  }\n});\n```\n\nAnd for SQL\n\n```\nclient.datastoreSqlQuery(sql, function(err, out) {\n  // out will follow recline structure, viz\n  {\n    total: ..\n    fields: ... (fields will have Recline / JSON Table Schema types)\n    hits: array of results ...\n  }\n});\n```\n\n### Recline JS Backend\n\nThis module also provides a Recline compatible backend available as:\n\n`recline.backend.Ckan`\n\nThe backend supports `fetch` and `query` but does not provide write support at\nthe present time.\n\n","maintainers":[{"name":"rufuspollock","email":"rufus.pollock@okfn.org"},{"name":"okfn","email":"paul.walsh@okfn.org"}],"time":{"modified":"2022-06-13T06:04:29.542Z","created":"2014-02-25T15:39:53.354Z","0.1.0":"2014-02-25T15:39:53.897Z","0.2.0":"2014-03-20T20:33:27.028Z","0.2.1":"2014-03-29T12:45:18.574Z","0.2.2":"2014-09-08T08:55:05.088Z","0.2.3":"2015-07-06T10:46:54.642Z"},"readmeFilename":"README.md","repository":{"type":"git","url":"https://github.com/okfn/ckan.js"},"author":{"name":"Open Knowledge Foundation","email":"labs@okfn.org"},"bugs":{"url":"https://github.com/okfn/ckan.js/issues"},"license":"MIT","homepage":"https://github.com/okfn/ckan.js"}