def create_upload(self, filename): """ Create a new source. Takes a `body` param, which must contain a `filename` of the file. Args: ``` filename (str): The name of the file you are uploading ``` Returns: ``` Source: Returns the new Source ``` Examples: ```python upload = revision.create_upload('foo.csv') ``` """ return self._subresource( Source, post(self.path(), auth=self.auth, data=json.dumps( {'source_type': { 'type': 'upload', 'filename': filename }})))
def create_upload(self, filename): """ Create a new source. Takes a `body` param, which must contain a `filename` of the file. Args: ``` filename (str): The name of the file you are uploading ``` Returns: ``` result (bool, Source | dict): Returns an API Result; the new Source or an error response ``` Examples: ```python (ok, upload) = revision.create_upload('foo.csv') ``` """ path = 'https://{domain}/api/publishing/v1/source'.format( domain=self.auth.domain) return self._subresource( Source, post(path, auth=self.auth, data=json.dumps( {'source_type': { 'type': 'upload', 'filename': filename }})))
def new(auth, metadata, external_datasets=[]): """ Initiate a new Revisions object Args: ``` auth (Socrata.Authorization): metadata (dict): Metadata to apply to the revision external_datasets ( [dict] ): List of external datasets to apply to the revision ``` Returns: ``` Revision The Revision resulting from this API call, or an error ``` """ path = 'https://{domain}/api/publishing/v1/revision'.format( domain=auth.domain, ) response = post(path, auth=auth, data=json.dumps({ 'action': { 'type': 'update' }, 'metadata': metadata, 'href': external_datasets })) return Revision(auth, response)
def create_source(self, uri, source_type): return self._subresource(Source, post( self.path(uri), auth = self.auth, data = json.dumps({ 'source_type' : source_type }) ))
def create_source(self, uri, source_type, parse_options = {}): return self._subresource(Source, post( self.path(uri), auth = self.auth, data = json.dumps({ 'source_type' : source_type, 'parse_options' : parse_options }) ))
def create_using_config(self, config): """ Create a revision for the given dataset. """ return self._subresource( Revision, post(self.path(), auth=self.auth, data=json.dumps({'config': config.attributes['name']})))
def _create(self, action_type, metadata, permission): body = { 'metadata': metadata, 'action': { 'type': action_type, 'permission': permission } } return self._subresource( Revision, post(self.path(), auth=self.auth, data=json.dumps(body)))
def build_config(self, uri, name, data_action): """ Create a new ImportConfig from this OutputSchema. See the API docs for what an ImportConfig is and why they're useful """ res = post(self.path(uri), auth=self.auth, data=json.dumps({ 'name': name, 'data_action': data_action })) return Config(self.auth, res, None)
def new(auth, metadata): path = 'https://{domain}/api/publishing/v1/revision'.format( domain=auth.domain, ) response = post(path, auth=auth, data=json.dumps({ 'action': { 'type': 'update' }, 'metadata': metadata })) return Revision(auth, response)
def transform(self, uri, body): """ Transform this InputSchema into an Output. Returns the new OutputSchema. Note that this call is async - the data may still be transforming even though the OutputSchema is returned. See OutputSchema.wait_for_finish to block until the """ return self._subresource(OutputSchema, post( self.path(uri), auth = self.auth, data = json.dumps(body), ))
def create_revision(self, uri, fourfour): """ Create a new Revision in the context of this ImportConfig. Sources that happen in this Revision will take on the values in this Config. """ # Because of circular dependencies ;_; from socrata.revisions import Revision res = post( self.path(uri).format(fourfour = fourfour), auth = self.auth ) return Revision(self.auth, res)
def create(self, name, data_action, parse_options = None, columns = None): """ Create a new ImportConfig. See http://docs.socratapublishing.apiary.io/ ImportConfig section for what is supported in `data_action`, `parse_options`, and `columns`. """ return self._subresource(Config, post( self.path(), auth = self.auth, data = json.dumps({ 'name': name, 'data_action': data_action, 'parse_options': parse_options, 'columns': columns }) ))
def bytes(self, uri, file_handle, content_type): return self._mutate( post(self.path(uri), auth=self.auth, data=file_handle, headers={'content-type': content_type}))
def update(self, uri, body): return self._clone( post(self.path(uri), auth=self.auth, data=json.dumps(body)))
def commit(self, uri, seq_num, byte_offset): return post(self.path(uri).format(seq_num=seq_num, byte_offset=byte_offset), auth=self.auth)
def chunk(self, uri, seq_num, byte_offset, bytes): return post(self.path(uri).format(seq_num=seq_num, byte_offset=byte_offset), auth=self.auth, data=bytes, headers={'content-type': 'application/octet-stream'})
def initiate(self, uri, content_type): return post(self.path(uri), auth=self.auth, data=json.dumps({'content_type': content_type}))