public void GetResponseListPagesAndContinuesWhenCompletePageIsReturned()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":100,""total"":300,""data"":[{""id"":""1""},{""id"":""2""},{""id"":""3""},{""id"":""4""},{""id"":""5""},{""id"":""6""},{""id"":""7""},{""id"":""8""},{""id"":""9""},{""id"":""10""},{""id"":""11""},{""id"":""12""},{""id"":""13""},{""id"":""14""},{""id"":""15""},{""id"":""16""},{""id"":""17""},{""id"":""18""},{""id"":""19""},{""id"":""20""},{""id"":""21""},{""id"":""22""},{""id"":""23""},{""id"":""24""},{""id"":""25""},{""id"":""26""},{""id"":""27""},{""id"":""28""},{""id"":""29""},{""id"":""30""},{""id"":""31""},{""id"":""32""},{""id"":""33""},{""id"":""34""},{""id"":""35""},{""id"":""36""},{""id"":""37""},{""id"":""38""},{""id"":""39""},{""id"":""40""},{""id"":""41""},{""id"":""42""},{""id"":""43""},{""id"":""44""},{""id"":""45""},{""id"":""46""},{""id"":""47""},{""id"":""48""},{""id"":""49""},{""id"":""50""},{""id"":""51""},{""id"":""52""},{""id"":""53""},{""id"":""54""},{""id"":""55""},{""id"":""56""},{""id"":""57""},{""id"":""58""},{""id"":""59""},{""id"":""60""},{""id"":""61""},{""id"":""62""},{""id"":""63""},{""id"":""64""},{""id"":""65""},{""id"":""66""},{""id"":""67""},{""id"":""68""},{""id"":""69""},{""id"":""70""},{""id"":""71""},{""id"":""72""},{""id"":""73""},{""id"":""74""},{""id"":""75""},{""id"":""76""},{""id"":""77""},{""id"":""78""},{""id"":""79""},{""id"":""80""},{""id"":""81""},{""id"":""82""},{""id"":""83""},{""id"":""84""},{""id"":""85""},{""id"":""86""},{""id"":""87""},{""id"":""88""},{""id"":""89""},{""id"":""90""},{""id"":""91""},{""id"":""92""},{""id"":""93""},{""id"":""94""},{""id"":""95""},{""id"":""96""},{""id"":""97""},{""id"":""98""},{""id"":""99""},{""id"":""100""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934\/responses?page=1&per_page=100""}}
            ");
            client.Responses.Add(@"
                {""per_page"":100,""total"":300,""data"":[{""id"":""101""},{""id"":""102""},{""id"":""103""},{""id"":""104""},{""id"":""105""},{""id"":""106""},{""id"":""107""},{""id"":""108""},{""id"":""109""},{""id"":""110""},{""id"":""111""},{""id"":""112""},{""id"":""113""},{""id"":""114""},{""id"":""115""},{""id"":""116""},{""id"":""117""},{""id"":""118""},{""id"":""119""},{""id"":""120""},{""id"":""121""},{""id"":""122""},{""id"":""123""},{""id"":""124""},{""id"":""125""},{""id"":""126""},{""id"":""127""},{""id"":""128""},{""id"":""129""},{""id"":""130""},{""id"":""131""},{""id"":""132""},{""id"":""133""},{""id"":""134""},{""id"":""135""},{""id"":""136""},{""id"":""137""},{""id"":""138""},{""id"":""139""},{""id"":""140""},{""id"":""141""},{""id"":""142""},{""id"":""143""},{""id"":""144""},{""id"":""145""},{""id"":""146""},{""id"":""147""},{""id"":""148""},{""id"":""149""},{""id"":""150""},{""id"":""151""},{""id"":""152""},{""id"":""153""},{""id"":""154""},{""id"":""155""},{""id"":""156""},{""id"":""157""},{""id"":""158""},{""id"":""159""},{""id"":""160""},{""id"":""161""},{""id"":""162""},{""id"":""163""},{""id"":""164""},{""id"":""165""},{""id"":""166""},{""id"":""167""},{""id"":""168""},{""id"":""169""},{""id"":""170""},{""id"":""171""},{""id"":""172""},{""id"":""173""},{""id"":""174""},{""id"":""175""},{""id"":""176""},{""id"":""177""},{""id"":""178""},{""id"":""179""},{""id"":""180""},{""id"":""181""},{""id"":""182""},{""id"":""183""},{""id"":""184""},{""id"":""185""},{""id"":""186""},{""id"":""187""},{""id"":""188""},{""id"":""189""},{""id"":""190""},{""id"":""191""},{""id"":""192""},{""id"":""193""},{""id"":""194""},{""id"":""195""},{""id"":""196""},{""id"":""197""},{""id"":""198""},{""id"":""199""},{""id"":""200""}],""page"":2,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/?page=2&per_page=100""}}
            ");
            client.Responses.Add(@"
                {""per_page"":100,""total"":300,""data"":[{""id"":""201""},{""id"":""202""},{""id"":""203""},{""id"":""204""},{""id"":""205""},{""id"":""206""},{""id"":""207""},{""id"":""208""},{""id"":""209""},{""id"":""210""},{""id"":""211""},{""id"":""212""},{""id"":""213""},{""id"":""214""},{""id"":""215""},{""id"":""216""},{""id"":""217""},{""id"":""218""},{""id"":""219""},{""id"":""220""},{""id"":""221""},{""id"":""222""},{""id"":""223""},{""id"":""224""},{""id"":""225""},{""id"":""226""},{""id"":""227""},{""id"":""228""},{""id"":""229""},{""id"":""230""},{""id"":""231""},{""id"":""232""},{""id"":""233""},{""id"":""234""},{""id"":""235""},{""id"":""236""},{""id"":""237""},{""id"":""238""},{""id"":""239""},{""id"":""240""},{""id"":""241""},{""id"":""242""},{""id"":""243""},{""id"":""244""},{""id"":""245""},{""id"":""246""},{""id"":""247""},{""id"":""248""},{""id"":""249""},{""id"":""250""},{""id"":""251""},{""id"":""252""},{""id"":""253""},{""id"":""254""},{""id"":""255""},{""id"":""256""},{""id"":""257""},{""id"":""258""},{""id"":""259""},{""id"":""260""},{""id"":""261""},{""id"":""262""},{""id"":""263""},{""id"":""264""},{""id"":""265""},{""id"":""266""},{""id"":""267""},{""id"":""268""},{""id"":""269""},{""id"":""270""},{""id"":""271""},{""id"":""272""},{""id"":""273""},{""id"":""274""},{""id"":""275""},{""id"":""276""},{""id"":""277""},{""id"":""278""},{""id"":""279""},{""id"":""280""},{""id"":""281""},{""id"":""282""},{""id"":""283""},{""id"":""284""},{""id"":""285""},{""id"":""286""},{""id"":""287""},{""id"":""288""},{""id"":""289""},{""id"":""290""},{""id"":""291""},{""id"":""292""},{""id"":""293""},{""id"":""294""},{""id"":""295""},{""id"":""296""},{""id"":""297""},{""id"":""298""},{""id"":""299""},{""id"":""300""}],""page"":3,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/?page=3&per_page=100""}}
            ");
            client.Responses.Add(@"
                {""per_page"":100,""total"":300,""data"":[],""page"":4,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/?page=4&per_page=100""}}
            ");
            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetCollectorResponseDetailsList(91395530, new GetResponseListSettings {
                Custom = "asdf"
            });

            Assert.AreEqual(300, results.Count);
            Assert.AreEqual(300, results.Last().Id);
            Assert.AreEqual(1, results.First().Id);
            Assert.AreEqual(4, client.Requests.Count);
        }
        public void GetCollectorDetailWeblinkIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""status"":""closed"",""redirect_url"":""https:\/\/www.surveymonkey.com"",""thank_you_message"":""Thank you for completing our survey!"",""response_count"":1,""closed_page_message"":""closed"",""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/57184593"",""close_date"":null,""display_survey_results"":false,""allow_multiple_responses"":true,""anonymous_type"":""not_anonymous"",""id"":""57184593"",""password_enabled"":false,""name"":""Web Link 1"",""date_modified"":""2014-08-26T12:50:00+00:00"",""url"":null,""edit_response_type"":""until_complete"",""sender_email"":null,""date_created"":""2014-08-26T11:14:00+00:00"",""disqualification_message"":""Thank you for completing our survey!"",""type"":""weblink""}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetCollectorDetails(57184593);

            Assert.IsTrue(result.AllowMultipleResponses);
            Assert.AreEqual(Collector.AnonymousOption.NotAnonymous, result.AnonymousType);
            Assert.IsNull(result.CloseDate);
            Assert.AreEqual("closed", result.ClosedPageMessage);
            Assert.AreEqual(new DateTime(2014, 8, 26, 11, 14, 0, DateTimeKind.Utc), result.DateCreated);
            Assert.AreEqual(new DateTime(2014, 8, 26, 12, 50, 0, DateTimeKind.Utc), result.DateModified);
            Assert.IsFalse(result.DisplaySurveyResults);
            Assert.AreEqual("Thank you for completing our survey!", result.DisqualificationMessage);
            Assert.AreEqual(Collector.EditResponseOption.UntilComplete, result.EditResponseType);
            Assert.AreEqual("https://api.surveymonkey.net/v3/collectors/57184593", result.Href);
            Assert.AreEqual(57184593, result.Id);
            Assert.AreEqual("Web Link 1", result.Name);
            Assert.IsFalse(result.PasswordEnabled);
            Assert.AreEqual("https://www.surveymonkey.com", result.RedirectUrl);
            Assert.AreEqual(1, result.ResponseCount);
            Assert.IsNull(result.SenderEmail);
            Assert.AreEqual(Collector.StatusType.Closed, result.Status);
            Assert.AreEqual("Thank you for completing our survey!", result.ThankYouMessage);
            Assert.AreEqual(Collector.CollectorType.Weblink, result.Type);
            Assert.IsNull(result.Url);
        }
        public void RetrySequenceIsRespected()
        {
            var toleranceMilliseconds = 80;

            var response = @"{""id"":""1234"",""name"":""Test Group"",""member_count"":1,""max_invites"":100,""date_created"":""2015-10-06T12:56:55+00:00""}";
            var client   = new MockWebClient();

            client.Responses.Add(response);
            client.Responses.Add(response);
            client.Responses.Add(response);
            client.Exceptions.Add(new WebException("1"));
            client.Exceptions.Add(new WebException("2"));
            client.Exceptions.Add(new WebException("3"));
            var api = new SurveyMonkeyApi("key", "token", client, new [] { 1, 2 });

            var exception = Assert.Throws <WebException>(delegate { api.GetGroupDetails(1234); });

            Assert.AreEqual("3", exception.Message);
            Assert.AreEqual(3, client.Requests.Count);

            Assert.GreaterOrEqual(toleranceMilliseconds, client.Requests.First().TimeSinceInitialisation);

            Assert.LessOrEqual(1000 - toleranceMilliseconds, client.Requests.Skip(1).First().TimeSinceInitialisation);
            Assert.GreaterOrEqual(1000 + toleranceMilliseconds, client.Requests.Skip(1).First().TimeSinceInitialisation);

            Assert.LessOrEqual(3000 - toleranceMilliseconds, client.Requests.Skip(2).First().TimeSinceInitialisation);
            Assert.GreaterOrEqual(3000 + toleranceMilliseconds, client.Requests.Skip(2).First().TimeSinceInitialisation);
        }
        public void GetSurveyResponseOverviewListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":50,""total"":3,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934\/responses\/4968420283"",""id"":""4968420283""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934\/responses\/4968420510"",""id"":""4968420510""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934\/responses\/4968420845"",""id"":""4968420845""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934\/responses?page=1&per_page=50""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetSurveyResponseOverviewList(84672934);

            Assert.AreEqual(1, client.Requests.Count);

            Assert.AreEqual(4968420283, results.First().Id);
            Assert.IsNull(results.First().DateModified);
            Assert.IsNull(results.First().DateCreated);
            Assert.IsNull(results.First().TotalTime);
            Assert.IsNull(results.First().CustomVariables);
            Assert.IsNull(results.First().IpAddress);
            Assert.IsNull(results.First().ResponseStatus);
            Assert.IsNull(results.First().CustomValue);
            Assert.IsNull(results.First().LogicPath);
            Assert.IsNull(results.First().PagePath);
            Assert.IsNull(results.First().Metadata);
            Assert.IsNull(results.First().RecipientId);
            Assert.IsNull(results.First().SurveyId);
            Assert.IsNull(results.First().CollectorId);
            Assert.IsNull(results.First().CollectionMode);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/84672934/responses/4968420283", results.First().Href);
            Assert.IsNull(results.First().EditUrl);
            Assert.IsNull(results.First().AnalyzeUrl);
            Assert.IsNull(results.First().Pages);
        }
        public void CreateWebhookHandledProperly()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3289918"",""event_type"":""response_completed"",""subscription_url"":""http:\/\/targetsite.com\/api\/"",""object_type"":""collector"",""object_ids"":[""49143218""],""id"":""3289918"",""name"":""New webhook""}
            ");

            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            var webhook = new Webhook
            {
                EventType       = WebhookEventType.ResponseCompleted,
                Name            = "New webhook",
                SubscriptionUrl = "http://targetsite.com/api/",
                ObjectType      = WebhookObjectType.Collector,
                ObjectIds       = new List <long> {
                    49143218
                }
            };

            var result = api.CreateWebhook(webhook);

            Assert.AreEqual("New webhook", result.Name);
            Assert.AreEqual(3289918, result.Id);
            Assert.AreEqual("POST", client.Requests.First().Verb);
            StringAssert.DoesNotContain("\"id\"", client.Requests.First().Body);
        }
        public void GetResponseOverviewIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""total_time"":8,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420283"",""custom_variables"":{},""ip_address"":""18.187.48.612"",""id"":""4968420283"",""logic_path"":{},""date_modified"":""2016-09-13T07:29:09+00:00"",""response_status"":""completed"",""custom_value"":"""",""analyze_url"":""http:\/\/www.surveymonkey.com\/analyze\/browse\/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420283"",""page_path"":[],""recipient_id"":"""",""collector_id"":""91395530"",""date_created"":""2016-09-13T07:29:01+00:00"",""survey_id"":""84672934"",""collection_mode"":""default"",""edit_url"":""http:\/\/www.surveymonkey.com\/r\/?sm=db1E_2B5FvGitK17_2F_2F8_2Blnhcl_2BCTwKHT5dPY9EBCDJmi8tUeGDo34qJJ5CuL7ceRS7"",""metadata"":{}}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetCollectorResponseDetails(84672934, 4968420283);

            Assert.AreEqual(@"http://www.surveymonkey.com/analyze/browse/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420283", result.AnalyzeUrl);
            Assert.AreEqual(CollectionMode.Default, result.CollectionMode);
            Assert.AreEqual(91395530, result.CollectorId);
            Assert.AreEqual(String.Empty, result.CustomValue);
            Assert.IsEmpty(result.CustomVariables);
            Assert.AreEqual(new DateTime(2016, 9, 13, 07, 29, 01, DateTimeKind.Utc), result.DateCreated);
            Assert.AreEqual(new DateTime(2016, 9, 13, 07, 29, 09, DateTimeKind.Utc), result.DateModified);
            Assert.AreEqual(@"http://www.surveymonkey.com/r/?sm=db1E_2B5FvGitK17_2F_2F8_2Blnhcl_2BCTwKHT5dPY9EBCDJmi8tUeGDo34qJJ5CuL7ceRS7", result.EditUrl);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/91395530/responses/4968420283", result.Href);
            Assert.AreEqual(4968420283, result.Id);
            Assert.AreEqual("18.187.48.612", result.IpAddress);
            Assert.IsEmpty(result.LogicPath);
            Assert.IsEmpty(result.Metadata);
            Assert.IsEmpty(result.PagePath);
            Assert.IsNull(result.RecipientId);
            Assert.AreEqual(ResponseStatus.Completed, result.ResponseStatus);
            Assert.AreEqual(84672934, result.SurveyId);
            Assert.AreEqual(8, result.TotalTime);
            Assert.IsNull(result.Pages);
        }
        public void GetResponseListUrlsAreCorrectlyGenerated()
        {
            var standardListResponse       = @"{""per_page"":50,""total"":3,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420283"",""id"":""4968420283""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420510"",""id"":""4968420510""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420845"",""id"":""4968420845""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses?page=1&per_page=50""}}";
            var standardIndividualResponse = @"{""total_time"":8,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420283"",""custom_variables"":{},""ip_address"":""18.187.48.612"",""id"":""4968420283"",""logic_path"":{},""date_modified"":""2016-09-13T07:29:09+00:00"",""response_status"":""completed"",""custom_value"":"""",""analyze_url"":""http:\/\/www.surveymonkey.com\/analyze\/browse\/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420283"",""page_path"":[],""recipient_id"":"""",""collector_id"":""91395530"",""date_created"":""2016-09-13T07:29:01+00:00"",""survey_id"":""84672934"",""collection_mode"":""default"",""edit_url"":""http:\/\/www.surveymonkey.com\/r\/?sm=db1E_2B5FvGitK17_2F_2F8_2Blnhcl_2BCTwKHT5dPY9EBCDJmi8tUeGDo34qJJ5CuL7ceRS7"",""metadata"":{}}";
            var client = new MockWebClient();

            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardListResponse);
            client.Responses.Add(standardIndividualResponse);
            client.Responses.Add(standardIndividualResponse);
            client.Responses.Add(standardIndividualResponse);
            client.Responses.Add(standardIndividualResponse);
            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            api.GetSurveyResponseDetailsList(1);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/1/responses/bulk", client.Requests.Last().Url);

            api.GetCollectorResponseDetailsList(2);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/2/responses/bulk", client.Requests.Last().Url);

            api.GetSurveyResponseOverviewList(3);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/3/responses", client.Requests.Last().Url);

            api.GetCollectorResponseOverviewList(4);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/4/responses", client.Requests.Last().Url);

            api.GetSurveyResponseDetailsList(5, new GetResponseListSettings());
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/5/responses/bulk", client.Requests.Last().Url);

            api.GetCollectorResponseDetailsList(6, new GetResponseListSettings());
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/6/responses/bulk", client.Requests.Last().Url);

            api.GetSurveyResponseOverviewList(7, new GetResponseListSettings());
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/7/responses", client.Requests.Last().Url);

            api.GetCollectorResponseOverviewList(8, new GetResponseListSettings());
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/8/responses", client.Requests.Last().Url);

            api.GetSurveyResponseDetails(9, 10);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/9/responses/10/details", client.Requests.Last().Url);

            api.GetCollectorResponseDetails(11, 12);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/11/responses/12/details", client.Requests.Last().Url);

            api.GetSurveyResponseOverview(13, 14);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/surveys/13/responses/14", client.Requests.Last().Url);

            api.GetCollectorResponseOverview(15, 16);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/15/responses/16", client.Requests.Last().Url);
        }
        public void GetGroupListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1,""page"":1,""total"":1,""data"":[{""id"":""1234"",""name"":""Test Group"",""href"":""https://api.surveymonkey.net/v3/groups/1234""}],""links"": {""self"":""https://api.surveymonkey.net/v3/groups?page=1&per_page=1""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetGroupList();

            Assert.AreEqual(1234, results.First().Id);
            Assert.AreEqual("Test Group", results.First().Name);
            Assert.AreEqual("https://api.surveymonkey.net/v3/groups/1234", results.First().Href);
        }
        public void GetCollectorRecipientListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1000,""total"":2,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/94732812\/recipients\/2751878525"",""id"":""2751878525"",""email"":""*****@*****.**""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/94732812\/recipients\/2751878526"",""id"":""2751878526"",""email"":""*****@*****.**""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/94732812\/recipients?page=1&per_page=1000""}}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetCollectorRecipientList(94732812);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(2751878525, result.First().Id);
            Assert.AreEqual("*****@*****.**", result.Last().Email);
            Assert.IsNull(result.First().MailStatus);
        }
Exemplo n.º 10
0
        public void GetWebhookListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":100,""total"":2,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3618472"",""id"":""3618472"",""name"":""First webhook""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3481793"",""id"":""3481793"",""name"":""Second webhook""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/webhooks?page=1&per_page=100""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetWebhookList();

            Assert.AreEqual(1, client.Requests.Count);
            Assert.AreEqual(3618472, results.First().Id);
            Assert.AreEqual("Second webhook", results.Last().Name);
        }
Exemplo n.º 11
0
        public void GetMemberListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1,""page"":1,""total"":1,""data"":[{""id"":""1234"",""username"":""test_user"",""href"":""http://api.surveymonkey.com/v3/members/1234""}],""links"":{""self"":""https://api.surveymonkey.net/v3/groups/12345/members?page=1&per_page=1""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetMemberList(1234);

            Assert.AreEqual(1234, results.First().Id);
            Assert.AreEqual("test_user", results.First().Username);
            Assert.AreEqual("http://api.surveymonkey.com/v3/members/1234", results.First().Href);
            Assert.IsNull(results.First().Status);
        }
Exemplo n.º 12
0
        public void DeleteWebhookHandledProperly()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3289918"",""event_type"":""response_completed"",""subscription_url"":""http:\/\/targetsite.com\/api\/"",""object_type"":""survey"",""object_ids"":[""49143218"",""49146481""],""id"":""3289918"",""name"":""First webhook""}
            ");

            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            var result = api.DeleteWebhook(3289918);

            Assert.AreEqual("First webhook", result.Name);
            Assert.AreEqual(3289918, result.Id);
            Assert.AreEqual("DELETE", client.Requests.First().Verb);
        }
Exemplo n.º 13
0
        public void GetRecipientListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1000,""total"":2,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/recipients\/2407626836"",""id"":""2407626836"",""email"":""*****@*****.**""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/recipients\/2407626837"",""id"":""2407626837"",""email"":""*****@*****.**""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/messages\/29296390\/recipients?page=1&per_page=1000""}}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetRecipientList(85470742, 29296390);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("https://api.surveymonkey.net/v3/collectors/85470742/recipients/2407626836", result.First().Href);
            Assert.AreEqual(2407626836, result.First().Id);
            Assert.AreEqual("*****@*****.**", result.Last().Email);
            Assert.IsNull(result.First().MailStatus);
        }
Exemplo n.º 14
0
        public void GetMessageListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1000,""total"":1,""data"":[{""status"":""sent"",""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/messages\/29296390"",""type"":""invite"",""id"":""29296390""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/messages?page=1&per_page=1000""}}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetMessageList(85470742);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("https://api.surveymonkey.net/v3/collectors/85470742/messages/29296390", result.First().Href);
            Assert.AreEqual(29296390, result.First().Id);
            Assert.AreEqual(MessageStatus.Sent, result.First().Status);
            Assert.AreEqual(MessageType.Invite, result.First().Type);
        }
Exemplo n.º 15
0
        public void GetGroupDetailsIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""id"":""1234"",""name"":""Test Group"",""member_count"":1,""max_invites"":100,""date_created"":""2015-10-06T12:56:55+00:00""}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetGroupDetails(1234);

            Assert.AreEqual(1234, results.Id);
            Assert.AreEqual("Test Group", results.Name);
            Assert.AreEqual(100, results.MaxInvites);
            Assert.AreEqual(new DateTime(2015, 10, 6, 12, 56, 55, DateTimeKind.Utc), results.DateCreated);
            Assert.IsNull(results.OwnerEmail);
        }
