Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## v0.0.2.11

### New Features

- Core: add function decode_api_id and encode_api_id to convert between nodeID and normal ID

## v0.0.2.10

### New Features
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ This module is used to interact with the Xurrent API. It provides a set of class
uri = "/requests?subject=Example Subject"
connection_object.api_call(uri, 'GET')

# Convert node ID
helper.decode_api_id('ZmFiaWFuc3RlaW5lci4yNDEyMTAxMDE0MTJANG1lLWRlbW8uY29tL1JlcS83MDU3NTU') # fabiansteiner.241210101412@4me-demo.com/Req/705755
# this can be used to derive the ID from the nodeID

```

#### People
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "xurrent"
version = "0.0.2.10"
version = "0.0.2.11"
authors = [
{ name="Fabian Steiner", email="fabian@stei-ner.net" },
]
Expand All @@ -18,7 +18,7 @@ Homepage = "https://github.com/fasteiner/xurrent-python"
Issues = "https://github.com/fasteiner/xurrent-python/issues"
[tool.poetry]
name = "xurrent"
version = "0.0.2.10"
version = "0.0.2.11"
description = "A python module to interact with the Xurrent API."
authors = ["Ing. Fabian Franz Steiner BSc. <fabian.steiner@tttech.com>"]
readme = "README.md"
Expand Down
29 changes: 29 additions & 0 deletions src/xurrent/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import json
import re
import base64

class LogLevel(Enum):
DEBUG = logging.DEBUG
Expand Down Expand Up @@ -245,3 +246,31 @@ def create_filter_string(self, filter: dict):
for key, value in filter.items():
filter_string += f'{key}={value}&'
return filter_string[:-1]

def decode_api_id(self, id: str):
"""
API resource IDs are base64-encoded strings with the padding bytes stripped off.
Ensure approproate padding and decode.
:param id: Encoded Xurrent resource ID
:return: String containing the decoded ID
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.decode_api_id('SGVsbG8sIHdvcmxkIQ')
'Hello, world!'
"""
#Get the length remainder of 4, fill the remainder to be a power of 4, but only if it is not already 4
padding_count = (4 - (len(id) % 4)) % 4
padding = "=" * padding_count
value = id + padding
return base64.decodebytes(value.encode()).decode()

def encode_api_id(self, id: str):
"""
API resource IDs are base64-encoded strings with the padding bytes stripped off.
Encode and strip padding.
:param id: Xurrent resource ID to encode
:return: String containing the encoded ID
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.encode_api_id('Hello, world!')
'SGVsbG8sIHdvcmxkIQ'
"""
return base64.encodebytes(id.encode()).decode().strip().rstrip("=")
Loading