Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Create dataset #8

Merged
merged 16 commits into from
Nov 23, 2015
Merged

Create dataset #8

merged 16 commits into from
Nov 23, 2015

Conversation

timwis
Copy link
Collaborator

@timwis timwis commented Nov 19, 2015

Not ready to merge yet. This is a work in progress. Just opening the pull request to encourage discussion around the implementation. (Update: Ready to merge)

I'm still new to python and would love feedback and suggestions. I figure there's also room to discuss things like columns, and the fact that creating a dataset is actually 3 HTTP requests (create, set public, publish). Here's what I have so far.

Edit: Another thing worth discussing is the fact that this uses the new API, so /resource/asdf-asdf.json is not the correct path (it's /api/views/asdf-asdf.json). I'd make the argument for abstracting the resource in the library and only looking for the 4x4 dataset ID. This way it would be very easy to switch from the old API to the new one, even for reading/GETs. I imagine in order to make this a non-breaking change, we'd have to allow the /resource/xxxx.json usage and just trim it off the string as I've done in this pull request.

@xmunoz
Copy link
Owner

xmunoz commented Nov 19, 2015

Thanks for your PR. I haven't looked over this super thoroughly yet, but my initial feedback is this: This is amazing! Can you add tests?

@timwis
Copy link
Collaborator Author

timwis commented Nov 19, 2015

Definitely. Just ran out of time this morning :P here's what I'm planning to add so far: https://github.com/timwis/sodapy/issues

@xmunoz
Copy link
Owner

xmunoz commented Nov 19, 2015

Rad! I'm glad someone else wants to take this up, because I'm rather busy these days. Can you also add an issue about updating the readme to describe this new endpoint's usage? I should have more time this weekend to review the code and provide more constructive feedback.

@timwis
Copy link
Collaborator Author

timwis commented Nov 19, 2015

Sounds great. I'll try to work on the other items in the meantime

@timwis
Copy link
Collaborator Author

timwis commented Nov 21, 2015

So I've added a test for create() but I've gone down a rabbit hole trying to add a request for set_public() to verify the query string parameters are constructed properly. It ended with this diagnosis. I notice your tests for get() don't verify the querystring construction either - perhaps you ran into this issue as well? Any thoughts on using http as the protocol instead of mock?

@@ -7,7 +7,7 @@
import json


PREFIX = "mock"
PREFIX = "http://"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requests library drops querystring parameters when the protocol is not http/https. (details)

@@ -62,7 +62,7 @@ def __init__(self, domain, app_token, username=None, password=None,
session_adapter["adapter"])
self.uri_prefix = session_adapter["prefix"]
else:
self.uri_prefix = "https"
self.uri_prefix = "https://"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session.mount() works when passed mock but not when https - for https to work, it needs to be passed https://. I'm not sure why this is, but the documentation suggests this approach fits fine. It required a few changes elsewhere, removing :// from a few string constructors. The alternative to doing that is to inject a :// into the session.mount() call, but I chose not to do that in case, in theory, you wanted to use a longer prefix like http://google.com (which would work with this approach)

@timwis
Copy link
Collaborator Author

timwis commented Nov 22, 2015

Okay @xmunoz, this pull request is ready to merge on my end! I've added a good number of comments and explanations alongside the changes. Let me know what you think.

}
resource = resource.rsplit("/", 1)[-1] # just get the dataset id

return self._perform_request("put", "/api/views/" + resource, params=params)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, you're right. Doing stuff like this is silly. I like the idea of only requiring the user to pass the 4x4 code + content-type extension and then building the URLs in the calls depending on which version of the API we are hitting. That's kind of asking a lot from you though, so I'll merge this first and do the cleanup in a separate commit.

@xmunoz
Copy link
Owner

xmunoz commented Nov 22, 2015

Thanks for all of your work on this! This is really impressive for someone who is just beginning with Python. My comments are minor: Can you delete this at the end of the README.md? 😉 I think that and the whitespace cleanup should just about do it for this PR.

Also, don't worry about updating the other README. It's in rst format, which is the pypi formatting language for the package. I just use pandoc to convert from markdown to rst, so README.md is actually the authoritative one. I'll need to do a couple of things before I build the next version for pypi anyway (v1/v2 url refactor, bump version number, etc).

It's late in Berlin. If you can take care of those two little things, I'll merge in the morning.

@timwis
Copy link
Collaborator Author

timwis commented Nov 22, 2015

Thanks for the encouragement! I've implemented those changes. Let me know when you get a chance to update it in pypi as I intend to use it in this project. Danke und guten nacht!

xmunoz added a commit that referenced this pull request Nov 23, 2015
@xmunoz xmunoz merged commit c15c011 into xmunoz:master Nov 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants