コード例 #1
0
        public async Task AuthenticateAndGetUserName()
        {
            using (dynamic google = new DynamicRestClient("https://www.googleapis.com/", MockInitialization.Handler, false, null,
                                                          async(request, cancelToken) =>
            {
                // this demonstrates how to use the configuration callback to handle authentication
                var auth = MockInitialization.GetAuthClient("email profile");
                var token = await auth.Authenticate("", cancelToken);
                Assert.IsNotNull(token, "auth failed");

                request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", token);
            }))
            {
                var profile = await google.oauth2.v1.userinfo.get();

                Assert.IsNotNull(profile);
                Assert.AreEqual("Kackman", profile.family_name);
            }
        }
コード例 #2
0
        [Ignore] // drive scopes don't work with device pin based oauth2 - ignore for now
        public async Task UploadFile()
        {
            var auth = MockInitialization.GetAuthClient("email profile https://www.googleapis.com/auth/devstorage.read_write");

            _token = await auth.Authenticate(_token);

            Assert.IsNotNull(_token, "auth failed");

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "OAuth",
                AuthToken  = _token
            };

            using (dynamic google = new DynamicRestClient("https://www.googleapis.com/", MockInitialization.Handler, false, defaults))
            {
                dynamic result = await google.upload.drive.v2.files.post(File.OpenRead(@"D:\temp\test.png"), uploadType : "media", title : "unit_test.jpg");

                Assert.IsNotNull(result);
            }
        }
コード例 #3
0
        public async Task UploadInt()
        {
            var auth = MockInitialization.GetAuthClient("email profile https://www.googleapis.com/auth/devstorage.read_write");

            _token = await auth.Authenticate(_token);

            Assert.IsNotNull(_token, "auth failed");

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "OAuth",
                AuthToken  = _token
            };

            using (dynamic google = new DynamicRestClient("https://www.googleapis.com/", defaults))
            {
                dynamic result = await google.upload.storage.v1.b.unit_tests.o.post(42, name : new PostUrlParam("int_object"), uploadType : new PostUrlParam("media"));

                Assert.IsNotNull(result);
            }
        }
コード例 #4
0
        public async Task UploadObject()
        {
            var auth = MockInitialization.GetAuthClient("email profile https://www.googleapis.com/auth/devstorage.read_write");

            _token = await auth.Authenticate(_token);

            Assert.IsNotNull(_token, "auth failed");

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "OAuth",
                AuthToken  = _token
            };

            using (dynamic google = new DynamicRestClient("https://www.googleapis.com/", MockInitialization.Handler, false, defaults))
                using (var stream = new StreamInfo(File.OpenRead(@"D:\temp\test.png"), "image/png"))
                {
                    dynamic result = await google.upload.storage.v1.b.unit_tests.o.post(stream, name : new PostUrlParam("test_object"), uploadType : new PostUrlParam("media"));

                    Assert.IsNotNull(result);
                }
        }
コード例 #5
0
        public async Task CreateGoogleCalendarUsingClient()
        {
            using (dynamic google = new DynamicRestClient("https://www.googleapis.com/calendar/v3/", MockInitialization.Handler, false, null,
                                                          async(request, cancelToken) =>
            {
                // this demonstrates how to use the configuration callback to handle authentication
                var auth = MockInitialization.GetAuthClient("email profile https://www.googleapis.com/auth/calendar");
                var token = await auth.Authenticate("", cancelToken);
                Assert.IsNotNull(token, "auth failed");

                request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", token);
            }))
            {
                dynamic calendar = new ExpandoObject();
                calendar.summary = "unit_testing";

                var list = await google.calendars.post(calendar);

                Assert.IsNotNull(list);
                Assert.AreEqual(list.summary, "unit_testing");
            }
        }