more work;
This commit is contained in:
@@ -3,3 +3,32 @@ from enum import Enum
|
|||||||
class DataFormat(Enum):
|
class DataFormat(Enum):
|
||||||
Raw = 0
|
Raw = 0
|
||||||
Formatted = 1
|
Formatted = 1
|
||||||
|
|
||||||
|
class ResultValueType(Enum):
|
||||||
|
String = 0
|
||||||
|
Integer = 1
|
||||||
|
Decimal = 2
|
||||||
|
Date = 3
|
||||||
|
TimeSpan = 4
|
||||||
|
Guid = 5
|
||||||
|
StringList = 6
|
||||||
|
IntegerList = 7
|
||||||
|
GuidList = 8
|
||||||
|
AttachmentList = 9
|
||||||
|
ScoringGroupList = 10
|
||||||
|
FileList = 11
|
||||||
|
|
||||||
|
class Increment(Enum):
|
||||||
|
Seconds = 0
|
||||||
|
Minutes = 1
|
||||||
|
Hours = 2
|
||||||
|
Days = 3
|
||||||
|
Weeks = 4
|
||||||
|
Months = 5
|
||||||
|
Years = 6
|
||||||
|
|
||||||
|
class Recurrence(Enum):
|
||||||
|
Empty = "None"
|
||||||
|
EndByDate = "EndByDate"
|
||||||
|
EndAfterOccurrences = 'EndAfterOccurrences'
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
from decimal import Decimal
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from Enums import DataFormat
|
from Enums import DataFormat, ResultValueType
|
||||||
|
|
||||||
# generic
|
# generic
|
||||||
|
|
||||||
@@ -128,12 +129,118 @@ class AddOrUpdateListItemResponse:
|
|||||||
def __init__(self, id: uuid):
|
def __init__(self, id: uuid):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
# field types
|
||||||
|
|
||||||
|
class StringFieldValue:
|
||||||
|
def __init__(self, value: str, fieldId: int):
|
||||||
|
self.type = ResultValueType.String.name
|
||||||
|
self.fieldId = fieldId
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
class IntegerFieldValue:
|
||||||
|
def __init__(self, value: int, fieldId: int):
|
||||||
|
self.type = ResultValueType.Integer.name
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class DecimalFieldValue:
|
||||||
|
def __init__(self, value: Decimal, fieldId: int):
|
||||||
|
self.type = ResultValueType.Decimal.name
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class DateFieldValue:
|
||||||
|
def __init__(self, value: datetime, fieldId: int):
|
||||||
|
self.type = ResultValueType.Date.name
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class GuidFieldValue:
|
||||||
|
def __init__(self, value: uuid, fieldId: int):
|
||||||
|
self.type = ResultValueType.Guid.name
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class TimeSpanData:
|
||||||
|
def __init__(self, quantity: Decimal, ):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TimeSpanValue:
|
||||||
|
def __init__(self, value: uuid, fieldId: int):
|
||||||
|
self.type = ResultValueType.Guid.name
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
# record specific
|
# record specific
|
||||||
|
|
||||||
|
class RecordFieldValue:
|
||||||
|
def __init__(self, type: str, fieldId: int, value: str):
|
||||||
|
self.type = type
|
||||||
|
self.fieldId = fieldId
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def AsString(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.String.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return StringFieldValue(str(self.value), self.fieldId).value
|
||||||
|
|
||||||
|
def AsInt(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.Integer.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return IntegerFieldValue(int(self.value), self.fieldId).value
|
||||||
|
|
||||||
|
def AsDecimal(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.Decimal.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return DecimalFieldValue(Decimal(self.value), self.fieldId).value
|
||||||
|
|
||||||
|
def AsDate(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.Date.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
for format in ["%Y-%m-%dT%H:%M:%S.%fZ","%Y-%m-%dT%H:%M:%SZ"]:
|
||||||
|
try:
|
||||||
|
date = datetime.datetime.strptime(self.value, format)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return DateFieldValue(date, self.fieldId).value
|
||||||
|
|
||||||
|
def AsGuid(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.Guid.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return GuidFieldValue(uuid.UUID(self.value), self.fieldId).value
|
||||||
|
|
||||||
|
def AsTimeSpan():
|
||||||
|
return
|
||||||
|
|
||||||
|
class Record:
|
||||||
|
def __init__(self, appId: int, recordId: int, fieldData: list[RecordFieldValue]):
|
||||||
|
self.appId = appId
|
||||||
|
self.recordId = recordId
|
||||||
|
self.fieldData = fieldData
|
||||||
|
|
||||||
class GetRecordsByAppRequest:
|
class GetRecordsByAppRequest:
|
||||||
def __init__(self, appId: int, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name, pagingRequest: PagingRequest=PagingRequest(1,50)):
|
def __init__(self, appId: int, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name, pagingRequest: PagingRequest=PagingRequest(1,50)):
|
||||||
self.appId = appId
|
self.appId = appId
|
||||||
self.fieldIds = fieldIds
|
self.fieldIds = fieldIds
|
||||||
self.dataFormat = dataFormat
|
self.dataFormat = dataFormat
|
||||||
self.pageSize = pagingRequest.pageSize
|
self.pageSize = pagingRequest.pageSize
|
||||||
self.pageNumber = pagingRequest.pageNumber
|
self.pageNumber = pagingRequest.pageNumber
|
||||||
|
|
||||||
|
class GetRecordsByAppResponse:
|
||||||
|
def __init__(self, pageNumber: int, pageSize: int, totalPages: int, totalRecords: int, records: list[Record]):
|
||||||
|
self.pageNumber = pageNumber
|
||||||
|
self.pageSize = pageSize
|
||||||
|
self.totalPages = totalPages
|
||||||
|
self.totalRecords = totalRecords
|
||||||
|
self.records = records
|
||||||
+45
-7
@@ -686,12 +686,9 @@ class OnspringClient:
|
|||||||
|
|
||||||
self.headers['Content-Type'] = 'application/json'
|
self.headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
requestData = json.dumps({
|
del listItemRequest.__dict__['listId']
|
||||||
'id': listItemRequest.id,
|
|
||||||
'name': listItemRequest.name,
|
requestData = json.dumps(listItemRequest.__dict__)
|
||||||
'numericValue': listItemRequest.numericValue,
|
|
||||||
'color': listItemRequest.color
|
|
||||||
})
|
|
||||||
|
|
||||||
response = requests.request(
|
response = requests.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
@@ -802,6 +799,7 @@ class OnspringClient:
|
|||||||
|
|
||||||
endpoint = GetRecordsByAppIdEndpoint(self.baseUrl, getRecordsByAppRequest.appId)
|
endpoint = GetRecordsByAppIdEndpoint(self.baseUrl, getRecordsByAppRequest.appId)
|
||||||
|
|
||||||
|
# use request object as key-value pairs for params
|
||||||
params = getRecordsByAppRequest.__dict__
|
params = getRecordsByAppRequest.__dict__
|
||||||
|
|
||||||
# remove appId from params
|
# remove appId from params
|
||||||
@@ -816,7 +814,47 @@ class OnspringClient:
|
|||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
params=params)
|
params=params)
|
||||||
|
|
||||||
return response
|
if response.status_code != 200:
|
||||||
|
return response
|
||||||
|
|
||||||
|
jsonResponse = response.json()
|
||||||
|
|
||||||
|
records = []
|
||||||
|
|
||||||
|
for item in jsonResponse['items']:
|
||||||
|
|
||||||
|
fields = []
|
||||||
|
|
||||||
|
record = Record(
|
||||||
|
item['appId'],
|
||||||
|
item['recordId'],
|
||||||
|
fields)
|
||||||
|
|
||||||
|
for field in item['fieldData']:
|
||||||
|
|
||||||
|
field = RecordFieldValue(
|
||||||
|
field['type'],
|
||||||
|
field['fieldId'],
|
||||||
|
field['value'])
|
||||||
|
|
||||||
|
fields.append(field)
|
||||||
|
|
||||||
|
record.fieldData = fields
|
||||||
|
|
||||||
|
records.append(record)
|
||||||
|
|
||||||
|
data = GetRecordsByAppResponse(
|
||||||
|
jsonResponse['pageNumber'],
|
||||||
|
jsonResponse['pageSize'],
|
||||||
|
jsonResponse['totalPages'],
|
||||||
|
jsonResponse['totalRecords'],
|
||||||
|
records)
|
||||||
|
|
||||||
|
return ApiResponse(
|
||||||
|
response.status_code,
|
||||||
|
data,
|
||||||
|
headers=response.headers,
|
||||||
|
responseText=response.text)
|
||||||
|
|
||||||
def GetRecordById(self, appId: int, recordId: int):
|
def GetRecordById(self, appId: int, recordId: int):
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,20 @@ url = cfg['prod']['url']
|
|||||||
|
|
||||||
onspringClient = OnspringClient(url, key)
|
onspringClient = OnspringClient(url, key)
|
||||||
|
|
||||||
request = GetRecordsByAppRequest(195, dataFormat=DataFormat.Formatted.name, fieldIds=[6985,6978])
|
request = GetRecordsByAppRequest(195)
|
||||||
|
|
||||||
response = onspringClient.GetRecordsByAppId(request)
|
response = onspringClient.GetRecordsByAppId(request)
|
||||||
|
|
||||||
print(response.status_code)
|
print(f'Status Code: {response.statusCode}')
|
||||||
print(response.url)
|
print(f'Page Size: {response.data.pageSize}')
|
||||||
print(response.json())
|
print(f'Page Number: {response.data.pageNumber}')
|
||||||
|
print(f'Total Pages: {response.data.totalPages}')
|
||||||
|
print(f'Total Records: {response.data.totalRecords}')
|
||||||
|
|
||||||
|
for record in response.data.records:
|
||||||
|
print(f' AppId: {record.appId}')
|
||||||
|
print(f' RecordId: {record.recordId}')
|
||||||
|
|
||||||
|
for value in record.fieldData:
|
||||||
|
print(f' Type: {value.type}, FieldId: {value.fieldId}, Value: {value.value}')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user