async public static Task <TwitterResponse> GetTwitterAccount(Account account)
        {
            string credentials_url = "https://api.twitter.com/1.1/account/verify_credentials.json";
            var    request         = new OAuth1Request("GET", new Uri(credentials_url), null, account);

            TwitterResponse twitterResponse = null;

            await request.GetResponseAsync().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    System.Diagnostics.Debug.WriteLine("Error: " + t.Exception.InnerException.Message);
                    return;
                }

                var res       = t.Result;
                var resString = res.GetResponseText();

                twitterResponse = JsonConvert.DeserializeObject <TwitterResponse>(resString);

                var outlet    = new Outlet();
                outlet.Handle = twitterResponse.screen_name;
                outlet.Type   = Outlet.outlet_type_twitter;
                outlet.Name   = twitterResponse.screen_name;

                RealmServices.SaveOutlet(outlet);
            });

            return(twitterResponse);
        }
Exemple #2
0
        public static void DeleteOutlet(Outlet outlet)
        {
            if (outlet == null)
            {
                return;
            }
            if (outlet.Type.Equals(Outlet.outlet_type_facebook, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var realm = RealmManager.SharedInstance.GetRealm(null);
            var cards = RealmServices.GetMyCards(false);

            realm.Write(() =>
            {
                outlet.Deleted = true;

                //delete any card that has no outlets
                foreach (var card in cards)
                {
                    if (card.Outlets.Where(c => c.Deleted == false).Count() == 0)
                    {
                        card.Deleted = true;
                    }
                }
            });
        }
Exemple #3
0
        public void NextPage()
        {
            var realm = RealmManager.SharedInstance.GetRealm(null);
            var me = RealmUserServices.GetMe(true);

            if (!String.IsNullOrEmpty(FacebookFirstName) || !String.IsNullOrEmpty(FacebookLastName))
            {
                realm.Write(() =>
                {
                    if (!String.IsNullOrEmpty(FacebookUserId))
                        me.FacebookID = FacebookUserId;

                    if (!String.IsNullOrEmpty(FacebookFirstName))
                        me.FirstName = FacebookFirstName;

                    if (!String.IsNullOrEmpty(FacebookLastName))
                        me.LastName = FacebookLastName;
                });
            }

            var outlet = new Outlet();
            outlet.Name = FacebookFullName;
            outlet.Handle = FacebookUserId;
            outlet.Locked = true;
            outlet.Type = Outlet.outlet_type_facebook;
            RealmServices.SaveOutlet(outlet);
        }
Exemple #4
0
        public List <Card> GetMyCards(bool forceToFront)
        {
            var cards = RealmServices.GetMyCards(forceToFront);

            if (CrossDeviceInfo.Current.Platform == Platform.Android)
            {
                cards.Add(null);
            }

            return(cards);
        }
        async public static Task <InstagramResponse> GetInstagramAccount(string token)
        {
            var client = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(10);

            Dictionary <string, string> Parameters = new Dictionary <string, string>();

            Parameters.Add("grant_type", "authorization_code");
            Parameters.Add("code", token);
            Parameters.Add("redirect_uri", NotSensitive.SystemUrls.instagram_redirect_url);
            Parameters.Add("client_id", NotSensitive.SlinkKeys.instagram_client_id);
            Parameters.Add("client_secret", NotSensitive.SlinkKeys.instagram_client_secret);


            var contentsTask = await client.PostAsync("https://api.instagram.com/oauth/access_token", new FormUrlEncodedContent(Parameters));


            if (contentsTask != null)
            {
                string result = contentsTask.Content.ReadAsStringAsync().Result;
                if (!String.IsNullOrEmpty(result))
                {
                    JToken jToken      = JToken.Parse(result);
                    var    accessToken = jToken["access_token"].ToString();
                    if (!String.IsNullOrEmpty(accessToken))
                    {
                        var client2 = new HttpClient();
                        client2.Timeout = TimeSpan.FromSeconds(10);
                        var contentsTask2 = await client2.GetAsync("https://api.instagram.com/v1/users/self/?access_token=" + accessToken);

                        if (contentsTask2 != null)
                        {
                            var result2 = JToken.Parse(contentsTask2.Content.ReadAsStringAsync().Result);
                            if (result2 != null)
                            {
                                var response = JsonConvert.DeserializeObject <InstagramResponse>(result2["data"].ToString());

                                var outlet = new Outlet();
                                outlet.Handle = response.username;
                                outlet.Type   = Outlet.outlet_type_instagram;
                                outlet.Name   = response.full_name;

                                RealmServices.SaveOutlet(outlet);

                                return(response);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemple #6
0
        public void AcceptCard()
        {
            var discoverModel = TableItems.FirstOrDefault();

            if (discoverModel == null)
            {
                return;
            }

            RealmServices.AcceptCard(discoverModel.Card);
            TableItems.Remove(discoverModel);
            AllItems.Add(discoverModel.Card);
        }
Exemple #7
0
        async public Task <bool> ShareChard()
        {
            try
            {
                SessionUUID = await RealmServices.BoardcastCard(SelectedCard, SessionUUID);

                Sharing = !String.IsNullOrEmpty(SessionUUID);
            }
            catch (Exception e)
            {
                Sharing = false;
                AppCenterManager.Report(e);
            }

            return(Sharing);
        }
        async void LocationReceived(Position position)
        {
            var location = new UserLocation();

            location.Latitude  = position.Latitude;  //34.0647985019681
            location.Longitude = position.Longitude; //-118.312238891951
            location.Accuracy  = position.Accuracy;

            RealmServices.SaveUserLocation(location);

            try
            {
                await WebServices.UserController.UpdateUser(location.Latitude, location.Longitude);
            }
            catch (Exception) { }
        }
        async public static Task <LinkedInResponse> GetLinkedInAccount(string token)
        {
            var client = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(10);

            Dictionary <string, string> Parameters = new Dictionary <string, string>();

            Parameters.Add("grant_type", "authorization_code");
            Parameters.Add("code", token);
            Parameters.Add("redirect_uri", "https://mobile.linkedin.com");
            Parameters.Add("client_id", NotSensitive.SlinkKeys.linkedin_client_id);
            Parameters.Add("client_secret", NotSensitive.SlinkKeys.linkedin_client_secret);


            var contentsTask = await client.PostAsync("https://www.linkedin.com/uas/oauth2/accessToken", new FormUrlEncodedContent(Parameters));


            if (contentsTask != null)
            {
                string result = contentsTask.Content.ReadAsStringAsync().Result;
                if (!String.IsNullOrEmpty(result))
                {
                    JToken jToken = JToken.Parse(result);
                    if (jToken == null || jToken["access_token"] == null)
                    {
                        return(null);
                    }

                    var accessToken = jToken["access_token"].ToString();
                    if (!String.IsNullOrEmpty(accessToken))
                    {
                        var client2 = new HttpClient();
                        client2.Timeout = TimeSpan.FromSeconds(10);
                        client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                        var contentsTask2 = await client2.GetAsync("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)?format=json");

                        if (contentsTask2 != null)
                        {
                            string result2 = contentsTask2.Content.ReadAsStringAsync().Result;
                            if (!String.IsNullOrEmpty(result2))
                            {
                                var response = JsonConvert.DeserializeObject <LinkedInResponse>(result2);

                                var handle = response.publicProfileUrl.Split('/').Last();

                                var outlet = new Outlet();
                                outlet.Handle = handle;
                                outlet.Type   = Outlet.outlet_type_linkedIn;
                                outlet.Name   = response.firstName + " " + response.lastName;

                                RealmServices.SaveOutlet(outlet);

                                return(response);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemple #10
0
        async public static Task <GithubResponse> GetGithubAccount(string token)
        {
            var client = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(10);

            Dictionary <string, string> Parameters = new Dictionary <string, string>();

            Parameters.Add("code", token);
            Parameters.Add("client_id", NotSensitive.SlinkKeys.github_client_id);
            Parameters.Add("client_secret", NotSensitive.SlinkKeys.github_client_secret);
            Parameters.Add("accept", "json");

            HttpResponseMessage contentsTask = null;

            try
            {
                contentsTask = await client.PostAsync("https://github.com/login/oauth/access_token", new FormUrlEncodedContent(Parameters));
            }
            catch (Exception e)
            {
                AppCenterManager.Report(e);
                return(null);
            }

            if (contentsTask == null)
            {
                return(null);
            }

            //access_token=01805dc46a84d7b7547f5d430629a0354fe7ddcd&scope=user%3Aemail&token_type=bearer
            string accessToken = null;
            string result      = contentsTask.Content.ReadAsStringAsync().Result;

            if (!String.IsNullOrEmpty(result))
            {
                var splitByAmpersand = result.Split('&');
                foreach (String sub in splitByAmpersand)
                {
                    if (sub.Contains("access_token"))
                    {
                        var seperatedByEquals = sub.Split('=');
                        accessToken = seperatedByEquals.Last();
                    }
                }


                if (!String.IsNullOrEmpty(accessToken))
                {
                    var client2 = new HttpClient();
                    client2.Timeout = TimeSpan.FromSeconds(10);
                    client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    client2.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
                    var contentsTask2 = await client2.GetAsync("https://api.github.com/user?access_token=" + accessToken);

                    if (contentsTask2 != null)
                    {
                        var result2 = JToken.Parse(contentsTask2.Content.ReadAsStringAsync().Result);
                        if (result2 != null)
                        {
                            var response = JsonConvert.DeserializeObject <GithubResponse>(result2.ToString());

                            var outlet = new Outlet();
                            outlet.Handle = response.id;
                            outlet.Type   = Outlet.outlet_type_github;
                            outlet.Name   = response.login;

                            RealmServices.SaveOutlet(outlet);

                            return(response);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #11
0
        async public Task GetNearbyTransactions()
        {
            if (QueryLock)
            {
                return;
            }
            QueryLock = true;

            try
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;

                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

                if (position == null)
                {
                    return;
                }

                var lat = position.Latitude;
                var lon = position.Longitude;

                var me = RealmUserServices.GetMe(false);
                if (me == null)
                {
                    return;
                }

                var id = ServiceLocator.Instance.Resolve <IPersistantStorage>().GetUserId();
                if (String.IsNullOrEmpty(id))
                {
                    return;
                }

                await WebServices.UserController.UpdateUser(lat, lon);

                await WebServices.TransactionsController.GetTranactions(AllItems);

                var cards         = RealmServices.GetUnretainedCards();
                var filteredCards = FilterCards(cards);

                System.Diagnostics.Debug.WriteLine("cards count: " + filteredCards.Count());

                foreach (var card in filteredCards)
                {
                    //don't show my own broadcasts
                    var isMine = card.Owner.FacebookID.Equals(id, StringComparison.OrdinalIgnoreCase);
                    if (isMine)
                    {
                        continue;
                    }

                    var model = new DiscoverModel();
                    model.Card = card;
                    TableItems.Add(model);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            QueryLock = false;
        }
Exemple #12
0
 public DiscoverShared()
 {
     RealmServices.DeleteAllUnretained();
 }