Exemplo n.º 16
0
        public void GetCollectorListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1000,""total"":3,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91664733"",""name"":""Email Invitation 1"",""id"":""91664733""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/57184593"",""name"":""Web Link 1"",""id"":""57184593""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/57185230"",""name"":""Web Link 2"",""id"":""57185230""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/55249163\/collectors?page=1&per_page=1000""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetCollectorList(55249163);

            Assert.AreEqual(1, client.Requests.Count);
            Assert.AreEqual(3, results.Count);
            Assert.AreEqual(91664733, results.First().Id);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/91664733", results.First().Href);
            Assert.AreEqual("Web Link 2", results.Last().Name);
            Assert.IsNull(results.First().AllowMultipleResponses);
        }
Exemplo n.º 17
0
        public void AuthenticationIsPassedToApi()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":50,""total"":2,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/55249163"",""id"":""55249163"",""title"":""All Question Types Test""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934"",""id"":""84672934"",""title"":""Two Question Survey""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/?page=1&per_page=50""}}
            ");

            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            api.GetSurveyList();

            Assert.AreEqual("application/json", client.Requests.First().Headers["Content-Type"]);
            Assert.AreEqual("bearer TestOAuthToken", client.Requests.First().Headers["Authorization"]);
            Assert.AreEqual("TestApiKey", client.Requests.First().QueryString["api_key"]);
            Assert.AreEqual(Encoding.UTF8, client.Requests.First().Encoding);
            Assert.AreEqual("https://api.surveymonkey.net/v3/surveys", client.Requests.First().Url);
        }
Exemplo n.º 18
0
        public void GetWebhookDetailsIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3285187"",""event_type"":""response_completed"",""subscription_url"":""http:\/\/targetsite.com\/api\/"",""object_type"":""survey"",""object_ids"":[""86842167""],""id"":""3285187"",""name"":""First webhook""}
            ");

            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            var result = api.GetWebhookDetails(3285187);

            Assert.AreEqual("First webhook", result.Name);
            Assert.AreEqual(3285187, result.Id);
            Assert.AreEqual("http://targetsite.com/api/", result.SubscriptionUrl);
            Assert.AreEqual(86842167, result.ObjectIds.First());
            Assert.IsNull(result.Authorization);
        }
Exemplo n.º 19
0
        public void GetRecipientDetailsIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""survey_response_status"":""not_responded"",""mail_status"":""sent"",""id"":""2407626836"",""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/recipients\/2407626836"",""remove_link"":""https:\/\/www.surveymonkey.com\/optout.aspx?sm=blablabla"",""survey_id"":""53774320"",""email"":""*****@*****.**"",""survey_link"":""https:\/\/www.surveymonkey.com\/r\/?sm=blabla""}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetRecipientDetails(85470742, 2407626836);

            Assert.AreEqual("*****@*****.**", result.Email);
            Assert.AreEqual("https://api.surveymonkey.net/v3/collectors/85470742/recipients/2407626836", result.Href);
            Assert.AreEqual(2407626836, result.Id);
            Assert.AreEqual(MessageStatus.Sent, result.MailStatus);
            Assert.AreEqual("https://www.surveymonkey.com/optout.aspx?sm=blablabla", result.RemoveLink);
            Assert.AreEqual(53774320, result.SurveyId);
            Assert.AreEqual("https://www.surveymonkey.com/r/?sm=blabla", result.SurveyLink);
            Assert.AreEqual(RecipientSurveyResponseStatus.NotResponded, result.SurveyResponseStatus);
        }
        public void GetCollectorListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":1000,""total"":3,""data"":[{""status"":""new"",""name"":""Email Invitation 1"",""date_modified"":""2016-09-17T21:36:00+00:00"",""response_count"":0,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91664733"",""date_created"":""2016-09-17T21:36:00+00:00"",""type"":""email"",""id"":""91664733""},{""status"":""closed"",""name"":""Web Link 1"",""date_modified"":""2014-08-26T12:50:00+00:00"",""url"":""https:\/\/www.surveymonkey.com\/r\/9QBY7BQ"",""response_count"":1,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/57184593"",""date_created"":""2014-08-26T11:14:00+00:00"",""type"":""weblink"",""id"":""57184593""},{""status"":""closed"",""name"":""Web Link 2"",""date_modified"":""2014-08-26T12:50:00+00:00"",""url"":""https:\/\/www.surveymonkey.com\/r\/9TWKVDN"",""response_count"":98,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/57185230"",""date_created"":""2014-08-26T11:42:00+00:00"",""type"":""weblink"",""id"":""57185230""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/55249163\/collectors?page=1&per_page=1000""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetCollectorList(55249163);

            Assert.AreEqual(1, client.Requests.Count);
            Assert.AreEqual(3, results.Count);
            Assert.AreEqual(91664733, results.First().Id);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/91664733", results.First().Href);
            Assert.AreEqual("Web Link 2", results.Last().Name);
            Assert.AreEqual(Collector.StatusType.New, results.First().Status);
            Assert.AreEqual(0, results.First().ResponseCount);
            Assert.IsNull(results.First().AllowMultipleResponses);
        }
Exemplo n.º 21
0
        public void GetMemberDetailsIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""id"":""1234"",""username"":""test_user"",""email"":""*****@*****.**"",""type"":""regular"",""status"":""active"",""user_id"":""1234"",""date_created"":""2015-10-06T12:56:55+00:00""}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetMemberDetails(1234, 1234);

            Assert.AreEqual(1234, results.Id);
            Assert.AreEqual("test_user", results.Username);
            Assert.AreEqual("*****@*****.**", results.Email);
            Assert.AreEqual(MemberStatus.Active, results.Status);
            Assert.AreEqual(MemberType.Regular, results.Type);
            Assert.IsNull(results.Href);
            Assert.AreEqual("1234", results.UserId);
            Assert.AreEqual(new DateTime(2015, 10, 6, 12, 56, 55, DateTimeKind.Utc), results.DateCreated);
        }
Exemplo n.º 22
0
        public void GetMessageDetailsIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""status"":""sent"",""body"":""Hi,\r\nHere's your survey: [SurveyLink]\r\nUnsubscribe: [OptOutLink]\r\n[FooterLink]"",""recipient_status"":null,""is_branding_enabled"":true,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/85470742\/messages\/29296390"",""is_scheduled"":true,""scheduled_date"":""2016-05-10T16:28:06+00:00"",""date_created"":""2016-05-10T16:23:04+00:00"",""type"":""invite"",""id"":""29296390"",""subject"":""MySubjectLine""}
            ");
            var api    = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var result = api.GetMessageDetails(85470742, 29296390);

            Assert.AreEqual("Hi,\r\nHere\'s your survey: [SurveyLink]\r\nUnsubscribe: [OptOutLink]\r\n[FooterLink]", result.Body);
            Assert.AreEqual(new DateTime(2016, 5, 10, 16, 23, 4, DateTimeKind.Utc), result.DateCreated);
            Assert.AreEqual("https://api.surveymonkey.net/v3/collectors/85470742/messages/29296390", result.Href);
            Assert.AreEqual(29296390, result.Id);
            Assert.IsTrue(result.IsBrandingEnabled);
            Assert.IsTrue(result.IsScheduled);
            Assert.AreEqual(new DateTime(2016, 5, 10, 16, 28, 6, DateTimeKind.Utc), result.ScheduledDate);
            Assert.AreEqual(MessageStatus.Sent, result.Status);
            Assert.AreEqual(MessageType.Invite, result.Type);
        }
Exemplo n.º 23
0
        public void RateLimitIsRespected()
        {
            var toleranceMilliseconds        = 50;
            var defaultRateLimitMilliseconds = 500;

            var stopwatch        = new Stopwatch();
            var client           = new MockWebClient();
            var repeatedResponse = @"
                {""per_page"":50,""total"":2,""data"":[{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/55249163"",""id"":""55249163"",""title"":""All Question Types Test""},{""href"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/84672934"",""id"":""84672934"",""title"":""Two Question Survey""}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/surveys\/?page=1&per_page=50""}}
            ";

            client.Responses.Add(repeatedResponse);
            client.Responses.Add(repeatedResponse);
            client.Responses.Add(repeatedResponse);
            client.Responses.Add(repeatedResponse);

            var api = new SurveyMonkeyApi("key", "token", client, 500);

            //Should be no rate limit first time
            stopwatch.Start();
            api.GetSurveyList();
            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, toleranceMilliseconds);

            //Second request should be rate limited
            stopwatch.Restart();
            api.GetSurveyList();
            Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, defaultRateLimitMilliseconds - toleranceMilliseconds);
            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, defaultRateLimitMilliseconds + toleranceMilliseconds);

            //Check subsequent requests are rate limited too
            stopwatch.Restart();
            api.GetSurveyList();
            Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, defaultRateLimitMilliseconds - toleranceMilliseconds);
            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, defaultRateLimitMilliseconds + toleranceMilliseconds);

            //If some time has elapsed, there should be no delay
            Thread.Sleep(1000);
            stopwatch.Restart();
            api.GetSurveyList();
            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, toleranceMilliseconds);
        }
Exemplo n.º 24
0
        protected void Send_Click(object sender, EventArgs e)
        {
            using (var api = new SurveyMonkeyApi("FUJTCAkWTMKHpIz93MGonA", "7zF8BOnG4G7RzWhxfQxo2a7GL8GCNMI.NkUuZ8eAG7K7qG9WhoRP3iAEkwfbTYwUZ7oUHeu8iqd-XU5h9AXRqmWEs5XP5Q7SQxS-EiQy5iXIYuCrIa6kBDs-3eov8ubt"))
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                //Get the id of our survey (or store this locally to avoid the api call)
                var  surveys  = api.GetUserDetails();
                long surveyId = 0;// surveys.First(s => s.Title == "Customer Feedback Survey").Id.Value;

                //Remember when we last did a check
                DateTime lastCheck = DateTime.UtcNow;

                while (true)
                {
                    //Wait 1 hour
                    System.Threading.Thread.Sleep(60 * 60 * 1000);

                    //Create a settings object to get only responses added since our last check
                    var settings = new GetResponseListSettings {
                        StartCreatedAt = lastCheck
                    };

                    //Remember the current time for filtering the next run
                    lastCheck = DateTime.UtcNow;

                    //Get any new responses
                    List <Response> newResponses = api.GetSurveyResponseDetailsList(surveyId, settings);

                    //Do something with any new responses
                    foreach (Response response in newResponses)
                    {
                        Console.WriteLine("New response from {0} -  view at {1}", response.IpAddress, response.AnalyzeUrl);
                    }

                    //Go again
                }
            }
        }
