- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
SDK
Py93 has a SDK.
It is stored in $py93.sdk.
Sends a XMLHttpRequest to an URL given in link parameter.
- 
link- String, the function will send aXMLHttpRequestto URL given in this parameter
- 
callback- Function, takes 2 parameters, will be called when got a response or an error occured
- 
async(optional) - Boolean, determines should request be asynchronous, default istrue
- 
succeed- Boolean, determines if request succeed (we got any response from server)
- 
details- Object, contains details about the request.
If request succeed, then details will have these properties:
- 
contentType- Value of response headerContent-Type, example:application/json; charset=utf-8
- 
status- HTTP status code, for example404,200
- 
statusText- HTTP status text, example:Not Found
- 
resp- A string with response from server.
- 
xhr-XMLHttpRequestcopy that used to configure and send the request, can be used for getting more data about the request.
If request failed, then details will have these attributes:
- 
errorType- Type of an error, possible values areerrorandtimeout
- 
xhr-XMLHttpRequestcopy that used to configure and send the request, can be used for getting more data about the request.
errorType will be equal to error if request failed (event error happened), for example: it was blocked by CORS.
If request failed, you can see the error message in the JavaScript console.
errorType will be equal to timeout if the request timed out (event timeout happened)
Example of details object, request succeed:
{
    contentType: "application/json; charset=utf-8",
    status: 200,
    statusText: "",
    resp: '{"foo": "bar"}',
    xhr: XMLHttpRequest {}
}Example of details object, request failed:
{
    errorType: "error",
    xhr: XMLHttpRequest {}
}$py93.sdk.checkLink('https://example.com/', function(succeed, details) {
    if (succeed) { // code in this if statement will not run
        console.log('Request succeed!')
    } else { // but code in else will run
        console.log(`Request failed! Error type: ${details.errorType}`) // => Request failed! Error type: error
    }
}, true) // Note: this request will be blocked by CORSValidates JSON string or object.
- 
json- A JSON string or object to validate
If no errors happened, then this function will return an object that has these properties:
- 
valid- Boolean,trueif all properties inchecksistrue, otherwisefalse.
- 
checks- Object that contains 8 booleans, if string/object is valid, then all booleans istrue.
If an error happened, then this function will return undefined and log the error to JavaScript console using console.error.
Object checks has these properties:
- 
versionExist- True ifversionexist
- 
versionIsNum- True ifversionis a number
- 
versionSupp- True if package JSON file syntax (defined inversion) is supported by this Py93 version
- 
metaExist- True ifmetaexist and it'stypeofisobject
- 
meta_titleExist- True iftitleinmetaexist
- 
meta_compVerExist- True ifcompVerinmetaexist
- 
installExist- True ifinstallexist andtypeofisobject
- 
install_packageExist- True ifpackagein "install" exist and typeof isstring
Example 1:
var returned = $py93.sdk.validatePackageJSON({
    version: 1,
    meta: {
        title: "hello-wiki",
        compVer: 1
    },
    install: {
        package: "https://example.com"
    }
})
console.log(`Valid: ${returned.valid}`) // => Valid: trueExample 2:
var returned = $py93.sdk.validatePackageJSON('{"version":1,"meta":{"title":"hello-wiki","compVer":1},"install":{"package":"https://example.com"}}')
console.log(`Valid: ${returned.valid}`) // => Valid: trueExample 3:
var returned = $py93.sdk.validatePackageJSON({
    meta: {
        title: "hello-wiki",
        compVer: 1
    },
    install: {
        package: "https://example.com"
    }
})
console.log(`Valid: ${returned.valid}`) // => Valid: falseExample 4:
var returned = $py93.sdk.validatePackageJSON('{"meta":{"title":"hello-wiki","compVer":1},"install":{"package":"https://example.com"}}')
console.log(`Valid: ${returned.valid}`) // => Valid: falseExample 5:
var returned = $py93.sdk.validatePackageJSON('{version:1,"meta":{"title":"hello-wiki","compVer":1},"install":{"package":"https://example.com"}}')
console.log(returned) // => undefined