Example #1
0
        private async Task Authorize()
        {
            dynamic keys = await GetAppCredentials("Facebook");
            string clientId = keys.client_id;

            IDeviceOAuth2Stepwise auth = new DeviceOAuth(EndPointInfo.Facebook, "public_profile", clientId);
            var info = await auth.StartAuthorization();
            
            var msg = $"Navigate to {info.VerificationUri} \nEnter this code: {info.UserCode}";
            Notify.Text = msg;

            var token = await auth.WaitForUserConsent(info);

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "Bearer",
                AuthToken = token.AccessToken
            };

            dynamic client = new DynamicRestClient("https://graph.facebook.com/v2.3/me", defaults);

            dynamic v = await client.get(fields: "name");
            Notify.Text = "";
            UserName.Text = v.name;
        }
Example #2
0
        private async Task Authorize()
        {
            dynamic keys = await GetAppCredentials("Facebook");

            string clientId = keys.client_id;

            IDeviceOAuth2Stepwise auth = new DeviceOAuth(EndPointInfo.Facebook, "public_profile", clientId);
            var info = await auth.StartAuthorization();

            var msg = $"Navigate to {info.VerificationUri} \nEnter this code: {info.UserCode}";

            Notify.Text = msg;

            var token = await auth.WaitForUserConsent(info);

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "Bearer",
                AuthToken  = token.AccessToken
            };

            dynamic client = new DynamicRestClient("https://graph.facebook.com/v2.3/me", defaults);

            dynamic v = await client.get(fields : "name");

            Notify.Text   = "";
            UserName.Text = v.name;
        }
        public async Task DeserializeToString()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
            {
                string content = await google.get(typeof(string));

                Assert.IsFalse(string.IsNullOrEmpty(content));
                Assert.IsTrue(content.StartsWith("<!doctype html>"));
            }
        }
        public async Task DeserializeToString()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
            {
                string content = await google.get(typeof(string));

                Assert.IsFalse(string.IsNullOrEmpty(content));
                Assert.IsTrue(content.StartsWith("<!doctype html>"));
            }
        }
        public async Task DownloadJsonFile()
        {
            using (dynamic client = new DynamicRestClient("https://storage.googleapis.com/pictureframe/settings.json"))
            {
                var result = await client.get();

                Assert.IsNotNull(result);
                Assert.AreEqual(10000, result.settingCheckInterval);
            }
        }
        public async Task DeserializeToByteArray()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
            {
                byte[] content = await google.get(typeof(byte[]));

                Assert.IsNotNull(content);
                Assert.IsTrue(content.Length > 0);

                var s = Encoding.UTF8.GetString(content);
                Assert.IsFalse(string.IsNullOrEmpty(s));
                Assert.IsTrue(s.StartsWith("<!doctype html>"));
            }
        }
        public async Task DeserializeToByteArray()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
            {
                byte[] content = await google.get(typeof(byte[]));

                Assert.IsNotNull(content);
                Assert.IsTrue(content.Length > 0);

                var s = Encoding.UTF8.GetString(content);
                Assert.IsFalse(string.IsNullOrEmpty(s));
                Assert.IsTrue(s.StartsWith("<!doctype html>"));
            }
        }
 public async Task ReturnResponseStream()
 {
     using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
         using (Stream responseStream = await google.get(typeof(Stream)))
         {
             Assert.IsNotNull(responseStream);
             using (var reader = new StreamReader(responseStream))
             {
                 var content = reader.ReadToEnd();
                 Assert.IsNotNull(content);
                 Assert.IsTrue(content.StartsWith("<!doctype html>"));
             }
         }
 }
Example #9
0
        public async Task FindUserByName()
        {
            var key = CredentialStore.RetrieveObject("flickr.key.json");
            var defaults = new DynamicRestClientDefaults();
            defaults.DefaultParameters.Add("format", "json");
            defaults.DefaultParameters.Add("api_key", key.Key);
            defaults.DefaultParameters.Add("nojsoncallback", "1");

            using (dynamic client = new DynamicRestClient("https://api.flickr.com/services/rest/", MockInitialization.Handler, false, defaults))
            {
                dynamic result = await client.get(method: "flickr.people.findByUsername", username: "******");
                Assert.IsNotNull(result);
                Assert.AreEqual("9039518@N03", result.user.id);
            }
        }
Example #10
0
        public async Task FindUserByName()
        {
            var key      = CredentialStore.RetrieveObject("flickr.key.json");
            var defaults = new DynamicRestClientDefaults();

            defaults.DefaultParameters.Add("format", "json");
            defaults.DefaultParameters.Add("api_key", key.Key);
            defaults.DefaultParameters.Add("nojsoncallback", "1");

            dynamic client = new DynamicRestClient("https://api.flickr.com/services/rest/", defaults);

            dynamic result = await client.get(method : "flickr.people.findByUsername", username : "******");

            Assert.IsNotNull(result);
            Assert.AreEqual("9039518@N03", (string)result.user.id);
        }
        public async Task ReturnHttpResponseMessage()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
                using (HttpResponseMessage response = await google.get(typeof(HttpResponseMessage)))
                {
                    Assert.IsNotNull(response);
                    // this makes it possible to inspect the response for more information than just the content
                    Assert.AreEqual("OK", response.ReasonPhrase);

                    // when asking for the complete response object the client does not check status
                    Assert.IsTrue(response.IsSuccessStatusCode);

                    var content = await response.Content.ReadAsStringAsync();

                    Assert.IsNotNull(content);
                    Assert.IsTrue(content.StartsWith("<!doctype html>"));
                }
        }
Example #12
0
        /// <summary>
        /// Returns the user's endpoint profile using <see cref="EndPointInfo.ProfileUri"/>.
        /// </summary>
        /// <param name="token">The auth token</param>
        /// <param name="cancelToken">A cancellation token</param>
        /// <returns>User's profile</returns>
        /// <exception cref="DynamicRestClientResponseException">When there is an http failure</exception>
        public async Task <dynamic> GetProfile(TokenInfo token, CancellationToken cancelToken)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = EndPoint.Scheme,
                AuthToken  = token.AccessToken
            };

            using (dynamic profileEndpoint = new DynamicRestClient(_endPoint.ProfileUri, defaults))
            {
                return(await profileEndpoint.get(cancelToken));
            }
        }
 public async Task ReturnResponseStream()
 {
     using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
     using (Stream responseStream = await google.get(typeof(Stream)))
     {
         Assert.IsNotNull(responseStream);
         using (var reader = new StreamReader(responseStream))
         {
             var content = reader.ReadToEnd();
             Assert.IsNotNull(content);
             Assert.IsTrue(content.StartsWith("<!doctype html>"));
         }
     }
 }
        public async Task ReturnHttpResponseMessage()
        {
            using (dynamic google = new DynamicRestClient("https://www.google.com/", MockInitialization.Handler))
            using (HttpResponseMessage response = await google.get(typeof(HttpResponseMessage)))
            {
                Assert.IsNotNull(response);
                // this makes it possible to inspect the response for more information than just the content
                Assert.AreEqual("OK", response.ReasonPhrase);

                // when asking for the complete response object the client does not check status
                Assert.IsTrue(response.IsSuccessStatusCode);

                var content = await response.Content.ReadAsStringAsync();

                Assert.IsNotNull(content);
                Assert.IsTrue(content.StartsWith("<!doctype html>"));
            }
        }
Example #15
0
        /// <summary>
        /// Returns the user's endpoint profile using <see cref="EndPointInfo.ProfileUri"/>
        /// </summary>
        /// <param name="token">The token</param>
        /// <param name="cancelToken">A cancellation token</param>
        /// <returns>User's profile</returns>
        public async Task<dynamic> GetProfile(TokenInfo token, CancellationToken cancelToken)
        {
            if (token == null) throw new ArgumentNullException("token");

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = EndPoint.Scheme,
                AuthToken = token.AccessToken
            };

            using (dynamic profileEndpoint = new DynamicRestClient(_endPoint.ProfileUri, defaults))
            {
                return await profileEndpoint.get(cancelToken);
            }
        }