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

Higher level abstraction #7

Open
alukach opened this issue May 14, 2017 · 2 comments
Open

Higher level abstraction #7

alukach opened this issue May 14, 2017 · 2 comments

Comments

@alukach
Copy link

alukach commented May 14, 2017

Currently, the CadastaSession class manages authentication and requests to the Cadasta Platform and the endpoints submodule allows users to not think about URLs. This is helpful but it still requires the users to have knowledge of RESTful interactions (e.g. use session.get() for reading and session.post() for creating).

I think it would be useful to create tooling to manage data at a higher level. This could look something like:

cadasta = CadastaInterface(CadastaSession())
project = cadasta.Organization.get(slug='my-org').Project.get_or_create(slug='my-proj')
party = project.Party.create(name='Jane Doe')

To model the relational nature of URLs between classes, I believe we would make a model class for each data type with a URL_TEMPLATE property (e.g. /organizations/{slug}). When instantiating related subclasses, we could replace the portions of URL_TEMPLATE that exist on the subclass with the populated URL from the parent class (e.g. /organizations/{slug}/projects/{slug} -> /organizations/my-org/projects/{slug} if we were looking at Organization.get(slug='my-org').Project). The API requests should be lazy to limit the amount of unnecessary requests (i.e. we don't actually want to query for Organization.get(slug='my-org') when we are running Organization.get(slug='my-org').Project.get(slug='my-proj').

@alukach
Copy link
Author

alukach commented May 14, 2017

Already existing higher-level functionality such as session.upload_file() or session.get_csrf() should probably me moved to the higher-level interface class.

@alukach
Copy link
Author

alukach commented May 15, 2017

Perhaps the above suggestion is overly complicated.

It's possible that something like the following would work just as well:

cadasta = CadastaInterface(CadastaSession())
org = cadasta.create(Party(org='foo', proj='my-project'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant