Example #1
0
    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
                     }})))
Example #2
0
    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
                     }})))
Example #3
0
    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
         })
     ))
Example #5
0
 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
         })
     ))
Example #6
0
 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']})))
Example #7
0
 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)))
Example #8
0
 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)
Example #9
0
    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)
Example #10
0
 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),
     ))
Example #11
0
    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)
Example #12
0
 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
         })
     ))
Example #13
0
 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}))
Example #14
0
 def update(self, uri, body):
     return self._clone(
         post(self.path(uri), auth=self.auth, data=json.dumps(body)))
Example #15
0
 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)
Example #16
0
 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'})
Example #17
0
 def initiate(self, uri, content_type):
     return post(self.path(uri),
                 auth=self.auth,
                 data=json.dumps({'content_type': content_type}))