Ejemplo n.º 1
0
        public async Task<Address> ReverseGeoCode(CancellationToken ct, User user, Coordinate location)
        {
            string parameters = "?latitude=" + location.Latitude.ToString(CultureInfo.InvariantCulture);
            parameters += "&longitude=" + location.Longitude.ToString(CultureInfo.InvariantCulture);

            string url = baseUri.ToString() + version1 + "/locations/" + parameters;

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV1 != Guid.Empty) ? overideTokenV1 : user.Token.Value));

            if (response.Success)
            {
                // Api stopped returning an error if you are not in Cape Town. (2014/09/22)
                if (String.IsNullOrEmpty(response.Data))
                    return new Address(AppResources.UnkownAddress, AppResources.UnkownAddress, location);

                var reverseGeoCodeJsonWrapper = JsonConvert.DeserializeObject<GeoCodeJsonWrapper>(response.Data);

                if (!reverseGeoCodeJsonWrapper.Locations.Any())
                    return null;

                return new Address(reverseGeoCodeJsonWrapper.Locations.First().Address, reverseGeoCodeJsonWrapper.Locations.First().Name, location);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 2
0
 public PathResultsModel(Address location, Address destination, IEnumerable<PathOption> pathOptions, IBumbleApiService BumbleApi, User user)
 {
     this.BumbleApi = BumbleApi;
     this.user = user;
     this.Location = location;
     this.Destination = destination;
     this.PathOptions = pathOptions;
     int numResults = pathOptions.Where(x => !x.IsUber).Count();
     if (numResults > 0)
     {
         TripAVisibility = Visibility.Visible;
     }
     if (numResults > 1)
     {
         TripBVisibility = Visibility.Visible;
     }
     if (numResults > 2)
     {
         TripCVisibility = Visibility.Visible;
     }
     if (numResults > 3)
     {
         TripDVisibility = Visibility.Visible;
     }
     if (numResults > 4)
     {
         TripEVisibility = Visibility.Visible;
     }
 }
Ejemplo n.º 3
0
        public async Task<bool> RegisterEmail(CancellationToken ct, User user, Email email)
        {
            // TODO
            //string url = baseUri.ToString() + "users/emailaddress";
            await TaskEx.Delay(1000);

            return true;

            /*string url = " https://Tumblegatewaytest.Bumble.co.za/v1/" + "users/emailaddress";

            string json = "{\"token\":\"" + user.Token.ToString() + "\"";
            json += ",\"emailaddress\":\"" + email.EmailAddress + "\"";
            json += "}";

            RestResponse response = await RestService.Post(ct, url, json);

            if (response.Success)
            {
                var result = JsonConvert.DeserializeObject<RegisterResult>(response.Data);

                return true;
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return false;
            }
            else
            {
                throw new Exception(response.Data);
            }*/
        }
Ejemplo n.º 4
0
        public async Task<User> RegisterFacebook(CancellationToken ct, User user)
        {
            // TODO
            string url = baseUri.ToString() + "users";
            /*await TaskEx.Delay(1000);

             user.IsBumbleRegistered = true;
            user.IsFacebookRegistered = true;

            return user;*/

            //string url = " https://Tumblegatewaytest.Bumble.co.za/v1/" + "users/emailaddress";

            string json = "{\"token\":\"" + user.Token.ToString() + "\"";
            json += ",\"facebookId\":\"" + user.FacebookInfo.FacebookId + "\"";
            json += "}";

            RestResponse response = await RestService.Patch(ct, url, json, Guid.Empty, user.Token.Value);

            if (response.Success)
            {
                var result = JsonConvert.DeserializeObject<RegisterResult>(response.Data);

                user.IsBumbleRegistered = true;
                user.IsFacebookRegistered = true;

                return user;
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return user;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 5
0
        public async Task<IEnumerable<PublicTransportOperator>> Operators(CancellationToken ct, User user)
        {
            string url = baseUri.ToString() + version1 + "/operators/";

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV1 != Guid.Empty) ? overideTokenV1 : user.Token.Value));

            if (response.Success)
            {
                var getOperatorsJsonWrapper = JsonConvert.DeserializeObject<GetOperatorsJsonWrapper>(response.Data);

                return ResultBuilder.BuildOperatorsResult(getOperatorsJsonWrapper.Operators);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 6
0
        public async Task<User> Authorise(CancellationToken ct, User user, Email email, Pin onetimePin)
        {
            await TaskEx.Delay(1000);

            user.IsBumbleRegistered = true;

            return user;

            /*string url = baseUri.ToString() + "authentication/login";

            string json = "{\"appkey\":\"" + appKey.ToString() + "\",\"pin\":\"" + onetimePin.PinNumber + "\",\"emailaddress\":\"" + email.EmailAddress + "\"}";

            RestResponse response = await RestService.Post(url, json);

            if (response.Success)
            {
                return JsonConvert.DeserializeObject<IdentifyResult>(response.Data);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }*/
        }
Ejemplo n.º 7
0
        public async Task<IEnumerable<Announcement>> Announcements(CancellationToken ct, User user, List<string> excludedModes, List<string> excludedOperators, DateTime? afterDate = null)
        {
            string url = baseUri.ToString() + version1 + "/announcements/";

            // Add guid to prevent caching of results.
            url += "?cache=" + Guid.NewGuid().ToString();

            if (excludedModes != null && excludedModes.Count() > 0)
            {
                foreach (string mode in excludedModes)
                    url += "&excludedmodes[]=" + mode;
            }

            if (excludedOperators != null && excludedOperators.Count() > 0)
            {
                foreach (string excludedOperator in excludedOperators)
                    url += "&excludedoperators[]=" + excludedOperator;
            }

            if (afterDate != null)
            {
                url += "&afterdate=" + afterDate.Value.ToString("o");
            }

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV2 != Guid.Empty) ? overideTokenV2 : user.Token.Value));

            if (response.Success)
            {
                var announcementJsonWrapper = JsonConvert.DeserializeObject<AnnouncementJsonWrapper>(response.Data);

                IEnumerable<Announcement> announcements = ResultBuilder.BuildAnnouncementsResult(announcementJsonWrapper.Announcements);

                return announcements.Where(x => !excludedModes.Intersect(x.Modes).Any() && !excludedOperators.Contains(x.OperatorName)).OrderByDescending(x => x.StartDate);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 8
0
        public async Task<Trip> Trip(CancellationToken ct, User user, Guid tripId)
        {
            string parameters = "?tripId=" + tripId.ToString();

            string url = baseUri.ToString() + version1 + "/trips/" + parameters;

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, user.Token.Value);

            if (response.Success)
            {
                var tripJsonWrapper = JsonConvert.DeserializeObject<TripJsonWrapper>(response.Data);

                return ResultBuilder.BuildTripResult(tripId, tripJsonWrapper);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 9
0
        public async Task<IEnumerable<PathOption>> Path(CancellationToken ct, User user, Coordinate startLocation, Coordinate endLocation, bool isDeparting, DateTime? date, int? timeOffset, List<string> excludedModes, List<string> excludedOperators)
        {
            string parameters = "?startlatitude=" + startLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&startlongitude=" + startLocation.Longitude.ToString(CultureInfo.InvariantCulture);
            parameters += "&endlatitude=" + endLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&endlongitude=" + endLocation.Longitude.ToString(CultureInfo.InvariantCulture);

            if (isDeparting)
            {
                if (date != null)
                    parameters += "&startdate=" + date.Value.ToString("o");
                else if (timeOffset != null)
                    parameters += "&startdate=" + DateTime.UtcNow.AddMinutes(timeOffset.Value).ToString("o");
            }
            else
            {
                if (date != null)
                    parameters += "&enddate=" + date.Value.ToString("o");
                else if (timeOffset != null)
                    parameters += "&enddate=" + DateTime.UtcNow.AddMinutes(timeOffset.Value).ToString("o");
            }

            if (excludedModes != null && excludedModes.Count() > 0)
            {
                foreach (string mode in excludedModes)
                    parameters += "&excludedmodes[]=" + mode;
            }

            if (excludedOperators != null && excludedOperators.Count() > 0)
            {
                foreach (string excludedOperator in excludedOperators)
                    parameters += "&excludedoperators[]=" + excludedOperator;
            }

            string url = baseUri.ToString() + version1 + "/paths/" + parameters;

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV2 != Guid.Empty) ? overideTokenV2 : user.Token.Value));

            if (response.Success)
            {
#if DEBUG
                Debug.WriteLine(response.Data);
#endif

                var getPathJsonWrapper = JsonConvert.DeserializeObject<GetPathResult>(response.Data);

                return ResultBuilder.BuildPathResult(getPathJsonWrapper.Results, unitOfWork.PublicTransportOperatorRepository.GetAll());
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 10
0
        public async Task<IEnumerable<Entities.PlaceOfInterest>> PlacesOfInterest(CancellationToken ct, User user, string searchText, string[] categories)
        {
            string parameters = String.Empty;
            if (!String.IsNullOrEmpty(searchText))
                parameters = "?searchtext=" + HttpUtility.UrlEncode(searchText);
            else if (categories != null && categories.Length > 0)
            {
                parameters = "?categories=" + string.Join(",", categories);
            }

            if (user.LastKnownGeneralLocation.IsValid())
                parameters += "&latitude=" + user.LastKnownGeneralLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&longitude=" + user.LastKnownGeneralLocation.Longitude.ToString(CultureInfo.InvariantCulture);

            string url = baseUri.ToString() + version1 + "/locations/" + parameters;

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV1 != Guid.Empty) ? overideTokenV1 : user.Token.Value));

            if (response.Success)
            {
                var pointOfInterestJsonWrapper = JsonConvert.DeserializeObject<PointOfInterestJsonWrapper>(response.Data);

                return ResultBuilder.BuildPlacesOfInterestResult(unitOfWork.PlaceOfInterestCategoryRepository.GetAll().ToList(), pointOfInterestJsonWrapper.Locations);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 11
0
        public async Task<IEnumerable<SearchItem>> Search(CancellationToken ct, User user, string searchText, Coordinate userLocation)
        {
            string parameters = "?searchText=" + HttpUtility.UrlEncode(searchText);

            if (userLocation != null)
            {
                parameters += "&latitude=" + userLocation.Latitude.ToString(CultureInfo.InvariantCulture);
                parameters += "&longitude=" + userLocation.Longitude.ToString(CultureInfo.InvariantCulture);
            }

            string url = baseUri.ToString() + version1 + "/searchitems/" + parameters;

            RestResponse response = await RestService.Get(ct, url, Guid.Empty, ((overideTokenV1 != Guid.Empty) ? overideTokenV1 : user.Token.Value));

            if (response.Success)
            {
                var searchItemsJsonWrapper = JsonConvert.DeserializeObject<SearchItemsJsonWrapper>(response.Data);

                return ResultBuilder.BuildSearchItemsResult(searchItemsJsonWrapper.SearchItems);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates and seeds the local database with default settings.
        /// (DEBUG) : In debug mode the Db is always re-created.
        /// (RELEASE) : In reelase, the Db is not dropped.
        /// </summary>
        /// <param name="unitOfWork"></param>
        public static bool Seed(IUnitOfWork unitOfWork, bool repopulate = false)
        {
            if (unitOfWork == null)
                throw new ArgumentNullException("unitOfWork");

            bool isCreated = false;
            User user = null;

            //#if DEBUG
            if (repopulate)
            {
                unitOfWork.ClearCachedItems();
                unitOfWork.Save();
            }
            //#else
                isCreated = unitOfWork.CreateDatabase();
            //#endif

            if (!isCreated)
            {
                try
                {
                    CacheSetting database = unitOfWork.CacheSettingRepository.GetByType(ResourceType.Database);

                    if (database == null || database.LastRefreshedDateUtc < lastDatabaseUpdate)
                    {
                        if (database != null)
                        {
                            // Save the user's details to be re-added to the database.
                            user = unitOfWork.UserRepository.GetUser();
                        }

                        isCreated = unitOfWork.DropAndCreateDatabase();

                        unitOfWork.Save();
                    }
                }
                catch (Exception)
                {
                    isCreated = unitOfWork.DropAndCreateDatabase();

                    unitOfWork.Save();
                }
            }

            if (isCreated || repopulate)
            {
                // Prepopulate the cache settings.
                unitOfWork.CacheSettingRepository.Insert(new CacheSetting(null, ResourceType.Operators));
                unitOfWork.CacheSettingRepository.Insert(new CacheSetting(lastDatabaseUpdate, ResourceType.Database));

                // Prepopulate the application settings.
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AllowLocation, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.UseMetric, new RegionInfo(CultureInfo.CurrentCulture.Name).IsMetric));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowWeather, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.StoreLocation, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.UseUber, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateLocation, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateMostFrequent, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateMostRecent, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.StoreRecent, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.SkipTripSelection, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowAnnouncementsApplicationBar, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowTripApplicationBar, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.LoginUber, false));

                // Prepopulate the modes.
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Bus, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Rail, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Taxi, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Boat, true));

                // Save cache setting to the database.
                unitOfWork.Save();

                if (user != null)
                {
                    // Re-populate the user
                    user = new User(Guid.NewGuid(), user.Token, user.Country, user.DismissedLocationPopup, user.LastKnownGeneralLocation, user.LastLocationUpdate, user.DismissedRateAppPopup, user.DismissedSignUpPopup, user.IsBumbleRegistered, user.Email, user.FirstName, user.LastName, user.IsFacebookRegistered, user.IsTwitterRegistered, user.FacebookInfo, user.TwitterInfo, user.TwitterHandle, user.AppUsageCount, user.DismissedLoginUberPopup, user.UberInfo, user.IsUberAuthenticated);
                    unitOfWork.UserRepository.Insert(user);
                    unitOfWork.Save();
                }
            }

            return isCreated;
        }
