Exemplo n.º 1
0
    def get_new(cls, id=None, revision=None):
        client = PaperlessClient.get_instance()

        return client.get_new_resources(
            cls.construct_get_new_resources_url(),
            params=cls.construct_get_new_params(id, revision) if id else None,
        )
Exemplo n.º 2
0
 def create(self, table_name):
     """
     Persist new version of self to Paperless Parts and updates instance with any new data from the creation.
     """
     client = PaperlessClient.get_instance()
     data = self.to_json({'name': table_name})
     resp_json = client.create_resource(self.construct_post_url(),
                                        data=data)
     return resp_json
Exemplo n.º 3
0
 def test_without_bearer_token_throws_an_error(self):
     """
     Without a proper access token the client will raise a PaperlessAuthorizationException.
     """
     client = PaperlessClient.get_instance()
     client.access_token = None
     self.assertEqual(client.access_token, None)
     self.assertRaises(PaperlessAuthorizationException,
                       self.client.get_authenticated_headers)
Exemplo n.º 4
0
 def update(self, table_name):
     """
     Persists local changes of an existing Paperless Parts resource to Paperless.
     """
     client = PaperlessClient.get_instance()
     data = self.to_json({'config': self.config, 'data': self.data})
     resp_json = client.update_resource(self.construct_patch_url(),
                                        table_name,
                                        data=data)
     return resp_json
Exemplo n.º 5
0
 def test_authorization_token(self):
     """
     Test that we generate the properly formatted authenticated headers.
     """
     client = PaperlessClient.get_instance()
     client.access_token = self.access_token
     self.assertEqual(client.access_token, self.access_token)
     headers = self.client.get_authenticated_headers()
     self.assertEqual(headers['Authorization'],
                      'API-Token {}'.format(self.access_token))
Exemplo n.º 6
0
 def test_client_is_singleton(self):
     # singleton by get_instance
     new_client1 = PaperlessClient.get_instance()
     self.assertTrue(new_client1 is self.client)
     new_client1.access_token = self.access_token
     self.assertEqual(self.access_token, self.client.access_token)
     # singleton by new instance
     new_client2 = PaperlessClient()
     self.assertTrue(new_client2 is self.client)
     self.assertEqual(self.access_token, new_client2.access_token)
Exemplo n.º 7
0
 def download_csv(cls, table_name, config=False, file_path=None):
     """
     Download a CSV of the table data. If config == True, download the config data for the table instead.
     """
     params = {'config': True} if config else None
     if file_path is None:
         file_path = f'table_{table_name}_{"config" if config else "data"}.csv'
     client = PaperlessClient.get_instance()
     client.download_file(cls.construct_download_csv_url(),
                          table_name,
                          file_path,
                          params=params)
Exemplo n.º 8
0
 def get(cls, id, revision=None):
     """
     Retrieves the resource specified by the id and revision.
     :raise PaperlessNotFoundException: Raised when the requested id 404s aka is not found.
     :param id: int
     :param revision: Optional[int]
     :return: resource
     """
     client = PaperlessClient.get_instance()
     return cls.from_json(
         client.get_resource(cls.construct_get_url(),
                             id,
                             params=cls.construct_get_params(revision)))
Exemplo n.º 9
0
 def create(self, account_id):
     """
     Persist new version of self to Paperless Parts and updates instance with any new data from the creation.
     """
     client = PaperlessClient.get_instance()
     data = self.to_json()
     resp = client.create_resource(self.construct_post_url(account_id),
                                   data=data)
     resp_obj = self.from_json(resp)
     keys = filter(
         lambda x: not x.startswith('__') and not x.startswith('_'),
         dir(resp_obj))
     for key in keys:
         setattr(self, key, getattr(resp_obj, key))
Exemplo n.º 10
0
 def set_status(self, status):
     client = PaperlessClient.get_instance()
     params = None
     if self.revision_number is not None:
         params = {'revision': self.revision_number}
     resp_json = client.request(
         url=f'quotes/public/{self.number}/status_change',
         method=PaperlessClient.METHODS.PATCH,
         data={"status": status},
         params=params,
     )
     resp_obj = self.from_json(resp_json)
     keys = filter(
         lambda x: not x.startswith('__') and not x.startswith('_'),
         dir(resp_obj))
     for key in keys:
         setattr(self, key, getattr(resp_obj, key))
Exemplo n.º 11
0
    def list(cls, account_id=None, params=None):
        """
        Returns a list of (1) either the minimal representation of this resource as defined by _list_object_representation or (2) a list of this resource.

        :param params: dict of params for your list request
        :return: [resource]
        """
        client = PaperlessClient.get_instance()
        resource_list = cls.parse_list_response(
            client.get_resource_list(cls.construct_list_url(account_id),
                                     params=params))
        if cls._list_object_representation:
            return [
                cls._list_object_representation.from_json(resource)
                for resource in resource_list
            ]
        else:
            return [cls.from_json(resource) for resource in resource_list]
Exemplo n.º 12
0
 def construct_post_url(cls):
     client = PaperlessClient.get_instance()
     return 'suppliers/public/{}/custom_tables'.format(client.group_slug)
Exemplo n.º 13
0
    def delete(cls, table_name):
        client = PaperlessClient.get_instance()

        return client.delete_resource(cls.construct_delete_url(), table_name)
Exemplo n.º 14
0
    def get(cls, table_name):
        client = PaperlessClient.get_instance()

        return client.get_resource(cls.construct_get_url(), table_name)
Exemplo n.º 15
0
    def get_list(cls):
        client = PaperlessClient.get_instance()

        return client.get_new_resources(cls.construct_list_url(), params=None)
Exemplo n.º 16
0
 def construct_list_url(cls):
     client = PaperlessClient.get_instance()
     return 'orders/groups/{}'.format(client.group_slug)