Exemplo n.º 25
0
        public void GetUserMeIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""username"":""*****@*****.**"",""first_name"":null,""last_name"":""McTest"",""account_type"":""gold"",""language"":""en"",""email"":""*****@*****.**"",""href"":""https:\/\/api.surveymonkey.net\/v3\/users\/me"",""date_last_login"":""2016-09-26T16:23:40.397000+00:00"",""date_created"":""2006-06-28T12:48:00+00:00"",""id"":""123456789""}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetUserDetails();

            Assert.AreEqual("*****@*****.**", results.Username);
            Assert.IsNull(results.FirstName);
            Assert.AreEqual("McTest", results.LastName);
            Assert.AreEqual("gold", results.AccountType);
            Assert.AreEqual("en", results.Language);
            Assert.AreEqual("*****@*****.**", results.Email);
            Assert.AreEqual("https://api.surveymonkey.net/v3/users/me", results.Href);
            Assert.AreEqual(new DateTime(2006, 6, 28, 12, 48, 0, DateTimeKind.Utc), results.DateCreated);
            Assert.AreEqual(new DateTime(2016, 9, 26, 16, 23, 40, 397, DateTimeKind.Utc), results.DateLastLogin);
            Assert.AreEqual(123456789, results.Id);
        }
        public void GetCollectorResponseDetailListIsDeserialised()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""per_page"":50,""total"":3,""data"":[{""total_time"":8,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420283"",""custom_variables"":{},""ip_address"":""18.187.48.612"",""id"":""4968420283"",""logic_path"":{},""date_modified"":""2016-09-13T07:29:09+00:00"",""response_status"":""completed"",""custom_value"":"""",""analyze_url"":""http:\/\/www.surveymonkey.com\/analyze\/browse\/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420283"",""pages"":[{""id"":""253784818"",""questions"":[{""id"":""1013185278"",""answers"":[{""choice_id"":""10565315476""}]},{""id"":""1013185659"",""answers"":[{""text"":""22222""}]}]}],""page_path"":[],""recipient_id"":"""",""collector_id"":""91395530"",""date_created"":""2016-09-13T07:29:01+00:00"",""survey_id"":""84672934"",""collection_mode"":""default"",""edit_url"":""http:\/\/www.surveymonkey.com\/r\/?sm=db1E_2B5FvGitK17_2F_2F8_2Blnhcl_2BCTwKHT5dPY9EBCDJmi8tUeGDo34qJJ5CuL7ceRS7"",""metadata"":{}},{""total_time"":7,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420510"",""custom_variables"":{},""ip_address"":""18.187.48.612"",""id"":""4968420510"",""logic_path"":{},""date_modified"":""2016-09-13T07:29:21+00:00"",""response_status"":""completed"",""custom_value"":"""",""analyze_url"":""http:\/\/www.surveymonkey.com\/analyze\/browse\/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420510"",""pages"":[{""id"":""253784818"",""questions"":[{""id"":""1013185278"",""answers"":[{""choice_id"":""10565315476""}]},{""id"":""1013185659"",""answers"":[{""text"":""2!""}]}]}],""page_path"":[],""recipient_id"":"""",""collector_id"":""91395530"",""date_created"":""2016-09-13T07:29:14+00:00"",""survey_id"":""84672934"",""collection_mode"":""default"",""edit_url"":""http:\/\/www.surveymonkey.com\/r\/?sm=Lx7StOGuxNDuVUAr8BPyjg2ViuVtA8zOHdXIxBAegrKWNdxw4B0iMvxwLegwwvY3"",""metadata"":{}},{""total_time"":15,""href"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/4968420845"",""custom_variables"":{},""ip_address"":""18.187.48.612"",""id"":""4968420845"",""logic_path"":{},""date_modified"":""2016-09-13T07:29:40+00:00"",""response_status"":""completed"",""custom_value"":"""",""analyze_url"":""http:\/\/www.surveymonkey.com\/analyze\/browse\/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420845"",""pages"":[{""id"":""253784818"",""questions"":[{""id"":""1013185278"",""answers"":[{""choice_id"":""10565315477""}]},{""id"":""1013185659"",""answers"":[{""text"":""The second!""}]}]}],""page_path"":[],""recipient_id"":"""",""collector_id"":""91395530"",""date_created"":""2016-09-13T07:29:24+00:00"",""survey_id"":""84672934"",""collection_mode"":""default"",""edit_url"":""http:\/\/www.surveymonkey.com\/r\/?sm=bc2BsaGJJWvkzcJSuPORfnpY5wGZdCs_2F0hBWIXcOYE1FZDU3KKxUI_2BgiFpNVzGc4"",""metadata"":{}}],""page"":1,""links"":{""self"":""https:\/\/api.surveymonkey.net\/v3\/collectors\/91395530\/responses\/bulk?page=1&per_page=50""}}
            ");

            var api     = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);
            var results = api.GetCollectorResponseDetailsList(91395530);

            Assert.AreEqual(1, client.Requests.Count);

            Assert.AreEqual(4968420283, results.First().Id);
            Assert.AreEqual(new DateTime(2016, 9, 13, 7, 29, 9, DateTimeKind.Utc), results.First().DateModified);
            Assert.AreEqual(new DateTime(2016, 9, 13, 7, 29, 01, DateTimeKind.Utc), results.First().DateCreated);
            Assert.AreEqual(8, results.First().TotalTime);
            Assert.IsEmpty(results.First().CustomVariables);
            Assert.AreEqual("18.187.48.612", results.First().IpAddress);
            Assert.AreEqual(ResponseStatus.Completed, results.First().ResponseStatus);
            Assert.AreEqual(String.Empty, results.First().CustomValue);
            Assert.IsEmpty(results.First().LogicPath);
            Assert.IsEmpty(results.First().PagePath);
            Assert.IsEmpty(results.First().Metadata);
            Assert.IsNull(results.First().RecipientId);
            Assert.AreEqual(84672934, results.First().SurveyId);
            Assert.AreEqual(91395530, results.First().CollectorId);
            Assert.AreEqual(CollectionMode.Default, results.First().CollectionMode);
            Assert.AreEqual(@"https://api.surveymonkey.net/v3/collectors/91395530/responses/4968420283", results.First().Href);
            Assert.AreEqual(@"http://www.surveymonkey.com/r/?sm=db1E_2B5FvGitK17_2F_2F8_2Blnhcl_2BCTwKHT5dPY9EBCDJmi8tUeGDo34qJJ5CuL7ceRS7", results.First().EditUrl);
            Assert.AreEqual(@"http://www.surveymonkey.com/analyze/browse/9GyriWHWhcPYK8l_2FdYdcIEvqmtt5hBjuRL79fS2mOFI_3D?respondent_id=4968420283", results.First().AnalyzeUrl);

            Assert.AreEqual(253784818, results.First().Pages.First().Id);
            Assert.AreEqual(1013185278, results.First().Pages.First().Questions.First().Id);
            Assert.AreEqual(10565315476, results.First().Pages.First().Questions.First().Answers.First().ChoiceId);
            Assert.AreEqual(1013185659, results.First().Pages.First().Questions.Last().Id);
            Assert.AreEqual("22222", results.First().Pages.First().Questions.Last().Answers.First().Text);
        }
Exemplo n.º 27
0
        public void ModifyWebhookHandledProperly()
        {
            var client = new MockWebClient();

            client.Responses.Add(@"
                {""href"":""https:\/\/api.surveymonkey.net\/v3\/webhooks\/3289918"",""event_type"":""response_completed"",""subscription_url"":""http:\/\/targetsite.com\/api\/"",""object_type"":""survey"",""object_ids"":[""49143218"",""49146481""],""id"":""3289918"",""name"":""First webhook""}
            ");

            var api = new SurveyMonkeyApi("TestApiKey", "TestOAuthToken", client);

            var webhook = new Webhook
            {
                ObjectIds = new List <long> {
                    49143218, 49146481
                }
            };

            var result = api.ModifyWebhook(3289918, webhook);

            Assert.AreEqual("First webhook", result.Name);
            Assert.AreEqual(3289918, result.Id);
            Assert.AreEqual("PATCH", client.Requests.First().Verb);
            StringAssert.DoesNotContain("\"id\"", client.Requests.First().Body);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SurveyMonkeyService" /> class.
 /// </summary>
 /// <param name="surveyMonkeyKey">The survey monkey key.</param>
 /// <param name="surveyMonkeyToken">The survey monkey token.</param>
 public SurveyMonkeyService(string surveyMonkeyKey, string surveyMonkeyToken)
 {
     this.api = new SurveyMonkeyApi(surveyMonkeyKey, surveyMonkeyToken);
 }