Ejemplo n.º 13
0
        public async Task<ContactResult> Contact(CancellationToken ct, User user, Email from, string subject, string message)
        {
            string url = baseUri.ToString() + "users/" + user.Token.Value.ToString() + "/messages";

            string json = "{\"message\":" + JsonConvert.ToString(subject + "\n\n" + message) + "}";

            RestResponse response = await RestService.Post(ct, url, json, Guid.Empty, user.Token.Value);

            if (response.Success)
            {
                return JsonConvert.DeserializeObject<ContactResult>(response.Data);
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return null;
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 14
0
        public SearchBoxModel(IUnitOfWork unitOfWork, IInMemoryApplicationSettingModel inMemoryApplicationSettingModel, WhereToViewModel whereToViewModel, SearchType searchType, IBumbleApiService BumbleApiService, User user, INavigationService navigationService)
        {
            this.Type = searchType;
            this.TripOptions = new TripOptionModel();
            this.BumbleApiService = BumbleApiService;
            this.navigationService = navigationService;
            this.user = user;
            this.whereToViewModel = whereToViewModel;
            this.unitOfWork = unitOfWork;
            this.inMemoryApplicationSettingModel = inMemoryApplicationSettingModel;

            switch (searchType)
            {
                case SearchType.Location:
                    this.TextLocation = AppResources.WhereToLocationTextBoxWaterMark;
                    break;
                case SearchType.Destination:
                    this.TextDestination = AppResources.WhereToDestinationTextBoxWaterMark;
                    break;
            }
        }
Ejemplo n.º 15
0
 public void UpdateUser(User user)
 {
     this.user = user;
 }
Ejemplo n.º 16
0
 protected virtual void PageUnloaded()
 {
     this.user = null;
 }
Ejemplo n.º 17
0
 protected virtual void PageLoaded()
 {
     this.user = UnitOfWork.UserRepository.GetUser();
 }