예제 #1
0
        /// <summary>
        /// Creates a Consumersurveys service that be used to send HTTP requests.
        /// </summary>
        /// <param name="serviceAccointEmail"> The service account email we are using for 2LO.</param>
        /// <returns>
        /// The consumer survey service used to send the HTTP requests.
        /// </returns>
        private static ConsumersurveysService GetServiceAccountCredential(
            String serviceAccountEmail)
        {
            X509Certificate2 certificate;

            try {
                certificate = new X509Certificate2(
                    @".\key.p12", "notasecret", X509KeyStorageFlags.Exportable);
            } catch (Exception e)
            {
                Console.WriteLine("Make sure key.p12 file is in the right location.\n" +
                                  e.ToString());
                return(null);
            }
            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                Scopes = new[] {
                    "https://www.googleapis.com/auth/consumersurveys",
                    "https://www.googleapis.com/auth/consumersurveys.readonly",
                    "https://www.googleapis.com/auth/userinfo.email"
                }
            }.FromCertificate(certificate));

            // Creating the consumer surveys service.
            var service = new ConsumersurveysService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
            });

            return(service);
        }
예제 #2
0
        /// <summary>
        /// Begins running a survey.
        /// Documentation https://developers.google.com/consumersurveys/v2/reference/surveys/start
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Consumersurveys service.</param>
        /// <param name="resourceId">NA</param>
        /// <param name="body">A valid Consumersurveys v2 body.</param>
        /// <returns>SurveysStartResponseResponse</returns>
        public static SurveysStartResponse Start(ConsumersurveysService service, string resourceId, SurveysStartRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (resourceId == null)
                {
                    throw new ArgumentNullException(resourceId);
                }

                // Make the request.
                return(service.Surveys.Start(body, resourceId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Surveys.Start failed.", ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Updates a MobileAppPanel. Currently the only property that can be updated is the owners property.
        /// Documentation https://developers.google.com/consumersurveys/v2/reference/mobileapppanels/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Consumersurveys service.</param>
        /// <param name="panelId">External URL ID for the panel.</param>
        /// <param name="body">A valid Consumersurveys v2 body.</param>
        /// <returns>MobileAppPanelResponse</returns>
        public static MobileAppPanel Update(ConsumersurveysService service, string panelId, MobileAppPanel body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (panelId == null)
                {
                    throw new ArgumentNullException(panelId);
                }

                // Make the request.
                return(service.Mobileapppanels.Update(body, panelId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Mobileapppanels.Update failed.", ex);
            }
        }
예제 #4
0
        /// <summary>
        /// Returns the Survey object for tbe specified survey id.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id of the Survey object we need.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey GetSurvey(ConsumersurveysService cs, String surveyId)
        {
            Survey survey = cs.Surveys.Get(surveyId).Execute();

            Console.WriteLine(survey.JsonSpec);
            return(survey);
        }
예제 #5
0
        /// <summary>
        /// Creates a new survey using a json object containing necessary survey fields.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="owners"> The list of owners that will be in the newly created survey.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>

        private static Survey CreateSurvey(ConsumersurveysService cs, List <String> owners)
        {
            SurveyAudience audience = new SurveyAudience()
            {
                Country = "US"
            };
            List <SurveyQuestion> questions = new List <SurveyQuestion>();
            SurveyQuestion        question  = new SurveyQuestion()
            {
                UnitsPosition          = "before",
                Type                   = "openNumericQuestion",
                Question               = "How much did you pay for your last phone?",
                LowValueLabel          = "1",
                UnitOfMeasurementLabel = "$",
                SingleLineResponse     = true,
                OpenTextPlaceholder    = "enter amount here",
            };

            questions.Add(question);

            Survey survey = new Survey()
            {
                Owners              = owners,
                Description         = "What phones do people buy and how much do they pay?",
                Title               = "Phone purchase survey",
                WantedResponseCount = 110,
                Audience            = audience,
                Questions           = questions,
            };
            Survey createdSurvey = cs.Surveys.Insert(survey).Execute();

            return(createdSurvey);
        }
예제 #6
0
        /// <summary>
        /// Creates a new survey using a json object containing necessary survey fields.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="owners"> The list of owners that will be in the newly created survey.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey CreateSurvey(ConsumersurveysService cs, List<String> owners)
        {
            SurveyAudience audience = new SurveyAudience()
            {
                Country = "US"
            };
            List<SurveyQuestion> questions = new List<SurveyQuestion>();
            SurveyQuestion question = new SurveyQuestion()
            {
                UnitsPosition = "before",
                Type = "openNumericQuestion",
                Question = "How much did you pay for your last phone?",
                LowValueLabel = "1",
                UnitOfMeasurementLabel = "$",
                SingleLineResponse = true,
                OpenTextPlaceholder = "enter amount here",
            };
            questions.Add(question);

            Survey survey = new Survey()
            {
                Owners = owners,
                Description = "What phones do people buy and how much do they pay?",
                Title = "Phone purchase survey",
                WantedResponseCount = 110,
                Audience = audience,
                Questions = questions,
            };
            Survey createdSurvey = cs.Surveys.Insert(survey).Execute();
            return createdSurvey;
        }
예제 #7
0
        /// <summary>
        /// Writes the survey results into a xls file.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id for which we are downloading the results for.</param>
        /// <param name="resultFile"> The file name which we write the survey results to.</param>
        private static void GetSurveyResults(
            ConsumersurveysService cs, String surveyId, String resultFile)
        {
            FileStream fileSteam = new FileStream(resultFile, FileMode.Create);

            cs.Results.Get(surveyId).Download(fileSteam);
        }
예제 #8
0
        /// <summary>
        /// Updates a survey. Currently the only property that can be updated is the owners property.
        /// Documentation https://developers.google.com/consumersurveys/v2/reference/surveys/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Consumersurveys service.</param>
        /// <param name="surveyUrlId">External URL ID for the survey.</param>
        /// <param name="body">A valid Consumersurveys v2 body.</param>
        /// <returns>SurveyResponse</returns>
        public static Survey Update(ConsumersurveysService service, string surveyUrlId, Survey body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (surveyUrlId == null)
                {
                    throw new ArgumentNullException(surveyUrlId);
                }

                // Make the request.
                return(service.Surveys.Update(body, surveyUrlId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Surveys.Update failed.", ex);
            }
        }
예제 #9
0
        /// <summary>
        /// Prints the surveys that are owned by the given user.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        private static void ListSurveys(ConsumersurveysService cs)
        {
            var surveyListResponse = cs.Surveys.List().Execute();

            foreach (Survey survey in surveyListResponse.Resources)
            {
                Console.WriteLine(survey.SurveyUrlId);
            }
        }
예제 #10
0
        /// <summary>
        /// Sends the survey to the review process and it is then started.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id of the survey we are starting.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey StartSurvey(ConsumersurveysService cs, String surveyId)
        {
            Survey survey = new Survey()
            {
                State = "running",
            };
            Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();

            return(updatedSurvey);
        }
예제 #11
0
        /// <summary>
        /// Updates the response count of the survey.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id for which we are updating the response count for.</param>
        /// <param name="responseCount">  An integer specifing the new response count for the survey.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey UpdateSurveyResponseCount(
            ConsumersurveysService cs, String surveyId, int responseCount)
        {
            Survey survey = new Survey()
            {
                WantedResponseCount = responseCount,
            };
            Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();

            return(updatedSurvey);
        }
예제 #12
0
        /// <summary>
        /// Updates the response count of the survey.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id for which we are updating the response count for.</param>
        /// <param name="responseCount">  An integer specifing the new response count for the survey.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey UpdateSurveyResponseCount(
            ConsumersurveysService cs, String surveyId, int responseCount)
        {
            Survey survey = new Survey()
            {
                WantedResponseCount = responseCount,
            };
            Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();

            Console.WriteLine("something2: " + updatedSurvey.JsonSpec);
            return(updatedSurvey);
        }
예제 #13
0
        /// <summary>
        /// Retrieves any survey results that have been produced so far. Results are formatted as an Excel file. You must add "?alt=media" to the URL as an argument to get results.
        /// Documentation https://developers.google.com/consumersurveys/v2/reference/results/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Consumersurveys service.</param>
        /// <param name="surveyUrlId">External URL ID for the survey.</param>
        /// <returns>SurveyResultsResponse</returns>
        public static SurveyResults Get(ConsumersurveysService service, string surveyUrlId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (surveyUrlId == null)
                {
                    throw new ArgumentNullException(surveyUrlId);
                }

                // Make the request.
                return(service.Results.Get(surveyUrlId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Results.Get failed.", ex);
            }
        }
예제 #14
0
        /// <summary>
        /// Lists the MobileAppPanels available to the authenticated user.
        /// Documentation https://developers.google.com/consumersurveys/v2/reference/mobileapppanels/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Consumersurveys service.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>MobileAppPanelsListResponseResponse</returns>
        public static MobileAppPanelsListResponse List(ConsumersurveysService service, MobileapppanelsListOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }

                // Building the initial request.
                var request = service.Mobileapppanels.List();

                // Applying optional parameters to the request.
                request = (MobileapppanelsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Mobileapppanels.List failed.", ex);
            }
        }
예제 #15
0
        /// <summary>
        /// Returns the Survey object for tbe specified survey id.
        /// </summary>
        /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
        /// <param name="surveyId"> The survey id of the Survey object we need.</param>
        /// <returns>
        /// A Survey object containing information about the survey.
        /// </returns>
        private static Survey GetSurvey(ConsumersurveysService cs, String surveyId)
        {
            Survey survey = cs.Surveys.Get(surveyId).Execute();

            return(survey);
        }
예제 #16
0
 /// <summary>
 /// Updates the response count of the survey.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id for which we are updating the response count for.</param>
 /// <param name="responseCount">  An integer specifing the new response count for the survey.</param>
 /// <returns>
 /// A Survey object containing information about the survey.
 /// </returns>
 private static Survey UpdateSurveyResponseCount(
     ConsumersurveysService cs, String surveyId, int responseCount)
 {
     Survey survey = new Survey()
     {
         WantedResponseCount = responseCount,
     };
     Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();
     return updatedSurvey;
 }
예제 #17
0
 /// <summary>
 /// Sends the survey to the review process and it is then started.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id of the survey we are starting.</param>
 /// <returns>
 /// A Survey object containing information about the survey.
 /// </returns>      
 private static Survey StartSurvey(ConsumersurveysService cs, String surveyId)
 {
     Survey survey = new Survey()
     {
         State = "running",
     };
     Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();
     return updatedSurvey;
 }
예제 #18
0
 /// <summary>
 /// Updates the response count of the survey.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id for which we are updating the response count for.</param>
 /// <param name="responseCount">  An integer specifing the new response count for the survey.</param>
 /// <returns>
 /// A Survey object containing information about the survey.
 /// </returns>
 private static Survey UpdateSurveyResponseCount(
     ConsumersurveysService cs, String surveyId, int responseCount)
 {
     Survey survey = new Survey()
     {
         WantedResponseCount = responseCount,
     };
     Survey updatedSurvey = cs.Surveys.Update(survey, surveyId).Execute();
     Console.WriteLine("something2: " + updatedSurvey.JsonSpec);
     return updatedSurvey;
 }
예제 #19
0
 /// <summary>
 /// Returns the Survey object for tbe specified survey id.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id of the Survey object we need.</param>
 /// <returns>
 /// A Survey object containing information about the survey.
 /// </returns> 
 private static Survey GetSurvey(ConsumersurveysService cs, String surveyId)
 {
     Survey survey = cs.Surveys.Get(surveyId).Execute();
     return survey;
 }
예제 #20
0
 /// <summary>
 /// Writes the survey results into a xls file.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id for which we are downloading the results for.</param>
 /// <param name="resultFile"> The file name which we write the survey results to.</param>
 private static void GetSurveyResults(
     ConsumersurveysService cs, String surveyId, String resultFile)
 {
     FileStream fileSteam = new FileStream(resultFile, FileMode.Create);
     cs.Results.Get(surveyId).Download(fileSteam);
 }
예제 #21
0
 /// <summary>
 /// Prints the surveys that are owned by the given user.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 private static void ListSurveys(ConsumersurveysService cs)
 {
     var surveyListResponse = cs.Surveys.List().Execute();
     foreach (Survey survey in surveyListResponse.Resources)
     {
         Console.WriteLine(survey.SurveyUrlId);
     }
 }
예제 #22
0
 /// <summary>
 /// Creates a Consumersurveys service that be used to send HTTP requests.
 /// </summary>
 /// <param name="serviceAccointEmail"> The service account email we are using for 2LO.</param>
 /// <returns>
 /// The consumer survey service used to send the HTTP requests.
 /// </returns>         
 private static ConsumersurveysService GetServiceAccountCredential(
     String serviceAccountEmail)
 {
     X509Certificate2 certificate;
     try {
         certificate = new X509Certificate2(
             @".\key.p12", "notasecret", X509KeyStorageFlags.Exportable);
     } catch (Exception e)
     {
         Console.WriteLine("Make sure key.p12 file is in the right location.\n" +
             e.ToString());
         return null;
     }
     ServiceAccountCredential credential = new ServiceAccountCredential(
         new ServiceAccountCredential.Initializer(serviceAccountEmail)
         {
             Scopes = new[] {
                 "https://www.googleapis.com/auth/consumersurveys",
                 "https://www.googleapis.com/auth/consumersurveys.readonly",
                 "https://www.googleapis.com/auth/userinfo.email" }
         }.FromCertificate(certificate));
 
     // Creating the consumer surveys service.
     var service = new ConsumersurveysService(new BaseClientService.Initializer()
     {
         HttpClientInitializer = credential,
     });
     return service;
 }
예제 #23
0
 /// <summary>
 /// Returns the Survey object for tbe specified survey id.
 /// </summary>
 /// <param name="cs"> The consumer survey service used to send the HTTP requests.</param>
 /// <param name="surveyId"> The survey id of the Survey object we need.</param>
 /// <returns>
 /// A Survey object containing information about the survey.
 /// </returns> 
 private static Survey GetSurvey(ConsumersurveysService cs, String surveyId)
 {
     Survey survey = cs.Surveys.Get(surveyId).Execute();
     Console.WriteLine(survey.JsonSpec);
     return survey;
 }