/// <summary> /// Updates a survey. Currently the only property that can be updated is the owners property. /// Documentation https://developers.google.com/surveys/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 Surveys service.</param> /// <param name="surveyUrlId">External URL ID for the survey.</param> /// <param name="body">A valid Surveys v2 body.</param> /// <returns>SurveyResponse</returns> public static Survey Update(SurveysService 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); } }
public void Given() { const string username = "******"; const string password = "******"; const string recipient = "44123456789"; var surveyId = Guid.NewGuid(); _errorCode = "survey_problem"; _errorDescription = "There was a problem"; _errorValue = "THIS VALUE"; _errorValue2 = "OTHER VALUE"; var data = new { errors = new[] { new { code = _errorCode, description = _errorDescription, values = new[] { _errorValue, _errorValue2 } } } }; MockApi.SetEndpoint(new MockEndpoint(400, JsonConvert.SerializeObject(data), "application/json; charset=utf-8")); var surveysClient = new SurveysService(MockApi.Url, new EsendexCredentials(username, password)); _result = surveysClient.Send(surveyId, recipient); }
/// <summary> /// Begins running a survey. /// Documentation https://developers.google.com/surveys/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 Surveys service.</param> /// <param name="resourceId">NA</param> /// <param name="body">A valid Surveys v2 body.</param> /// <returns>SurveysStartResponseResponse</returns> public static SurveysStartResponse Start(SurveysService 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); } }
public async Task DetailTest() { var fake = Mock.Of <ISurveysRepo>(); var surveyService = new SurveysService(fake); var id = "2"; await surveyService.DetailsSurveys(id); }
/// <summary> /// Creates a Surveys service that be used to send HTTP requests. /// </summary> /// <returns> /// The survey service used to send the HTTP requests. /// </returns> private static SurveysService GetServiceAccountCredential() { String accountSecretFileName = "account_secret.json"; // [START google_surveys_auth] var scopes = new[] { SurveysService.Scope.Surveys, SurveysService.Scope.SurveysReadonly, SurveysService.Scope.UserinfoEmail }; GoogleCredential credential; using (var stream = new FileStream(accountSecretFileName, FileMode.Open, FileAccess.Read)) { credential = GoogleCredential.FromStream(stream).CreateScoped(scopes); } var surveysService = new SurveysService(new BaseClientService.Initializer() { HttpClientInitializer = credential, }); // [END google_surveys_auth] return(surveysService); }
/// <summary> /// Updates a MobileAppPanel. Currently the only property that can be updated is the owners property. /// Documentation https://developers.google.com/surveys/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 Surveys service.</param> /// <param name="panelId">External URL ID for the panel.</param> /// <param name="body">A valid Surveys v2 body.</param> /// <returns>MobileAppPanelResponse</returns> public static MobileAppPanel Update(SurveysService 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); } }
/// <summary> /// Writes the survey results into a xls file. /// </summary> /// <param name="surveysService"> The 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( SurveysService surveysService, String surveyId, String resultFile) { // [START google_surveys_results] FileStream fileSteam = new FileStream(resultFile, FileMode.Create); surveysService.Results.Get(surveyId).Download(fileSteam); // [END google_surveys_results] }
/// <summary> /// Gets information about a survey. /// </summary> /// <param name="surveysService"> The survey service used to send the HTTP requests.</param> /// <param name="surveyId"> The survey id of the survey we are getting.</param> /// <returns> /// A Survey object containing information about the survey. /// </returns> private static Survey GetSurvey(SurveysService surveysService, String surveyId) { // [START google_surveys_get] Survey survey = surveysService.Surveys.Get(surveyId).Execute(); // [END google_surveys_get] return(survey); }
public async Task RemoveTest() { var fake = Mock.Of <ISurveysRepo>(); var surveyService = new SurveysService(fake); var survey = new Survey() { Question = "test2?", Min = 0, Desc1 = "desc1", Max = 8, Desc2 = "desc2", TherapyId = "2" }; await surveyService.Delete(survey); }
public async Task AddTest() { var fake = Mock.Of <ISurveysRepo>(); var surveyService = new SurveysService(fake); var survey = new Survey() { Question = "test?", Min = 0, Desc1 = "desc1", Max = 10, Desc2 = "desc2", TherapyId = "3" }; await surveyService.AddAndSave(survey); }
public async Task UpdateTest() { var fake = Mock.Of <ISurveysRepo>(); var surveyService = new SurveysService(fake); var survey = new Survey() { Question = "test1?", Min = 0, Desc1 = "desc1", Max = 9, Desc2 = "desc2", TherapyId = "1" }; await surveyService.Update(survey); }
/// <summary> /// Updates the response count of the survey. /// </summary> /// <param name="surveysService"> The 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( SurveysService surveysService, String surveyId, int responseCount) { Survey survey = new Survey() { WantedResponseCount = responseCount, }; Survey updatedSurvey = surveysService.Surveys.Update(survey, surveyId).Execute(); return(updatedSurvey); }
/// <summary> /// Prints the surveys that are owned by the given user. /// </summary> /// <param name="surveysService"> The survey service used to send the HTTP requests.</param> private static void ListSurveys(SurveysService surveysService) { // [START google_surveys_list] var surveyListResponse = surveysService.Surveys.List().Execute(); // [END google_surveys_list] foreach (Survey survey in surveyListResponse.Resources) { Console.WriteLine(survey.SurveyUrlId); } }
/// <summary> /// Sends the survey to the review process and it is then started. /// </summary> /// <param name="surveysService"> The 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(SurveysService surveysService, String surveyId) { // [START google_surveys_start] Survey newSurvey = new Survey() { State = "running", }; Survey survey = surveysService.Surveys.Update(newSurvey, surveyId).Execute(); // [END google_surveys_start] return(survey); }
public void Given() { const string username = "******"; const string password = "******"; _recipient = "44123456789"; _surveyId = Guid.NewGuid(); _expectedUrl = string.Format("/v1.0/surveys/{0}/send", _surveyId); _expectedUserAgent = string.Format("Esendex .NET SDK v{0}.{1}.{2}", _version.Major, _version.Minor, _version.Build); MockApi.SetEndpoint(new MockEndpoint(200, contentType: "text/plain")); var surveysClient = new SurveysService(MockApi.Url, new EsendexCredentials(username, password)); surveysClient.Send(_surveyId, _recipient); _request = MockApi.LastRequest; }
public async Task GetSurveysTest() { var surveys = new List <Survey> { new Survey() { Question = "test3?", Min = 0, Desc1 = "desc1", Max = 7, Desc2 = "desc2", TherapyId = "4" }, new Survey() { Question = "test4?", Min = 0, Desc1 = "desc1", Max = 6, Desc2 = "desc2", TherapyId = "5" }, }; var fakeRepositoryMock = new Mock <ISurveysRepo>(); fakeRepositoryMock.Setup(x => x.GetAll()).ReturnsAsync(surveys); var surveyService = new SurveysService(fakeRepositoryMock.Object); var resultSurveys = await surveyService.GetSurvey(); Assert.Collection(resultSurveys, survey => { Assert.Equal("test3?", survey.Question); Assert.Equal(0, survey.Min); Assert.Equal("desc1", survey.Desc1); Assert.Equal(7, survey.Max); Assert.Equal("desc2", survey.Desc2); Assert.Equal("4", survey.TherapyId); }, survey => { Assert.Equal("test4?", survey.Question); Assert.Equal(0, survey.Min); Assert.Equal("desc1", survey.Desc1); Assert.Equal(6, survey.Max); Assert.Equal("desc2", survey.Desc2); Assert.Equal("5", survey.TherapyId); }); }
public void Given() { const string username = "******"; const string password = "******"; const string recipient = "44123456789"; var surveyId = Guid.NewGuid(); MockApi.SetEndpoint(new MockEndpoint(_statusCode)); var surveysClient = new SurveysService(MockApi.Url, new EsendexCredentials(username, password)); try { surveysClient.Send(surveyId, recipient); } catch (WebException ex) { _result = ex; } }
/// <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/surveys/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 Surveys service.</param> /// <param name="surveyUrlId">External URL ID for the survey.</param> /// <returns>SurveyResultsResponse</returns> public static SurveyResults Get(SurveysService 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); } }
/// <summary> /// Creates a survey. /// Documentation https://developers.google.com/surveys/v2/reference/surveys/insert /// 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 Surveys service.</param> /// <param name="body">A valid Surveys v2 body.</param> /// <returns>SurveyResponse</returns> public static Survey Insert(SurveysService service, Survey body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.Surveys.Insert(body).Execute()); } catch (Exception ex) { throw new Exception("Request Surveys.Insert failed.", ex); } }
/// <summary> /// Creates a new survey using a json object containing necessary survey fields. /// </summary> /// <param name="surveysService"> The 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(SurveysService surveysService, List <String> owners) { // [START google_surveys_create] List <string> langs = new List <string>(); langs.Add("en-US"); SurveyAudience audience = new SurveyAudience() { Country = "US", Languages = langs }; List <SurveyQuestion> questions = new List <SurveyQuestion>(); SurveyQuestion question = new SurveyQuestion() { Type = "numericOpenEnded", Question = "How much did you pay for your last phone?", UnitOfMeasurementLabel = "$", SingleLineResponse = true, OpenTextPlaceholder = "enter amount here", }; questions.Add(question); Survey newSurvey = 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 survey = surveysService.Surveys.Insert(newSurvey).Execute(); // [END google_surveys_create] return(survey); }
/// <summary> /// Lists the MobileAppPanels available to the authenticated user. /// Documentation https://developers.google.com/surveys/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 Surveys service.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>MobileAppPanelsListResponseResponse</returns> public static MobileAppPanelsListResponse List(SurveysService 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); } }
public SurveyController(SurveysService surveysService) { _surveysService = surveysService; }
/// <summary> /// Deletes a survey. /// </summary> /// <param name="surveysService"> The survey service used to send the HTTP requests.</param> /// <param name="surveyId"> The survey id of the survey we are deleting.</param> private static void DeleteSurvey(SurveysService surveysService, String surveyId) { // [START google_surveys_delete] surveysService.Surveys.Delete(surveyId).Execute(); // [END google_surveys_delete] }
public override void TestInit() { this.SurveysService = new SurveysService(); this.currentuser = new TestUser(); }