コード例 #1
0
def run():
    ctx = context.ApiContext(
        context.ApiEnvironmentType.SANDBOX,
        '### YOUR_API_KEY ###',  # Put your API key here
        'test device python')

    ctx.save()
    ctx_restored = context.ApiContext.restore()
    print(
        'Is original context equal the one saved and restored?:',
        converter.class_to_json(ctx) == converter.class_to_json(ctx_restored))
    def create_with_list_response(
        cls,
        monetary_account_id: int = None,
        all_notification_filter: List[NotificationFilterUrl] = None,
        custom_headers: Dict[str, str] = None
    ) -> BunqResponse[List[NotificationFilterUrl]]:
        if all_notification_filter is None:
            all_notification_filter = []

        if custom_headers is None:
            custom_headers = {}

        request_map = {cls.FIELD_NOTIFICATION_FILTERS: all_notification_filter}
        request_map_string = converter.class_to_json(request_map)
        request_map_string = cls._remove_field_for_request(request_map_string)

        api_client = ApiClient(cls._get_api_context())
        request_bytes = request_map_string.encode()
        endpoint_url = cls._ENDPOINT_URL_CREATE.format(
            cls._determine_user_id(),
            cls._determine_monetary_account_id(monetary_account_id))
        response_raw = api_client.post(endpoint_url, request_bytes,
                                       custom_headers)

        return NotificationFilterUrl._from_json_list(response_raw,
                                                     cls._OBJECT_TYPE_GET)
コード例 #3
0
ファイル: api_context.py プロジェクト: siccovansas/sdk_python
    def to_json(self) -> str:
        """
        Serializes an ApiContext to JSON string.

        """

        return converter.class_to_json(self)
コード例 #4
0
    def create_with_api_context(
            cls,
            client_payment_service_provider_certificate: str,
            client_payment_service_provider_certificate_chain: str,
            client_public_key_signature: str,
            api_context: ApiContext,
            all_custom_header=None) -> UserCredentialPasswordIp:
        request_map = {
            cls.FIELD_CLIENT_PAYMENT_SERVICE_PROVIDER_CERTIFICATE:
            client_payment_service_provider_certificate,
            cls.FIELD_CLIENT_PAYMENT_SERVICE_PROVIDER_CERTIFICATE_CHAIN:
            client_payment_service_provider_certificate_chain,
            cls.FIELD_CLIENT_PUBLIC_KEY_SIGNATURE: client_public_key_signature
        }

        if all_custom_header is None:
            all_custom_header = {}

        api_client = ApiClient(api_context)
        request_bytes = converter.class_to_json(request_map).encode()
        endpoint_url = cls._ENDPOINT_URL_CREATE
        response_raw = api_client.post(endpoint_url, request_bytes,
                                       all_custom_header)

        response_body = converter.json_to_class(
            dict, response_raw.body_bytes.decode())
        response_body_dict = converter.deserialize(
            cls, response_body[cls._FIELD_RESPONSE])[0]

        return UserCredentialPasswordIp.from_json(
            json.dumps(response_body_dict[cls._OBJECT_TYPE_GET]))
コード例 #5
0
ファイル: core.py プロジェクト: willemli/sdk_python
    def generate_request_body_bytes(cls, secret):
        """
        :type secret: str

        :rtype: bytes
        """

        return converter.class_to_json({cls.FIELD_SECRET: secret}).encode()
コード例 #6
0
ファイル: context.py プロジェクト: edgarlanting/sdk_python
    def to_json(self):
        """
        Serializes an ApiContext to JSON string.

        :rtype: str
        """

        return converter.class_to_json(self)
コード例 #7
0
ファイル: core.py プロジェクト: willemli/sdk_python
    def generate_request_body_bytes(cls, public_key_string):
        """
        :type public_key_string: str

        :rtype: bytes
        """

        return converter.class_to_json({
            cls.FIELD_CLIENT_PUBLIC_KEY:
            public_key_string,
        }).encode()
コード例 #8
0
    def test_api_context_save_json(self):
        """
        Converts an ApiContext to JSON data, saves the ApiContext using the
        ApiContext.save() function with the to_JSON flag set to True, and
        compares whether the JSON data equals the returned JSON data from the
        ApiContext.save() function.
        """

        context_json = converter.class_to_json(self._API_CONTEXT)
        context_saved = self._API_CONTEXT.to_json()

        self.assertEqual(context_saved, context_json)
