adding more doc strings

This commit is contained in:
StevanFreeborn
2022-04-29 10:53:17 -05:00
parent f0edea8ac4
commit e9dd6470ea
+240 -44
View File
@@ -1,9 +1,6 @@
from audioop import mul
import datetime import datetime
import uuid import uuid
from requests import Response
from Enums import * from Enums import *
from decimal import Decimal from decimal import Decimal
from datetime import datetime from datetime import datetime
@@ -328,6 +325,17 @@ class SaveFileResponse:
# list specific # list specific
class ListItemRequest: class ListItemRequest:
"""
An object to represent the necessary information for adding or updating a list value. If no id is provided the list value will be added. If an id is provided then an attempt will be made to find that list value and update it.
Attributes:
listId (`int`): The id of the parent list that the list value belongs to.
name (`str`): The name of the list value.
id (`uuid`): The id of the list value.
numericValue (`int`): The numeric value assigned to the list value.
color (`str`): The color value assigned to the list value.
"""
def __init__(self, listId: int, name: str, id: uuid=None, numericValue: int=None, color: str=None): def __init__(self, listId: int, name: str, id: uuid=None, numericValue: int=None, color: str=None):
self.listId = listId self.listId = listId
self.name = name self.name = name
@@ -336,18 +344,43 @@ class ListItemRequest:
self.color = color self.color = color
class AddOrUpdateListItemResponse: class AddOrUpdateListItemResponse:
"""
An object to represent a response to a request made by an `OnspringClient` to add or update a list value in Onspring.
Attributes:
id (`int`): The id of the list value updated or added in Onspring.
"""
def __init__(self, id: uuid): def __init__(self, id: uuid):
self.id = id self.id = id
# record specific # record specific
class RecordFieldValue: class RecordFieldValue:
"""
An object to represent the value in a field in an Onspring record.
Attributes:
fieldId (`int`): The id of the field that the value is in.
value (`str`): The value of the field.
type (`str`): The type of value.
"""
def __init__(self, fieldId: int, value: str, type: str=None): def __init__(self, fieldId: int, value: str, type: str=None):
self.type = type
self.fieldId = fieldId self.fieldId = fieldId
self.value = value self.value = value
self.type = type
def AsString(self): def AsString(self):
"""
If the `Models.RecordFieldValue` type is String will return the value property as a `str` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `str`.
"""
if self.type != ResultValueType.String.name: if self.type != ResultValueType.String.name:
return None return None
@@ -355,6 +388,15 @@ class RecordFieldValue:
return StringFieldValue(self.fieldId, self.value).value return StringFieldValue(self.fieldId, self.value).value
def AsInteger(self): def AsInteger(self):
"""
If the `Models.RecordFieldValue` type is Integer will return the value property as an `int` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as an `int`.
"""
if self.type != ResultValueType.Integer.name: if self.type != ResultValueType.Integer.name:
return None return None
@@ -362,6 +404,15 @@ class RecordFieldValue:
return IntegerFieldValue(self.fieldId, int(self.value)).value return IntegerFieldValue(self.fieldId, int(self.value)).value
def AsDecimal(self): def AsDecimal(self):
"""
If the `Models.RecordFieldValue` type is Decimal will return the value property as a `Decimal` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `Decimal`.
"""
if self.type != ResultValueType.Decimal.name: if self.type != ResultValueType.Decimal.name:
return None return None
@@ -369,6 +420,15 @@ class RecordFieldValue:
return DecimalFieldValue(self.fieldId, Decimal(self.value)).value return DecimalFieldValue(self.fieldId, Decimal(self.value)).value
def AsDate(self): def AsDate(self):
"""
If the `Models.RecordFieldValue` type is Date will return the value property as a `datetime` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `datetime`.
"""
if self.type != ResultValueType.Date.name: if self.type != ResultValueType.Date.name:
return None return None
@@ -378,6 +438,15 @@ class RecordFieldValue:
return DateFieldValue(self.fieldId, date).value return DateFieldValue(self.fieldId, date).value
def AsGuid(self): def AsGuid(self):
"""
If the `Models.RecordFieldValue` type is Guid will return the value property as an `UUID` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as an `UUID`.
"""
if self.type != ResultValueType.Guid.name: if self.type != ResultValueType.Guid.name:
return None return None
@@ -385,6 +454,15 @@ class RecordFieldValue:
return GuidFieldValue(self.fieldId, uuid.UUID(self.value)).value return GuidFieldValue(self.fieldId, uuid.UUID(self.value)).value
def AsTimeSpan(self): def AsTimeSpan(self):
"""
If the `Models.RecordFieldValue` type is TimeSpan will return the value property as a `Model.TimeSpanData` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `Model.TimeSpanData`.
"""
if self.type != ResultValueType.TimeSpan.name: if self.type != ResultValueType.TimeSpan.name:
return None return None
@@ -409,6 +487,15 @@ class RecordFieldValue:
return TimeSpanValue(self.fieldId, data).value return TimeSpanValue(self.fieldId, data).value
def AsStringList(self): def AsStringList(self):
"""
If the `Models.RecordFieldValue` type is StringList will return the value property as a `list[str]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[str]`.
"""
if self.type != ResultValueType.StringList.name: if self.type != ResultValueType.StringList.name:
return None return None
@@ -418,6 +505,15 @@ class RecordFieldValue:
return StringListValue(self.fieldId, strings).value return StringListValue(self.fieldId, strings).value
def AsIntegerList(self): def AsIntegerList(self):
"""
If the `Models.RecordFieldValue` type is IntegerList will return the value property as a `list[int]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[int]`.
"""
if self.type != ResultValueType.IntegerList.name: if self.type != ResultValueType.IntegerList.name:
return None return None
@@ -427,6 +523,15 @@ class RecordFieldValue:
return IntegerListValue(self.fieldId, integers).value return IntegerListValue(self.fieldId, integers).value
def AsGuidList(self): def AsGuidList(self):
"""
If the `Models.RecordFieldValue` type is GuidList will return the value property as a `list[UUID]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[UUID]`.
"""
if self.type != ResultValueType.GuidList.name: if self.type != ResultValueType.GuidList.name:
return None return None
@@ -439,6 +544,15 @@ class RecordFieldValue:
return GuidListValue(self.fieldId, guids).value return GuidListValue(self.fieldId, guids).value
def AsAttachmentList(self): def AsAttachmentList(self):
"""
If the `Models.RecordFieldValue` type is AttachmentList will return the value property as a `list[Models.Attachment]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[Models.Attachment]`.
"""
if self.type != ResultValueType.AttachmentList.name: if self.type != ResultValueType.AttachmentList.name:
return None return None
@@ -460,6 +574,15 @@ class RecordFieldValue:
return AttachmentListValue(self.fieldId, attachments).value return AttachmentListValue(self.fieldId, attachments).value
def AsScoringGroupList(self): def AsScoringGroupList(self):
"""
If the `Models.RecordFieldValue` type is ScoringGroupList will return the value property as a `list[Models.ScoringGroup]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[Models.ScoringGroup]`.
"""
if self.type != ResultValueType.ScoringGroupList.name: if self.type != ResultValueType.ScoringGroupList.name:
return return
@@ -481,6 +604,15 @@ class RecordFieldValue:
return ScoringGroupListValue(self.fieldId, scoringGroups).value return ScoringGroupListValue(self.fieldId, scoringGroups).value
def AsFileList(self): def AsFileList(self):
"""
If the `Models.RecordFieldValue` type is FileList will return the value property as a `list[int]` otherwise will return `None`.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as a `list[int]`.
"""
if self.type != ResultValueType.FileList.name: if self.type != ResultValueType.FileList.name:
return None return None
@@ -490,100 +622,151 @@ class RecordFieldValue:
return FileListValue(self.fieldId, files).value return FileListValue(self.fieldId, files).value
def getValue(self): def getValue(self):
"""
Will determine the appropriate way to return the fields value based on it's type.
Args:
None
Returns:
The value of the `Models.RecordFieldValue` as the appropriate object.
"""
if self.type == ResultValueType.String.name: if self.type == ResultValueType.String.name:
return self.AsString() return self.AsString()
elif self.type == ResultValueType.Integer.name: elif self.type == ResultValueType.Integer.name:
return self.AsInteger() return self.AsInteger()
elif self.type == ResultValueType.Decimal.name: elif self.type == ResultValueType.Decimal.name:
return self.AsDecimal() return self.AsDecimal()
elif self.type == ResultValueType.Date.name: elif self.type == ResultValueType.Date.name:
return self.AsDate() return self.AsDate()
elif self.type == ResultValueType.TimeSpan.name: elif self.type == ResultValueType.TimeSpan.name:
return self.AsTimeSpan() return self.AsTimeSpan()
elif self.type == ResultValueType.Guid.name: elif self.type == ResultValueType.Guid.name:
return self.AsGuid() return self.AsGuid()
elif self.type == ResultValueType.StringList.name: elif self.type == ResultValueType.StringList.name:
return self.AsStringList() return self.AsStringList()
elif self.type == ResultValueType.IntegerList.name: elif self.type == ResultValueType.IntegerList.name:
return self.AsIntegerList() return self.AsIntegerList()
elif self.type == ResultValueType.GuidList.name: elif self.type == ResultValueType.GuidList.name:
return self.AsGuidList() return self.AsGuidList()
elif self.type == ResultValueType.AttachmentList.name: elif self.type == ResultValueType.AttachmentList.name:
return self.AsAttachmentList() return self.AsAttachmentList()
elif self.type == ResultValueType.ScoringGroupList.name: elif self.type == ResultValueType.ScoringGroupList.name:
return self.AsScoringGroupList() return self.AsScoringGroupList()
elif self.type == ResultValueType.FileList.name: elif self.type == ResultValueType.FileList.name:
return self.AsFileList() return self.AsFileList()
else: else:
return None return None
def GetResultValueString(self): def GetResultValueString(self):
match self.type: """
case ResultValueType.String.name: Will return the value property regardless of the field value's type as a string.
return self.AsString()
case ResultValueType.Integer.name: Args:
return self.AsInteger() None
case ResultValueType.Decimal.name: Returns:
return self.AsDecimal() The value of the `Models.RecordFieldValue` as a string.
"""
if self.type == ResultValueType.String.name:
return self.AsString()
case ResultValueType.Date.name: elif self.type == ResultValueType.Integer.name:
return self.AsDate() return self.AsInteger()
case ResultValueType.TimeSpan.name: elif self.type == ResultValueType.Decimal.name:
data = self.AsTimeSpan() return self.AsDecimal()
return f'Quantity: {data.quantity}, Increment: {data.increment}, Recurrence: {data.recurrence}, EndByDate: {data.endByDate}, EndAfterOccurrences: {data.endAfterOccurrences}'
case ResultValueType.Guid.name: elif self.type == ResultValueType.Date.name:
return self.AsGuid() return self.AsDate()
case ResultValueType.StringList.name: elif self.type == ResultValueType.TimeSpan.name:
data = self.AsStringList() data = self.AsTimeSpan()
return f'{",".join(data)}' return f'Quantity: {data.quantity}, Increment: {data.increment}, Recurrence: {data.recurrence}, EndByDate: {data.endByDate}, EndAfterOccurrences: {data.endAfterOccurrences}'
case ResultValueType.IntegerList.name: elif self.type == ResultValueType.Guid.name:
data = self.AsIntegerList() return self.AsGuid()
return f'{",".join([str(i) for i in data])}'
case ResultValueType.GuidList.name: elif self.type == ResultValueType.StringList.name:
data = self.AsGuidList() data = self.AsStringList()
return f'{",".join([str(guid) for guid in data])}' return f'{",".join(data)}'
case ResultValueType.AttachmentList.name: elif self.type == ResultValueType.IntegerList.name:
data = self.AsAttachmentList() data = self.AsIntegerList()
return f'{",".join([str(i) for i in data])}'
strings = [] elif self.type == ResultValueType.GuidList.name:
data = self.AsGuidList()
return f'{",".join([str(guid) for guid in data])}'
for attachment in data: elif self.type == ResultValueType.AttachmentList.name:
string = f'FileId: {attachment.fileId}, FileName: {attachment.fileName}, Notes: {attachment.notes}, StorageLocation: {attachment.storageLocation}' data = self.AsAttachmentList()
strings.append(string)
return f'{"; ".join(strings)}' strings = []
case ResultValueType.ScoringGroupList.name: for attachment in data:
data = self.AsScoringGroupList() string = f'FileId: {attachment.fileId}, FileName: {attachment.fileName}, Notes: {attachment.notes}, StorageLocation: {attachment.storageLocation}'
strings.append(string)
strings = [] return f'{"; ".join(strings)}'
for scoringGroup in data: elif self.type == ResultValueType.ScoringGroupList.name:
string = f'ListValueId: {scoringGroup.listValueId}, Name: {scoringGroup.name}, Score: {scoringGroup.score}, Max Score: {scoringGroup.maximumScore}' data = self.AsScoringGroupList()
strings.append(string)
return f'{"; ".join(strings)}' strings = []
case ResultValueType.FileList.name: for scoringGroup in data:
data = self.AsFileList() string = f'ListValueId: {scoringGroup.listValueId}, Name: {scoringGroup.name}, Score: {scoringGroup.score}, Max Score: {scoringGroup.maximumScore}'
return f'{",".join([str(i) for i in data])}' strings.append(string)
return f'{"; ".join(strings)}'
elif self.type == ResultValueType.FileList.name:
data = self.AsFileList()
return f'{",".join([str(i) for i in data])}'
else:
return None
class Record: class Record:
"""
An object to represent an Onspring record.
Attributes:
appId ('int'): The id of the Onspring app where the record resides.
recordId (`int`): The id of the Onspring record.
fields (`list[Models.RecordFieldValue]`): The record's field values.
"""
def __init__(self, appId: int, fields: list[RecordFieldValue], recordId: int=None): def __init__(self, appId: int, fields: list[RecordFieldValue], recordId: int=None):
self.appId = appId self.appId = appId
self.recordId = recordId self.recordId = recordId
self.fields = fields self.fields = fields
class GetRecordsByAppRequest: class GetRecordsByAppRequest:
"""
An object to represent all the necessary information for making a succcessful request to get a collection of Onspring records.
Attributes:
appId (`int`): The id for the Onspring app where the records reside.
fieldIds (`list[int]`): The ids for the fields in the Onspring app that should be included for each record in the response.
dataFormat (`str`): The format of the response data.
pagingRequest (`Models.PagingRequest`): Used to set the page number and page size of the request. By default the these will be 1 and 50 respectively.
"""
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
@@ -592,6 +775,17 @@ class GetRecordsByAppRequest:
self.pageNumber = pagingRequest.pageNumber self.pageNumber = pagingRequest.pageNumber
class QueryRecordsRequest: class QueryRecordsRequest:
"""
An object to represent all the necessary information for making a succcessful request to get a collection of Onspring records based on a specific criteria. For more information on constructing a proper filter please refer to the official Onspring API guide: https://shorturl.at/cnsFK.
Attributes:
appId (`int`): The id for the Onspring app where the records reside.
filter (`str`): The criteria used to determine what records should be included in the response.
fieldIds (`list[int]`): The ids for the fields in the Onspring app that should be included for each record in the response.
dataFormat (`str`): The format of the response data.
pagingRequest (`Models.PagingRequest`): Used to set the page number and page size of the request. By default the these will be 1 and 50 respectively.
"""
def __init__(self, appId: int, filter: str, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name, pagingRequest: PagingRequest=PagingRequest(1,50)): def __init__(self, appId: int, filter: str, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name, pagingRequest: PagingRequest=PagingRequest(1,50)):
self.appId = appId self.appId = appId
self.filter = filter self.filter = filter
@@ -600,6 +794,8 @@ class QueryRecordsRequest:
self.pagingRequest = pagingRequest self.pagingRequest = pagingRequest
class GetRecordsResponse: class GetRecordsResponse:
def __init__(self, pageNumber: int, pageSize: int, totalPages: int, totalRecords: int, records: list[Record]): def __init__(self, pageNumber: int, pageSize: int, totalPages: int, totalRecords: int, records: list[Record]):
self.pageNumber = pageNumber self.pageNumber = pageNumber
self.pageSize = pageSize self.pageSize = pageSize