Module
request.py
Request handelling and data structures for interacting with iMath REST API
- class imath_requests.request.DefectData(defect_type: imath_requests.request.DefectType, identified_by: str, timestamp: str, position: imath_requests.request.Pose3D, dimension: imath_requests.request.Pose3D)
Bases:
imath_requests.request.RequestData
Defect data helper class.
TODO: Add description
- defect_type
defect type
- Type
- identified_by
Data source e.g. I3DR_DESKTOP_ABC123
- Type
str
- timestamp
Timestamp e.g. 1516193959559
- Type
str
- position
Position of defect
- Type
Position
- dimension
Dimension of defect
- Type
Dimension
- static from_json(json_data: str) imath_requests.request.ImageInspectionData
- to_json() dict
Convert ImageInspectionData into json string for use in REST API.
- Returns
Json formatted string
- Return type
dict
- class imath_requests.request.DefectType(code: str)
Bases:
imath_requests.request.RequestData
Defect data helper class.
TODO: Add description
- code
defect code
- Type
str
- static from_json(json_data: str) imath_requests.request.DefectType
- to_json() dict
Convert DefectType into json string for use in REST API.
- Returns
Json formatted string
- Return type
dict
- exception imath_requests.request.EntityExistsError(response: requests.models.Response)
Bases:
imath_requests.request.iMathResponseError
Exception for entity already exists
- exception imath_requests.request.HttpRequestMethodNotSupportedError(response: requests.models.Response)
Bases:
imath_requests.request.ResponseError
Exception for Http Request Method Not Supported
- class imath_requests.request.ImageInspectionData(filename: str, captured_by: str, timestamp: str, position: imath_requests.request.Pose3D, dimension: imath_requests.request.Pose3D, defects: list)
Bases:
imath_requests.request.RequestData
Image Inspection data helper class.
TODO: Add description
- filename
Image filename
- Type
str
- captured_by
Data source e.g. I3DR_DESKTOP_ABC123
- Type
str
- timestamp
Timestamp e.g. 1516193959559
- Type
str
- defects
List of DefectData
- Type
list
- static from_json(json_data: str) imath_requests.request.ImageInspectionData
- to_json() dict
Convert ImageInspectionData into json string for use in REST API.
- Returns
Json formatted string
- Return type
dict
- class imath_requests.request.MetaData(property: str, value: any)
Bases:
imath_requests.request.RequestData
Meta data helper class.
Includes addition functions creating json data from meta data for easy use in REST API.
- property
Name of meta data
- Type
str
- value
value of meta data
- Type
str/int/float
- static from_json(json_data: dict) imath_requests.request.MetaData
- to_json() dict
Convert MetaData into json string for use in REST API.
- Returns
Json formatted string
- Return type
dict
- property value
- class imath_requests.request.PartInspectionData(id: str, source: str, timestamp: str, images: list, meta_datas: list)
Bases:
imath_requests.request.RequestData
Part Inspection data helper class.
TODO: Add description
- id
Unique part ID e.g. Part1234
- Type
str
- source
Data source e.g. I3DR_DESKTOP_ABC123
- Type
str
- timestamp
Timestamp e.g. 1516193959559
- Type
str
- images
List of ImageInspectionData
- Type
list
- meta_datas
List of MetaData
- Type
list
- static from_json(json_data: str) imath_requests.request.PartInspectionData
- to_json() dict
Convert InspectionData into json string for use in REST API.
- Returns
Json formatted string
- Return type
dict
- class imath_requests.request.Pose3D(x: float, y: float, z: float)
Bases:
object
Pose 3D class.
Store pose data as x, y, z
- x
X component of pose
- Type
float
- y
Y component of pose
- Type
float
- z
Z component of pose
- Type
float
- class imath_requests.request.RequestData
Bases:
abc.ABC
- abstract static from_json()
- abstract to_json() dict
- exception imath_requests.request.RequestError
Bases:
Exception
Base class for other request exceptions
- exception imath_requests.request.ResponseError(response: requests.models.Response)
Bases:
imath_requests.request.RequestError
Exception for bad response
- exception imath_requests.request.iMathResponseError(response: requests.models.Response)
Bases:
imath_requests.request.ResponseError
Exception for bad response from iMath backend exceptions
- imath_requests.request.post(json_data: dict, ip, username, password, client=None)
- imath_requests.request.post_data(request_data: imath_requests.request.RequestData, ip, username, password, client=None)
- imath_requests.request.timestamp(dt: datetime.datetime)
server.py
Mock server for testing REST API.
- class imath_requests.server.PartEndpoint
Bases:
flask_restful.Resource
Part data API endpoint class.
Resource used in Flask app to mock REST API.
- get()
REST API get request to return part data.
- Returns
part data (json), status code
- Return type
tuple, int
- methods: t.Optional[t.List[str]] = {'GET', 'POST'}
A list of methods this view can handle.
- post()
REST API post request to accept part data.
- Returns
part data (json), status code
- Return type
tuple, int
- imath_requests.server.create_app(test_config=None)
Create Flask app
Create and configure the app to mockup server for iMath REST API.
- Parameters
test_config – Test config
- Returns
Flask App, Flask API
- Return type
app, api