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

[epic] v0.2 Development of the Client SDK #4

Closed
8 of 10 tasks
rufuspollock opened this issue Sep 3, 2020 · 3 comments · Fixed by #13, #14 or #27
Closed
8 of 10 tasks

[epic] v0.2 Development of the Client SDK #4

rufuspollock opened this issue Sep 3, 2020 · 3 comments · Fixed by #13, #14 or #27

Comments

@rufuspollock
Copy link
Member

rufuspollock commented Sep 3, 2020

v0.1 was about basic "push" functionality which is done.

v0.2 is about refactoring this to be more elegant and support for reading/writing metadata

API design should follow https://github.com/datopian/ckan-client-guide (but tweaked for js/nodejs idioms)

https://github.com/okfn/ckan.js could probably be reused for the plumbing layer.

Acceptance

  • client.push(datasetMetadata) function works which takes dataset JS object (in f11s format) and puts it to CKAN datastore
  • client.pushBlob(resource, onProgressFn): uploads a resource's data to the Blob Storage. resource is a data.js File object of a specific type e.g. FileInterface
  • client.retrieve(datasetIdOrName)

Porcelain

  • client.action(...)

Bonus

  • client.pushResource(resource, dataset-name) takes resource in data.js and saves data to storage and metadata
  • client.pushResourceMedata

Tasks

API design

This is indicative - see individual issues for precise specifications

Uses data.js and its Frictionless (f11s) data interface as the way to access files and datasets. Metadata follows Frictionless formats.

Plumbing

This is relatively raw low level APIs.

  • Storage: getting authz, interaction with giftless etc
  • MetaStore: CKAN action API v3
client = Client(...)
client.action_api(...)

Porcelain

// create a dataset (or overwrite existing one) - just puts metadata (file uploading is separate)
client.push(datasetMetadata)

// longform of previous item
resource = open(path) # f11s.Resource object
// this uploads just the data to storage ...
// resource has .stream, 
client.pushBlob(resource)
// f11s.Dataset({metadata})
// so can do dataset.descriptor
dataset = client.retrieve(dataset_name)
dataset.resources.push(resource.descriptor)
client.push(dataset)

// bonus
// convenience function
// dataset must exist
client.pushResource(f11s_resource, dataset=dataset_name)
// convenience
client.pushResourceMetadata(...) # only save resource metadata ... 

// GET functions
client.retrieve(dataset_id_or_name)

// BONUS
client.retrieveResource(resource_id OR dataset_id + resource_name)

Example usage

import data.js as f11s
import ckanclient

// resource is a data.js file object from a browser file selection
resource = filereader object wrapped ...


dataset = {
  descriptor:
    name: ... 
    resources:
}

What is an f11s_dataset?

dataset.descriptor => Frictionless formatted object for a dataset ...

put

Client.action_api = async function(action, payload) {

}

Client.put = async function(f11s_dataset) {
  ckan_metadata = f11s2ckan.dataset(f11s_dataset.descriptor)
  // https://docs.ckan.org/en/2.9/api/index.html#ckan.logic.action.create.package_create
  // see existing code https://github.com/okfn/ckan.js#catalog
  await res = client.action_api('package_create', ckan_metadata)
  return res
}
@rufuspollock rufuspollock added this to Prioritized Backlog in DataPub Overview Sep 4, 2020
mariorodeghiero added a commit that referenced this issue Sep 7, 2020
…tion to receive an URL - #4

- update readme
- refactor code to use client
- refactor code to use open function
- fix ckanAuthz url
@mariorodeghiero
Copy link
Collaborator

mariorodeghiero commented Sep 7, 2020

@rufuspollock rufuspollock moved this from Prioritized Backlog to In Progress in DataPub Overview Sep 10, 2020
mariorodeghiero added a commit that referenced this issue Sep 11, 2020
- create action function to be able create/update dataset and resource
- add test to create a dataset
- add test to create/update a resource
- add test to the action function
anuveyatsu added a commit that referenced this issue Sep 11, 2020
…metadata

[add][lg] create methods and test - #4
@rufuspollock rufuspollock linked a pull request Sep 14, 2020 that will close this issue
@mariorodeghiero
Copy link
Collaborator

  • Created tests and the action function to be able to create_resource and update_resource.

@mariorodeghiero
Copy link
Collaborator

In Progress:

  • Refactoring Datapub to use the create_resource and update_resource
    Estimate: 0.5day

@kmanaseryan kmanaseryan linked a pull request Sep 14, 2020 that will close this issue
2 tasks
DMS Product Roadmap including CKAN and DataHub automation moved this from In Progress to Done Sep 14, 2020
DataPub Overview automation moved this from In Progress to Done Sep 14, 2020
@kmanaseryan kmanaseryan reopened this Sep 14, 2020
@kmanaseryan kmanaseryan moved this from Done to In Progress in DataPub Overview Sep 14, 2020
@kmanaseryan kmanaseryan linked a pull request Sep 14, 2020 that will close this issue
DataPub Overview automation moved this from In Progress to Done Sep 14, 2020
rufuspollock added a commit that referenced this issue Sep 14, 2020
#4 Add support for generic action request to CKAN
@kmanaseryan kmanaseryan moved this from Done to In Progress in DataPub Overview Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment