continuing implementing;
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def parseDate(date: str):
|
||||||
|
|
||||||
|
if date==None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
for format in ["%Y-%m-%dT%H:%M:%S.%fZ","%Y-%m-%dT%H:%M:%SZ"]:
|
||||||
|
try:
|
||||||
|
return datetime.strptime(date, format)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from decimal import Decimal
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from Enums import DataFormat, ResultValueType
|
from Enums import *
|
||||||
|
from decimal import Decimal
|
||||||
|
from datetime import datetime
|
||||||
|
from Helpers import parseDate
|
||||||
|
|
||||||
# generic
|
# generic
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ class File:
|
|||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
class FileInfo:
|
class FileInfo:
|
||||||
def __init__(self, type: str, contentType: str, name: str, createdDate: str, modifiedDate: str, owner: str, fileHref: str):
|
def __init__(self, type: str, contentType: str, name: str, createdDate: datetime, modifiedDate: datetime, owner: str, fileHref: str):
|
||||||
self.type = type
|
self.type = type
|
||||||
self.contentType = contentType
|
self.contentType = contentType
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -133,44 +135,59 @@ class AddOrUpdateListItemResponse:
|
|||||||
|
|
||||||
class StringFieldValue:
|
class StringFieldValue:
|
||||||
def __init__(self, value: str, fieldId: int):
|
def __init__(self, value: str, fieldId: int):
|
||||||
self.type = ResultValueType.String.name
|
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
class IntegerFieldValue:
|
class IntegerFieldValue:
|
||||||
def __init__(self, value: int, fieldId: int):
|
def __init__(self, value: int, fieldId: int):
|
||||||
self.type = ResultValueType.Integer.name
|
|
||||||
self.value = value
|
self.value = value
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
|
|
||||||
class DecimalFieldValue:
|
class DecimalFieldValue:
|
||||||
def __init__(self, value: Decimal, fieldId: int):
|
def __init__(self, value: Decimal, fieldId: int):
|
||||||
self.type = ResultValueType.Decimal.name
|
|
||||||
self.value = value
|
self.value = value
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
|
|
||||||
class DateFieldValue:
|
class DateFieldValue:
|
||||||
def __init__(self, value: datetime, fieldId: int):
|
def __init__(self, value: datetime, fieldId: int):
|
||||||
self.type = ResultValueType.Date.name
|
|
||||||
self.value = value
|
self.value = value
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
|
|
||||||
class GuidFieldValue:
|
class GuidFieldValue:
|
||||||
def __init__(self, value: uuid, fieldId: int):
|
def __init__(self, value: uuid.UUID, fieldId: int):
|
||||||
self.type = ResultValueType.Guid.name
|
|
||||||
self.value = value
|
self.value = value
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
|
|
||||||
class TimeSpanData:
|
class TimeSpanData:
|
||||||
def __init__(self, quantity: Decimal, ):
|
def __init__(self, quantity: Decimal, increment: str, recurrence: str=None, endByDate: datetime=None, endAfterOccurrences: int=None):
|
||||||
pass
|
self.quantity = quantity
|
||||||
|
self.increment = increment
|
||||||
|
self.recurrence = recurrence
|
||||||
|
self.endByDate = endByDate
|
||||||
|
self.endAfterOccurrences = endAfterOccurrences
|
||||||
|
|
||||||
|
|
||||||
class TimeSpanValue:
|
class TimeSpanValue:
|
||||||
def __init__(self, value: uuid, fieldId: int):
|
def __init__(self, value: TimeSpanData, fieldId: int):
|
||||||
self.type = ResultValueType.Guid.name
|
|
||||||
self.value = value
|
self.value = value
|
||||||
self.fieldId = fieldId
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class StringListValue:
|
||||||
|
def __init__(self, value: list[str], fieldId: int):
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class IntegerListValue:
|
||||||
|
def __init__(self, value: list[int], fieldId: int):
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
class GuidListValue:
|
||||||
|
def __init__(self, value: list[uuid.UUID], fieldId: int):
|
||||||
|
self.value = value
|
||||||
|
self.fieldId = fieldId
|
||||||
|
|
||||||
|
|
||||||
# record specific
|
# record specific
|
||||||
|
|
||||||
class RecordFieldValue:
|
class RecordFieldValue:
|
||||||
@@ -184,7 +201,7 @@ class RecordFieldValue:
|
|||||||
if self.type != ResultValueType.String.name:
|
if self.type != ResultValueType.String.name:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return StringFieldValue(str(self.value), self.fieldId).value
|
return StringFieldValue(self.value, self.fieldId).value
|
||||||
|
|
||||||
def AsInt(self):
|
def AsInt(self):
|
||||||
|
|
||||||
@@ -205,11 +222,7 @@ class RecordFieldValue:
|
|||||||
if self.type != ResultValueType.Date.name:
|
if self.type != ResultValueType.Date.name:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for format in ["%Y-%m-%dT%H:%M:%S.%fZ","%Y-%m-%dT%H:%M:%SZ"]:
|
date = parseDate(self.value)
|
||||||
try:
|
|
||||||
date = datetime.datetime.strptime(self.value, format)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return DateFieldValue(date, self.fieldId).value
|
return DateFieldValue(date, self.fieldId).value
|
||||||
|
|
||||||
@@ -220,14 +233,70 @@ class RecordFieldValue:
|
|||||||
|
|
||||||
return GuidFieldValue(uuid.UUID(self.value), self.fieldId).value
|
return GuidFieldValue(uuid.UUID(self.value), self.fieldId).value
|
||||||
|
|
||||||
def AsTimeSpan():
|
def AsTimeSpan(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.TimeSpan.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
value = dict(self.value)
|
||||||
|
|
||||||
|
quantity = value.get('quantity')
|
||||||
|
increment = value.get('increment')
|
||||||
|
recurrence = value.get('recurrence')
|
||||||
|
endByDate = value.get('endByDate')
|
||||||
|
endAfterOccurrences = value.get('endAfterOccurrences')
|
||||||
|
|
||||||
|
endByDate = parseDate(endByDate)
|
||||||
|
|
||||||
|
data = TimeSpanData(
|
||||||
|
quantity,
|
||||||
|
increment,
|
||||||
|
recurrence,
|
||||||
|
endByDate,
|
||||||
|
endAfterOccurrences)
|
||||||
|
|
||||||
|
return TimeSpanValue(data, self.fieldId).value
|
||||||
|
|
||||||
|
def AsStringList(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.StringList.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return StringListValue(self.value, self.fieldId).value
|
||||||
|
|
||||||
|
def AsIntegerList(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.IntegerList.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return IntegerListValue(self.value, self.fieldId).value
|
||||||
|
|
||||||
|
def AsGuidList(self):
|
||||||
|
|
||||||
|
if self.type != ResultValueType.GuidList.name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
guids = []
|
||||||
|
|
||||||
|
for guid in self.value:
|
||||||
|
guids.append(uuid.UUID(guid))
|
||||||
|
|
||||||
|
return GuidListValue(guids, self.fieldId).value
|
||||||
|
|
||||||
|
def AsAttachmentList(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
def AsScoringGroupList(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
def AsFileList(self):
|
||||||
return
|
return
|
||||||
|
|
||||||
class Record:
|
class Record:
|
||||||
def __init__(self, appId: int, recordId: int, fieldData: list[RecordFieldValue]):
|
def __init__(self, appId: int, recordId: int, fields: list[RecordFieldValue]):
|
||||||
self.appId = appId
|
self.appId = appId
|
||||||
self.recordId = recordId
|
self.recordId = recordId
|
||||||
self.fieldData = fieldData
|
self.fields = fields
|
||||||
|
|
||||||
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)):
|
||||||
|
|||||||
+6
-3
@@ -459,12 +459,15 @@ class OnspringClient:
|
|||||||
|
|
||||||
jsonResponse = response.json()
|
jsonResponse = response.json()
|
||||||
|
|
||||||
|
createdDate = parseDate(jsonResponse['createdDate'])
|
||||||
|
modifiedDate = parseDate(jsonResponse['modifiedDate'])
|
||||||
|
|
||||||
fileInfo = FileInfo(
|
fileInfo = FileInfo(
|
||||||
jsonResponse['type'],
|
jsonResponse['type'],
|
||||||
jsonResponse['contentType'],
|
jsonResponse['contentType'],
|
||||||
jsonResponse['name'],
|
jsonResponse['name'],
|
||||||
jsonResponse['createdDate'],
|
createdDate,
|
||||||
jsonResponse['modifiedDate'],
|
modifiedDate,
|
||||||
jsonResponse['owner'],
|
jsonResponse['owner'],
|
||||||
jsonResponse['fileHref'])
|
jsonResponse['fileHref'])
|
||||||
|
|
||||||
@@ -839,7 +842,7 @@ class OnspringClient:
|
|||||||
|
|
||||||
fields.append(field)
|
fields.append(field)
|
||||||
|
|
||||||
record.fieldData = fields
|
record.fields = fields
|
||||||
|
|
||||||
records.append(record)
|
records.append(record)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ url = cfg['prod']['url']
|
|||||||
|
|
||||||
onspringClient = OnspringClient(url, key)
|
onspringClient = OnspringClient(url, key)
|
||||||
|
|
||||||
request = GetRecordsByAppRequest(195)
|
request = GetRecordsByAppRequest(195, dataFormat=DataFormat.Raw.name)
|
||||||
|
|
||||||
response = onspringClient.GetRecordsByAppId(request)
|
response = onspringClient.GetRecordsByAppId(request)
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ for record in response.data.records:
|
|||||||
print(f' AppId: {record.appId}')
|
print(f' AppId: {record.appId}')
|
||||||
print(f' RecordId: {record.recordId}')
|
print(f' RecordId: {record.recordId}')
|
||||||
|
|
||||||
for value in record.fieldData:
|
for field in record.fields:
|
||||||
print(f' Type: {value.type}, FieldId: {value.fieldId}, Value: {value.value}')
|
if field.type == ResultValueType.Decimal.name:
|
||||||
|
print(f' Type: {field.type}, FieldId: {field.fieldId}, Value: {field.AsDecimal()}')
|
||||||
|
print(field.AsDecimal())
|
||||||
Reference in New Issue
Block a user