コード例 #9
0
    def create(cls,
               description: str,
               secret: str,
               permitted_ips: List[str] = None,
               custom_headers: Dict[str, str] = None,
               api_context: ApiContext = None) -> BunqResponseInt:
        """
        Create a new DeviceServer providing the installation token in the header
        and signing the request with the private part of the key you used to
        create the installation. The API Key that you are using will be bound to
        the IP address of the DeviceServer which you have
        created.<br/><br/>Using a Wildcard API Key gives you the freedom to make
        API calls even if the IP address has changed after the POST
        device-server.<br/><br/>Find out more at this link <a
        href="https://bunq.com/en/apikey-dynamic-ip"
        target="_blank">https://bunq.com/en/apikey-dynamic-ip</a>.

        :param description: The description of the DeviceServer. This is only
        for your own reference when reading the DeviceServer again.
        :type description: str
        :param secret: The API key. You can request an API key in the bunq app.
        :type secret: str
        :param permitted_ips: An array of IPs (v4 or v6) this DeviceServer will
        be able to do calls from. These will be linked to the API key.
        :type permitted_ips: list[str]
        :type custom_headers: dict[str, str]|None
        :type api_context: ApiContext

        :rtype: BunqResponseInt
        """

        if api_context is None:
            raise BunqException(cls._ERROR_API_CONTEXT_IS_NULL)

        if custom_headers is None:
            custom_headers = {}

        request_map = {
            cls.FIELD_DESCRIPTION: description,
            cls.FIELD_SECRET: secret,
            cls.FIELD_PERMITTED_IPS: permitted_ips
        }

        api_client = ApiClient(api_context)
        request_bytes = converter.class_to_json(request_map).encode()
        endpoint_url = cls._ENDPOINT_URL_CREATE
        response_raw = api_client.post(endpoint_url, request_bytes,
                                       custom_headers)

        return BunqResponseInt.cast_from_bunq_response(
            cls._process_for_id(response_raw)
        )
コード例 #10
0
    def test_api_context_save(self):
        """
        Converts an ApiContext to JSON data, saves the same ApiContext to a
        temporary file, and compares whether the JSON data is equal to the
        data in the file.

        Removes the temporary file before assertion.
        """

        context_json = converter.class_to_json(self._API_CONTEXT)

        self._API_CONTEXT.save(self._TMP_FILE_PATH_FULL)

        with open(self._TMP_FILE_PATH_FULL, self._FILE_MODE_READ) as file_:
            context_retrieved = file_.read()

        os.remove(self._TMP_FILE_PATH_FULL)

        self.assertEqual(context_retrieved, context_json)
コード例 #11
0
    def test_create_oauth_client(self) -> None:
        if os.path.isfile(self._FILE_TEST_OAUTH_PATH_FULL):
            return

        try:
            client_id = OauthClient.create().value
            oauth_client = OauthClient.get(client_id).value

            self.assertIsNotNone(oauth_client)

            serialized_client = converter.class_to_json(oauth_client)

            file = open(self._FILE_TEST_OAUTH_PATH_FULL,
                        ApiContext._FILE_MODE_WRITE)
            file.write(serialized_client)
            file.close()

            self.assertTrue(os.path.isfile(self._FILE_TEST_OAUTH_PATH_FULL))

        except AssertionError:
            raise AssertionError
コード例 #12
0
ファイル: core.py プロジェクト: willemli/sdk_python
    def to_json(self):
        """
        :rtype: str
        """

        return converter.class_to_json(self)
コード例 #13
0
ファイル: session_server.py プロジェクト: snakx/bunq-api
 def generate_request_body_bytes(cls, secret: str) -> bytes:
     return converter.class_to_json({cls.FIELD_SECRET: secret}).encode()
コード例 #14
0
 def generate_request_body_bytes(cls, public_key_string: str) -> bytes:
     return converter.class_to_json({
         cls.FIELD_CLIENT_PUBLIC_KEY:
         public_key_string,
     }).encode()
コード例 #15
0
 def to_json(self) -> str:
     return converter.class_to_json(self)