Example #1
0
        public async Task GetAllRides_WhenProvidingNoAuthenticationToken_ReturnsAuthenticationToken()
        {
            // Arrange
            _testMediator.SetExpectedHttpStatusCode(HttpStatusCode.OK);
            await SetupExpectedResponsesFromTestJsonFiles();

            var request = new GetARyderRequest
            {
                FromAddress = new GetARyderAddress
                {
                    City  = "TestCity",
                    State = "TestState"
                },
                ToAddress = new GetARyderAddress
                {
                    City  = "TestCity",
                    State = "TestState"
                }
            };

            // Act
            var response = _domainFacade.GetAllRides(request);

            // Assert
            Assert.IsNotNull(response);
        }
        public void Transform(GetARyderRequest request, LyftRideTypesResponse rideTypes,
                              LyftRideEstimatesResponse rideEstimates, LyftRideEtasResponse rideEtas, GetARyderResponse response)
        {
            PopulateRideTypes(rideTypes, response);
            PopulateRideEstimates(rideEstimates, response);
            PopulateRideEtas(rideEtas, response);

            response.DeepAppLink = CreateDeepAppLink("Lyft", request);
        }
Example #3
0
        private async Task MaintainOAuthToken(GetARyderRequest getARyderRequest)
        {
            if (!string.IsNullOrWhiteSpace(getARyderRequest.Credentials.AccessToken) &&
                !IsTimestampExpired(getARyderRequest.Credentials.AccessTokenExpiration))
            {
                return;
            }

            await ObtainOAuthToken(getARyderRequest);
        }
Example #4
0
        private async Task EnsureGeolocationsPopulated(GetARyderRequest getARyderRequest)
        {
            if (IsGeolocationEmpty(getARyderRequest.FromGeolocation))
            {
                await PopulateGeolocation(getARyderRequest.FromAddress, getARyderRequest.FromGeolocation);
            }

            if (IsGeolocationEmpty(getARyderRequest.ToGeolocation))
            {
                await PopulateGeolocation(getARyderRequest.ToAddress, getARyderRequest.ToGeolocation);
            }
        }
Example #5
0
        public async void Test1()
        {
            var domain = new DomainFacade();

            var request = new GetARyderRequest();
            request.FromAddress.City = "Huntington Park";
            request.FromAddress.State = "CA";
            request.FromAddress.Street = "Marconi Street";
            request.FromAddress.StreetNumber = "7035";

            request.ToAddress.City = "Huntington Park";
            request.ToAddress.State = "CA";
            request.ToAddress.Street = "Arbutus Ave";
            request.ToAddress.StreetNumber = "6022";

            var result = await domain.GetAllRides(request);
        }
Example #6
0
        public async Task GetAllRides_WhenGivenTwoLocations_ReturnAvailableRides()
        {
            var domain = new DomainFacade();

            var request = new GetARyderRequest();

            request.FromAddress.City         = "Huntington Park";
            request.FromAddress.State        = "CA";
            request.FromAddress.Street       = "Marconi Street";
            request.FromAddress.StreetNumber = "7035";

            request.ToAddress.City         = "Huntington Park";
            request.ToAddress.State        = "CA";
            request.ToAddress.Street       = "Arbutus Ave";
            request.ToAddress.StreetNumber = "6022";

            var result = await domain.GetAllRides(request);
        }
Example #7
0
        protected override async Task <GetARyderResponse> GetAllRidesCore(GetARyderRequest request)
        {
            await MaintainOAuthToken(request);

            var rideTypes = await GetResponseFromLyftApi <LyftRideTypesResponse>(GetMapquestRideTypesUrl(request), request.Credentials.AccessToken);

            var rideEstimates = await GetResponseFromLyftApi <LyftRideEstimatesResponse>(GetMapquestRideEstimatesUrl(request), request.Credentials.AccessToken);

            var rideEtas = await GetResponseFromLyftApi <LyftRideEtasResponse>(GetMapquestRideEtasUrl(request), request.Credentials.AccessToken);

            var response = new GetARyderResponse
            {
                Credentials = request.Credentials
            };

            this._lyftToGetARydertransformer.Transform(request, rideTypes, rideEstimates, rideEtas, response);
            response.FromAddress     = request.FromAddress;
            response.FromGeolocation = request.FromGeolocation;
            response.ToAddress       = request.ToAddress;
            response.ToGeolocation   = request.ToGeolocation;

            return(response);
        }
Example #8
0
        private async Task ObtainOAuthToken(GetARyderRequest getARyderRequest)
        {
            using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, _lyftGatewayConfiguration.AuthenticationUrl))
            {
                var oAuthRequest = new LyftOAuthRequest {
                    GrantType = "client_credentials", Scope = "public"
                };
                var oAuthJson          = JsonConvert.SerializeObject(oAuthRequest);
                var oAuthContent       = new StringContent(oAuthJson, Encoding.UTF8, "application/json");
                var encodedOAuthHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_lyftGatewayConfiguration.ClientId}:{_lyftGatewayConfiguration.ClientSecret}"));

                httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", encodedOAuthHeader);
                httpRequest.Content = oAuthContent;

                var httpResponse = await _httpClient.SendAsync(httpRequest);

                EnsureHttpResponseSuccess(httpResponse);
                var responseJson = await httpResponse.Content.ReadAsStringAsync();

                var oAuthResponse = JsonConvert.DeserializeObject <LyftOAuthResponse>(responseJson);
                PopulateCredentials(oAuthResponse, getARyderRequest.Credentials);
            }
        }
Example #9
0
        public async Task <GetARyderResponse> GetAllRides(GetARyderRequest getARyderRequest)
        {
            await EnsureGeolocationsPopulated(getARyderRequest);

            return(await RideSharingGateway.GetAllRides(getARyderRequest));
        }
Example #10
0
 protected abstract Task <GetARyderResponse> GetAllRidesCore(GetARyderRequest getARyderRequest);
Example #11
0
 public async Task <GetARyderResponse> GetAllRides(GetARyderRequest getARyderRequest)
 => await GetAllRidesCore(getARyderRequest);
Example #12
0
 private string GetMapquestRideTypesUrl(GetARyderRequest request)
 => $"{_lyftGatewayConfiguration.ApiUrl}ridetypes?lat={request.FromGeolocation.Latitude}&lng={request.FromGeolocation.Longitude}";
Example #13
0
 private string GetMapquestRideEtasUrl(GetARyderRequest request)
 => $"{_lyftGatewayConfiguration.ApiUrl}nearby-drivers-pickup-etas?lat={request.FromGeolocation.Latitude}&lng={request.FromGeolocation.Longitude}";
Example #14
0
 private string GetMapquestRideEstimatesUrl(GetARyderRequest request)
 => $"{_lyftGatewayConfiguration.ApiUrl}cost?start_lat={request.FromGeolocation.Latitude}&start_lng={request.FromGeolocation.Longitude}&end_lat={request.ToGeolocation.Latitude}&end_lng={request.ToGeolocation.Longitude}";
 private string CreateDeepAppLink(string rideType, GetARyderRequest request)
 => $"lyft://ridetype?id={rideType}&" +
 $"pickup[Latitude]={request.FromGeolocation.Latitude}&" +
 $"pickup[Longitude]={request.FromGeolocation.Longitude}&" +
 $"destination[Latitude]={request.ToGeolocation.Latitude}&" +
 $"destination[Longitude]={request.ToGeolocation.Longitude}";
Example #16
0
 public async Task <GetARyderResponse> GetAllRides(GetARyderRequest getARideRequest)
 => await GetARyderManager.GetAllRides(getARideRequest);