2022-04-16 11:36:46 -05:00
import datetime
2022-04-16 22:55:22 -05:00
import uuid
2022-04-16 11:36:46 -05:00
2022-04-18 15:07:31 -05:00
from Enums import *
from decimal import Decimal
from datetime import datetime
from Helpers import parseDate
2022-04-17 00:31:43 -05:00
2022-04-16 11:36:46 -05:00
# generic
2022-04-15 14:44:27 -05:00
class ApiResponse :
2022-04-23 17:02:51 -05:00
"""
An object to represent a response to a request made by an `OnspringClient`.
Attributes:
statusCode (`int`): The http status code of the response.
data: If the success was successful will contain the response data deserialized to custom python objects.
message (`str`): A message that may provide more detail about the requests success or failure.
raw (`requests.Response`): Exposes the raw response object of the request if you'd like to handle it directly.
"""
2022-04-19 21:09:55 -05:00
def __init__ ( self , statusCode = None , data = None , message = None , raw = None ):
2022-04-15 14:44:27 -05:00
self . statusCode = statusCode
self . isSuccessful = int ( statusCode ) < 400
self . data = data
self . message = message
2022-04-19 21:09:55 -05:00
self . raw = raw
2022-04-15 14:44:27 -05:00
class PagingRequest :
2022-04-23 17:02:51 -05:00
"""
An object to represent the page number and page size of a paginated request made by an `OnspringClient`.
Attributes:
pageNumber (`int`): The page number that will be requested.
pageSize (`int`): The size of the page that will be requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , pageNumber : int , pageSize : int ):
2022-04-15 14:44:27 -05:00
self . pageNumber = pageNumber
self . pageSize = pageSize
2022-04-16 11:36:46 -05:00
#app specific
2022-04-15 14:44:27 -05:00
class App :
2022-04-23 17:02:51 -05:00
"""
An object to represent an Onspring app.
Attributes:
href (`str`): The href for the Onspring app.
id (`int`): The id of the Onspring app.
name (`str`): The name of the Onspring app.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , href : str , id : int , name : str ):
2022-04-15 14:44:27 -05:00
self . href = href
self . id = id
self . name = name
class GetAppsResponse :
2022-04-23 17:02:51 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a paginated response to a request made by an `OnspringClient` to request a collection of Onspring apps.
2022-04-23 17:02:51 -05:00
Attributes:
2022-04-27 20:32:09 -05:00
pageNumber (`int`): The page number returned.
pageSize (`int`): The size of the page returned.
totalPages (`int`): The total number of pages for the request.
totalRecords (`int`): The total records for the request.
apps (`list[Models.App]`): The apps requested.
2022-04-23 17:02:51 -05:00
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , pageNumber : int , pageSize : int , totalPages : int , totalRecords : int , apps : list [ App ]):
2022-04-15 14:44:27 -05:00
self . pageNumber = pageNumber
self . pageSize = pageSize
self . totalPages = totalPages
self . totalRecords = totalRecords
self . apps = apps
class GetAppByIdResponse :
2022-04-27 20:32:09 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a response to a request made by an `OnspringClient` to request an Onspring app.
2022-04-27 20:32:09 -05:00
Attributes:
app (`Models.App`): The requested app.
"""
2022-04-15 14:44:27 -05:00
def __init__ ( self , app : App ):
self . app = app
class GetAppsByIdsResponse :
2022-04-27 20:32:09 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a response to a request made by an `OnspringClient` to request a collection of Onspring apps.
2022-04-27 20:32:09 -05:00
Attributes:
count (`int`): The number of apps requested.
apps (`list[Models.App]`): The apps requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , count : int , apps : list [ App ]):
2022-04-15 14:44:27 -05:00
self . count = count
self . apps = apps
2022-04-16 11:36:46 -05:00
# field specific
2022-04-21 16:22:44 -05:00
class ListValue :
2022-04-28 11:51:04 -05:00
"""
An object to represent an Onspring list value.
Attributes:
id (`int`): The id of the Onspring list value.
name (`str`): The list value's name.
sortOrder (`int`): The list value's sort order in respect to other values in the same list.
numericalValue (`Decimal`): The numeric value assigned to the list value.
color (`str`): The color assigned to the list value.
"""
2022-04-21 16:22:44 -05:00
def __init__ ( self , id : int , name : str , sortOrder : int , numericValue : Decimal , color : str ):
self . id = id
self . name = name
self . sortOrder = sortOrder
if numericValue != None :
self . numericValue = Decimal ( numericValue )
else :
self . numericValue = numericValue
self . color = color
def AsString ( self ):
2022-04-28 11:51:04 -05:00
"""
Gets the list value as a comma separated string of it's properties and their values.
Args:
None
Returns:
A `str` representation of the list value object.
"""
2022-04-21 16:22:44 -05:00
return f 'Id: { self . id } , Name: { self . name } , Value: { self . numericValue } , Sort Order: { self . sortOrder } , Color: { self . color } '
2022-04-15 14:44:27 -05:00
class Field :
2022-04-28 11:51:04 -05:00
"""
An object to represent an Onspring field.
Attributes:
id (`int`): The id of the Onspring field.
appId ('int'): The id of the Onspring app where the field resides.
name (`str`): The name of the field.
type (`str`): The type of the field.
status (`str`): The stuat of the field.
isRequired (`bool`): Indicates whether the field is required in Onspring or not.
isUnique (`bool`): Indicates whether the field requires unique values in Onspring or not.
listId (`int`): The id of the fields list if applicable. Used for list fields and formula fields with list output type.
values (`list[Models.ListValue]`): The values of the fields list if applicable. Used for list fields and formula fields with list output type.
multiplicity (`str`): The multiplicity of the field if applicable. Used for list fields, reference fields, and formula fields with a list output type.
outputType (`str`): The output type of the field if applicable. Used for formula fields.
"""
2022-04-21 16:22:44 -05:00
def __init__ (
self , id : int ,
appId : int ,
name : str ,
type : str ,
status : str ,
isRequired : bool ,
isUnique : bool ,
listId : int = None ,
values : list [ ListValue ] = None ,
multiplicity : str = None ,
outputType : str = None
):
2022-04-15 14:44:27 -05:00
self . id = id
self . appId = appId
self . name = name
self . type = type
self . status = status
self . isRequired = isRequired
self . isUnique = isUnique
2022-04-21 16:22:44 -05:00
self . listId = listId
self . values = values
self . outputType = outputType
self . multiplicity = multiplicity
2022-04-15 14:44:27 -05:00
class GetFieldByIdResponse :
2022-04-28 11:51:04 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a response to a request made by an `OnspringClient` to request an Onspring field.
2022-04-28 11:51:04 -05:00
Attributes:
field (`Models.Field`): The requested field.
"""
2022-04-15 14:44:27 -05:00
def __init__ ( self , field : Field ):
self . field = field
class GetFieldsByIdsResponse :
2022-04-28 11:51:04 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a response to a request made by an `OnspringClient` to request a collection of Onspring fields.
2022-04-28 11:51:04 -05:00
Attributes:
count (`int`): The number of fields requested.
fields (`list[Models.Field]`): The fields requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , count : int , fields : list [ Field ]):
2022-04-15 14:44:27 -05:00
self . count = count
self . fields = fields
class GetFieldsByAppIdResponse :
2022-04-28 11:51:04 -05:00
"""
2022-04-28 12:35:53 -05:00
An object to represent a paginated response to a request made by an `OnspringClient` to request a collection of Onspring fields.
2022-04-28 11:51:04 -05:00
Attributes:
pageNumber (`int`): The page number returned.
pageSize (`int`): The size of the page returned.
totalPages (`int`): The total number of pages for the request.
totalRecords (`int`): The total records for the request.
fields (`list[Models.Field]`): The fields requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , pageNumber : int , pageSize : int , totalPages : int , totalRecords : int , fields : list [ Field ]):
2022-04-15 14:44:27 -05:00
self . pageNumber = pageNumber
self . pageSize = pageSize
self . totalPages = totalPages
self . totalRecords = totalRecords
2022-04-16 11:36:46 -05:00
self . fields = fields
# file specific
class File :
2022-04-28 12:35:53 -05:00
"""
An object to represent a file stored in Onsprng.
Attributes:
name (`str`): The name of the file.
contentType (`str`): The content type of the file.
contentLength (`int`): The length of the file's content.
content (`bytes`): The content of the file.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , name : str , contentType : str , contentLength : int , content : bytes ):
self . name = name
self . contentType = contentType
self . contentLength = contentLength
self . content = content
class FileInfo :
2022-04-28 12:35:53 -05:00
"""
An object to represent the metadata for a file stored in Onspring.
Attributes:
type (`str`): The type of file as stored in Onspring Attachment or Image.
contentType (`str`): The content type of the file itself.
name (`str`): The name of the file
createdDate (`datetime`): The created date of the file.
modifiedDate (`datetime`): The modified date of the file.
owner (`str`): The owner of the file.
fileHref (`str`): The href for the file.
"""
2022-04-18 15:07:31 -05:00
def __init__ ( self , type : str , contentType : str , name : str , createdDate : datetime , modifiedDate : datetime , owner : str , fileHref : str ):
2022-04-16 11:36:46 -05:00
self . type = type
self . contentType = contentType
self . name = name
self . createdDate = createdDate
self . modifiedDate = modifiedDate
self . owner = owner
self . fileHref = fileHref
class GetFileInfoByIdResponse :
2022-04-28 12:35:53 -05:00
"""
An object to represent a response to a request made by an `OnspringClient` to request a info for a file in Onspring.
Attributes:
fileInfo (`Models.FileInfo`): The file info requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , fileInfo : FileInfo ):
self . fileInfo = fileInfo
class GetFileByIdResponse :
2022-04-28 12:35:53 -05:00
"""
An object to represent a response to a request made by an `OnspringClient` to request a file in Onspring.
Attributes:
file (`Models.File`): The file requested.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , file : File ):
self . file = file
class SaveFileRequest :
2022-04-22 23:13:43 -05:00
"""
An object to represent all the necessary information needed to make a successful 'OnspringClient.SaveFile' request.
Attributes:
recordId (`int`): The unique id of the record where you want to save the file.
fieldId (`int`): The unique id of the field where you want to save the file.
fileName (`str`): The name of the file you want to save.
filePath (`str`): The path to the file you want to save.
contentType (`str`): The content type of the file you want to save.
notes (`str`): An option note about the file.
notes (`datetime`): An optional date noting when the file was modified.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , recordId : int , fieldId : int , fileName : str , filePath : str , contentType : str , notes : str = None , modifiedDate : datetime = None ):
self . recordId = recordId
self . fieldId = fieldId
self . notes = notes
self . modifiedDate = modifiedDate
self . fileName = fileName
self . filePath = filePath
self . contentType = contentType
class SaveFileResponse :
2022-04-28 12:35:53 -05:00
"""
An object to represent a response to a request made by an `OnspringClient` to save a file in Onspring.
Attributes:
id (`int`): The id of the file saved in Onspring.
"""
2022-04-16 11:36:46 -05:00
def __init__ ( self , id : int ):
2022-04-16 22:55:22 -05:00
self . id = id
# list specific
class ListItemRequest :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-16 22:55:22 -05:00
def __init__ ( self , listId : int , name : str , id : uuid = None , numericValue : int = None , color : str = None ):
self . listId = listId
self . name = name
self . id = id
self . numericValue = numericValue
self . color = color
class AddOrUpdateListItemResponse :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-16 22:55:22 -05:00
def __init__ ( self , id : uuid ):
2022-04-17 00:31:43 -05:00
self . id = id
# record specific
2022-04-18 10:39:20 -05:00
class RecordFieldValue :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-19 21:09:55 -05:00
def __init__ ( self , fieldId : int , value : str , type : str = None ):
2022-04-18 10:39:20 -05:00
self . fieldId = fieldId
self . value = value
2022-04-29 10:53:17 -05:00
self . type = type
2022-04-18 10:39:20 -05:00
def AsString ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 10:39:20 -05:00
if self . type != ResultValueType . String . name :
return None
2022-04-20 00:07:44 -05:00
return StringFieldValue ( self . fieldId , self . value ) . value
2022-04-18 10:39:20 -05:00
2022-04-18 16:13:34 -05:00
def AsInteger ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 10:39:20 -05:00
if self . type != ResultValueType . Integer . name :
return None
2022-04-20 13:45:34 -05:00
return IntegerFieldValue ( self . fieldId , int ( self . value )) . value
2022-04-18 10:39:20 -05:00
def AsDecimal ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 10:39:20 -05:00
if self . type != ResultValueType . Decimal . name :
return None
2022-04-20 13:45:34 -05:00
return DecimalFieldValue ( self . fieldId , Decimal ( self . value )) . value
2022-04-18 10:39:20 -05:00
def AsDate ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 10:39:20 -05:00
if self . type != ResultValueType . Date . name :
return None
2022-04-18 15:07:31 -05:00
date = parseDate ( self . value )
2022-04-18 10:39:20 -05:00
2022-04-20 13:45:34 -05:00
return DateFieldValue ( self . fieldId , date ) . value
2022-04-18 10:39:20 -05:00
def AsGuid ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 10:39:20 -05:00
if self . type != ResultValueType . Guid . name :
return None
2022-04-20 13:45:34 -05:00
return GuidFieldValue ( self . fieldId , uuid . UUID ( self . value )) . value
2022-04-18 10:39:20 -05:00
2022-04-18 15:07:31 -05:00
def AsTimeSpan ( self ):
2022-04-29 10:53:17 -05:00
"""
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`.
"""
2022-04-18 15:07:31 -05:00
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 )
2022-04-20 13:45:34 -05:00
return TimeSpanValue ( self . fieldId , data ) . value
2022-04-18 15:07:31 -05:00
def AsStringList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 15:07:31 -05:00
if self . type != ResultValueType . StringList . name :
return None
2022-04-20 13:45:34 -05:00
strings = [ str ( string ) for string in self . value ]
return StringListValue ( self . fieldId , strings ) . value
2022-04-18 15:07:31 -05:00
def AsIntegerList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 15:07:31 -05:00
if self . type != ResultValueType . IntegerList . name :
return None
2022-04-20 13:45:34 -05:00
integers = [ int ( integer ) for integer in self . value ]
2022-04-18 15:07:31 -05:00
2022-04-20 13:45:34 -05:00
return IntegerListValue ( self . fieldId , integers ) . value
2022-04-18 15:07:31 -05:00
def AsGuidList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 15:07:31 -05:00
if self . type != ResultValueType . GuidList . name :
return None
guids = []
for guid in self . value :
guids . append ( uuid . UUID ( guid ))
2022-04-20 13:45:34 -05:00
return GuidListValue ( self . fieldId , guids ) . value
2022-04-18 15:07:31 -05:00
def AsAttachmentList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 16:13:34 -05:00
if self . type != ResultValueType . AttachmentList . name :
return None
attachments = []
for attachment in self . value :
attachment = dict ( attachment )
attachment = Attachment (
attachment . get ( 'fileId' ),
attachment . get ( 'fileName' ),
attachment . get ( 'notes' ),
attachment . get ( 'storageLocation' ))
attachments . append ( attachment )
2022-04-20 13:45:34 -05:00
return AttachmentListValue ( self . fieldId , attachments ) . value
2022-04-18 15:07:31 -05:00
def AsScoringGroupList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 16:13:34 -05:00
if self . type != ResultValueType . ScoringGroupList . name :
return
scoringGroups = []
for scoringGroup in self . value :
scoringGroup = dict ( scoringGroup )
scoringGroup = ScoringGroup (
uuid . UUID ( scoringGroup . get ( 'listValueId' )),
scoringGroup . get ( 'name' ),
Decimal ( scoringGroup . get ( 'score' )),
Decimal ( scoringGroup . get ( 'maximumScore' )))
scoringGroups . append ( scoringGroup )
2022-04-20 13:45:34 -05:00
return ScoringGroupListValue ( self . fieldId , scoringGroups ) . value
2022-04-18 15:07:31 -05:00
def AsFileList ( self ):
2022-04-29 10:53:17 -05:00
"""
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]`.
"""
2022-04-18 16:13:34 -05:00
if self . type != ResultValueType . FileList . name :
return None
2022-04-20 13:45:34 -05:00
files = [ int ( file ) for file in self . value ]
2022-04-18 16:13:34 -05:00
2022-04-20 13:45:34 -05:00
return FileListValue ( self . fieldId , files ) . value
2022-04-18 16:13:34 -05:00
def getValue ( self ):
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-18 16:13:34 -05:00
if self . type == ResultValueType . String . name :
return self . AsString ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . Integer . name :
return self . AsInteger ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . Decimal . name :
return self . AsDecimal ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . Date . name :
return self . AsDate ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . TimeSpan . name :
return self . AsTimeSpan ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . Guid . name :
return self . AsGuid ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . StringList . name :
return self . AsStringList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . IntegerList . name :
return self . AsIntegerList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . GuidList . name :
return self . AsGuidList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . AttachmentList . name :
return self . AsAttachmentList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . ScoringGroupList . name :
return self . AsScoringGroupList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
elif self . type == ResultValueType . FileList . name :
return self . AsFileList ()
2022-04-29 10:53:17 -05:00
2022-04-18 16:13:34 -05:00
else :
return None
2022-04-18 10:39:20 -05:00
2022-04-20 13:45:34 -05:00
def GetResultValueString ( self ):
2022-04-29 10:53:17 -05:00
"""
Will return the value property regardless of the field value's type as a string.
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
Args:
None
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
Returns:
The value of the `Models.RecordFieldValue` as a string.
"""
if self . type == ResultValueType . String . name :
return self . AsString ()
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . Integer . name :
return self . AsInteger ()
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . Decimal . name :
return self . AsDecimal ()
elif self . type == ResultValueType . Date . name :
return self . AsDate ()
elif self . type == ResultValueType . TimeSpan . name :
data = self . AsTimeSpan ()
return f 'Quantity: { data . quantity } , Increment: { data . increment } , Recurrence: { data . recurrence } , EndByDate: { data . endByDate } , EndAfterOccurrences: { data . endAfterOccurrences } '
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . Guid . name :
return self . AsGuid ()
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . StringList . name :
data = self . AsStringList ()
return f ' { "," . join ( data ) } '
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . IntegerList . name :
data = self . AsIntegerList ()
return f ' { "," . join ([ str ( i ) for i in data ]) } '
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . GuidList . name :
data = self . AsGuidList ()
return f ' { "," . join ([ str ( guid ) for guid in data ]) } '
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . AttachmentList . name :
data = self . AsAttachmentList ()
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
strings = []
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
for attachment in data :
string = f 'FileId: { attachment . fileId } , FileName: { attachment . fileName } , Notes: { attachment . notes } , StorageLocation: { attachment . storageLocation } '
strings . append ( string )
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
return f ' { "; " . join ( strings ) } '
2022-04-20 13:45:34 -05:00
2022-04-29 10:53:17 -05:00
elif self . type == ResultValueType . ScoringGroupList . name :
data = self . AsScoringGroupList ()
strings = []
for scoringGroup in data :
string = f 'ListValueId: { scoringGroup . listValueId } , Name: { scoringGroup . name } , Score: { scoringGroup . score } , Max Score: { scoringGroup . maximumScore } '
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
2022-04-20 13:45:34 -05:00
2022-04-18 10:39:20 -05:00
class Record :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-19 21:09:55 -05:00
def __init__ ( self , appId : int , fields : list [ RecordFieldValue ], recordId : int = None ):
2022-04-18 10:39:20 -05:00
self . appId = appId
self . recordId = recordId
2022-04-18 15:07:31 -05:00
self . fields = fields
2022-04-18 10:39:20 -05:00
2022-04-17 00:31:43 -05:00
class GetRecordsByAppRequest :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-17 00:31:43 -05:00
def __init__ ( self , appId : int , fieldIds : list [ int ] = [], dataFormat : str = DataFormat . Raw . name , pagingRequest : PagingRequest = PagingRequest ( 1 , 50 )):
self . appId = appId
self . fieldIds = fieldIds
self . dataFormat = dataFormat
self . pageSize = pagingRequest . pageSize
2022-04-18 10:39:20 -05:00
self . pageNumber = pagingRequest . pageNumber
2022-04-19 21:09:55 -05:00
class QueryRecordsRequest :
2022-04-29 10:53:17 -05:00
"""
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.
"""
2022-04-19 21:09:55 -05:00
def __init__ ( self , appId : int , filter : str , fieldIds : list [ int ] = [], dataFormat : str = DataFormat . Raw . name , pagingRequest : PagingRequest = PagingRequest ( 1 , 50 )):
self . appId = appId
self . filter = filter
self . fieldIds = fieldIds
self . dataFormat = dataFormat
self . pagingRequest = pagingRequest
class GetRecordsResponse :
2022-04-29 10:53:17 -05:00
2022-04-18 10:39:20 -05:00
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
2022-04-19 21:09:55 -05:00
self . records = records
class GetRecordByIdRequest :
def __init__ ( self , appId : int , recordId : int , fieldIds : list [ int ] = [], dataFormat : str = DataFormat . Raw . name ):
self . appId = appId
self . recordId = recordId
self . fieldIds = fieldIds
self . dataFormat = dataFormat
class GetBatchRecordsRequest :
def __init__ ( self , appId : int , recordIds : list [ int ], fieldIds : list [ int ] = [], dataFormat : str = DataFormat . Raw . name ):
self . appId = appId
self . recordIds = recordIds
self . fieldIds = fieldIds
self . dataFormat = dataFormat
class GetBatchRecordsResponse :
def __init__ ( self , count : int , records : list [ Record ]):
self . count = count
self . records = records
class AddOrUpdateRecordResponse :
def __init__ ( self , id : int , warnings : list [ str ] = []):
self . id = id
2022-04-20 00:07:44 -05:00
self . warnings = warnings
2022-04-20 13:45:34 -05:00
class DeleteBatchRecordsRequest :
def __init__ ( self , appId : int , recordIds : list [ int ]):
2022-04-21 16:22:44 -05:00
self . appId = appId
2022-04-20 13:45:34 -05:00
self . recordIds = recordIds
2022-04-20 00:07:44 -05:00
# field types
class StringFieldValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value ):
self . type = ResultValueType . String . name
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 13:45:34 -05:00
class IntegerFieldValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : int ):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . Integer . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class DecimalFieldValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : Decimal ):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . Decimal . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class DateFieldValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : datetime ):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . Date . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class GuidFieldValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : uuid . UUID ):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . Guid . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
class TimeSpanData :
def __init__ ( self , quantity : Decimal , increment : Increment , recurrence : Recurrence = None , endByDate : datetime = None , endAfterOccurrences : int = None ):
self . quantity = quantity
self . increment = increment
self . recurrence = recurrence
self . endByDate = endByDate
self . endAfterOccurrences = endAfterOccurrences
def AsString ( self ):
if self . endByDate != None :
formattedDate = self . endByDate . strftime ( "%m/ %d /%Y %I:%M %p" )
return f 'Every { self . quantity } { self . increment } End By { formattedDate } '
elif self . endAfterOccurrences != None :
return f 'Every { self . quantity } { self . increment } End After { self . endAfterOccurrences } '
else :
return f ' { self . quantity } { self . increment } '
2022-04-20 13:45:34 -05:00
class TimeSpanValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : TimeSpanData ):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . TimeSpan . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class StringListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ str ]):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . StringList . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class IntegerListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ int ]):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . IntegerList . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class GuidListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ uuid . UUID ]):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . GuidList . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
class Attachment :
def __init__ ( self , fileId : int , fileName : str , notes : str , storageLocation : str ):
self . fileId = fileId
self . fileName = fileName
self . notes = notes
self . storageLocation = storageLocation
2022-04-20 13:45:34 -05:00
class AttachmentListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ Attachment ]):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . AttachmentList . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
2022-04-20 13:45:34 -05:00
class FileListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ int ]):
2022-04-20 00:07:44 -05:00
self . type = ResultValueType . FileList . name
2022-04-20 13:45:34 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
2022-04-20 00:07:44 -05:00
class ScoringGroup :
def __init__ ( self , listValueId : uuid . UUID , name : str , score : Decimal , maximumScore : Decimal ):
self . listValueId = listValueId
self . name = name
self . score = score
self . maximumScore = maximumScore
2022-04-20 13:45:34 -05:00
class ScoringGroupListValue ( RecordFieldValue ):
def __init__ ( self , fieldId : int , value : list [ ScoringGroup ]):
self . type = ResultValueType . ScoringGroupList . name
2022-04-21 16:22:44 -05:00
RecordFieldValue . __init__ ( self , fieldId , value , self . type )
# report specific
class GetReportByIdRequest :
def __init__ ( self , reportId : int , apiDataFormat : str = DataFormat . Raw . name , dataType : str = ReportDataType . ReportData . name ):
self . reportId = reportId
self . apiDataFormat = apiDataFormat
self . dataType = dataType
class Row :
def __init__ ( self , recordId : int , cells : list [ str ]):
self . recordId = recordId
self . cells = cells
class GetReportByIdResponse :
def __init__ ( self , columns : list [ str ], rows : list [ Row ]):
self . columns = columns
self . rows = rows
class Report :
def __init__ ( self , appId : int , id : int , name : str , description : str ):
self . appId = appId
self . id = id
self . name = name
self . description = description
class GetReportsByAppIdResponse :
def __init__ ( self , pageNumber : int , pageSize : int , totalPages : int , totalRecords : int , reports : list [ Report ]):
self . pageNumber = pageNumber
self . pageSize = pageSize
self . totalPages = totalPages
self . totalRecords = totalRecords
self . reports = reports