Example #1
0
        public async Task <FormUrlResult> GenerateFormUrl(FormUrlOptions parameters)
        {
            if (parameters == null)
            {
                throw new Exception("parameters not provided");
            }
            if (parameters.formsAppId == null)
            {
                Form form = await oneBlinkApiClient.GetRequest <Form>($"/forms/{parameters.formId}");

                parameters.formsAppId = form.formsAppIds[0];
            }

            if (parameters.formsAppId == null)
            {
                throw new Exception("This form has not been added to a forms app yet.");
            }
            FormsListFormsApp formsApp = await oneBlinkApiClient.GetRequest <FormsListFormsApp>($"/forms-apps/{parameters.formsAppId}");

            string preFillFormDataId = null;

            if (parameters.preFillData != null)
            {
                PrefillClient prefillClient = new PrefillClient(oneBlinkApiClient);
                PreFillMeta   preFillMeta   = await prefillClient.GetPreFillMeta((int)parameters.formId);

                string preFillMetaId = await prefillClient.PutPreFillData <dynamic>(parameters.preFillData, preFillMeta);

                preFillFormDataId = preFillMeta.preFillFormDataId;
            }

            string userToken = null;

            if (parameters.username != null)
            {
                AesUserToken aesUserToken = new AesUserToken(parameters.secret);
                userToken = aesUserToken.encrypt(parameters.username);
            }

            // Default expiry for token is 8 hours
            int    jwtExpiry = parameters.expiryInSeconds ?? 28800;
            string token     = Token.GenerateJSONWebToken(accessKey: oneBlinkApiClient.accessKey, oneBlinkApiClient.secretKey, jwtExpiry);

            string formUrl = _generateFormUrl(
                formId: parameters.formId,
                formsApp: formsApp,
                token: token,
                externalId: parameters.externalId,
                preFillFormDataId: preFillFormDataId,
                userToken: userToken,
                previousFormSubmissionApprovalId: parameters.previousFormSubmissionApprovalId
                );
            string expiry = DateTime.UtcNow.AddSeconds(jwtExpiry).ToString("o");

            return(new FormUrlResult()
            {
                formUrl = formUrl,
                expiry = expiry
            });
        }
Example #2
0
        public async Task <Job> CreateJob <T>(Job job, T preFillData)
        {
            _ValidateJob(job);
            PrefillClient prefillClient = new PrefillClient(oneBlinkApiClient);
            string        preFillMetaId = await prefillClient.SetPreFillData <T>(preFillData, job.formId);

            job.preFillFormDataId = preFillMetaId;

            return(await _CreateJob(job));
        }