Esempio n. 1
0
        private static AweformUser AweformUserFromJSON(AweformJSON.Element json)
        {
            AweformUser user = new AweformUser();

            user.Id           = json.GetAttributeAsInt64("id");
            user.EmailAddress = json.GetAttributeAsString("emailAddress");
            user.Name         = json.GetAttributeAsString("name");
            user.AccountType  = json.GetAttributeAsString("accountType");

            return(user);
        }
Esempio n. 2
0
        private static AweformFormDefinition AweformFormDefinitionFromJSON(AweformJSON.Element json)
        {
            AweformFormDefinition formDefinition = new AweformFormDefinition();

            formDefinition.Id          = json.GetAttributeAsInt64("id");
            formDefinition.Name        = json.GetAttributeAsString("name");
            formDefinition.WorkspaceId = json.GetAttributeAsInt64("workspaceId");

            AweformJSON.Element components = json.GetAttribute("components");

            foreach (AweformJSON.Element component in components.Elements)
            {
                AweformFormComponent formComponent = new AweformFormComponent();
                formComponent.Name = component.GetAttributeAsString("name");
                formComponent.Type = (AweformFormComponentType)Enum.Parse(typeof(AweformFormComponentType), component.GetAttributeAsString("type"));

                if (formComponent.Type == AweformFormComponentType.PictureChoice || formComponent.Type == AweformFormComponentType.Rating || formComponent.Type == AweformFormComponentType.Select || formComponent.Type == AweformFormComponentType.YesNo)
                {
                    formComponent.Options = new List <String>();

                    AweformJSON.Element options = component.GetAttribute("options");

                    foreach (AweformJSON.Element option in options.Elements)
                    {
                        formComponent.Options.Add(option.Value);
                    }
                }

                formDefinition.Components.Add(formComponent);
            }

            return(formDefinition);
        }
Esempio n. 3
0
        private static AweformResponse AweformResponseFromJSON(AweformJSON.Element json)
        {
            AweformResponse response = new AweformResponse();

            response.Id          = json.GetAttributeAsInt64("id");
            response.DateInUtc   = DateTime.Parse(json.GetAttributeAsString("dateInUTC"), CultureInfo.InvariantCulture);
            response.FormId      = json.GetAttributeAsInt64("formId");
            response.WorkspaceId = json.GetAttributeAsInt64("workspaceId");

            List <AweformJSON.Element> attributes = json.GetAttributes();

            foreach (AweformJSON.Element attribute in attributes)
            {
                if (attribute.Name == "id" || attribute.Name == "dateInUTC" || attribute.Name == "formId" || attribute.Name == "workspaceId")
                {
                    continue;
                }

                AweformQuestionAndAnswer questionAndAnswer = new AweformQuestionAndAnswer();
                questionAndAnswer.Question = attribute.Name;
                questionAndAnswer.Answer   = attribute.Value;

                response.Answers.Add(questionAndAnswer);
            }

            return(response);
        }
Esempio n. 4
0
        private static AweformWorkspace AweformWorkspaceFromJSON(AweformJSON.Element json)
        {
            AweformWorkspace workspace = new AweformWorkspace();

            workspace.Id   = json.GetAttributeAsInt64("id");
            workspace.Name = json.GetAttributeAsString("name");

            return(workspace);
        }
Esempio n. 5
0
        private static AweformForm AweformFormFromJSON(AweformJSON.Element json)
        {
            AweformForm form = new AweformForm();

            form.Id          = json.GetAttributeAsInt64("id");
            form.Name        = json.GetAttributeAsString("name");
            form.WorkspaceId = json.GetAttributeAsInt64("workspaceId");

            return(form);
        }
Esempio n. 6
0
        protected AweformJSON.Element Request(String url)
        {
            WebClient wc = new WebClient();

            String response = wc.DownloadString(APIURL + url + (url.Contains("?", StringComparison.InvariantCulture) ? "&" : "?") + "apiKey=" + APIKey);

            wc.Dispose();

            AweformJSON.Element component = AweformJSON.Parse(response);

            if (component.GetAttribute("error") != null)
            {
                throw new AweformException(component.GetAttributeAsString("error"));
            }

            return(component);
        }