예제 #1
0
        /// <summary>
        /// Returns the query string for the initial auth connection
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        protected string GetAuthQueryString(RideWithGPSConnectionInfo connection)
        {
            var query = HttpUtility.ParseQueryString(string.Empty);

            query["email"]    = connection.Email;
            query["password"] = connection.Password.ConvertToString();
            query["apikey"]   = connection.ApiKey;
            query["version"]  = connection.Version;

            return(query.ToString());
        }
예제 #2
0
        /// <summary>
        /// Creates a new RideWithGPSClient object from the RideWithGPSConnectionInfo details
        /// </summary>
        /// <param name="connection">The connection details (api key, credentials, etc)</param>
        /// <returns></returns>
        public static async Task <RideWithGPSClient> Connect(RideWithGPSConnectionInfo connection)
        {
            var httpClient = new HttpClient();
            var client     = new RideWithGPSClient(httpClient, connection);

            var url = $"{connection.BaseUrl}/users/current.json?{client.GetAuthQueryString(connection)}";

            var result = await httpClient.GetAsync(url);

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

            var json = JsonSerializer.Deserialize <AuthenticatedUserResponse>(response);

            client.AuthToken = json.user.auth_token;

            return(client);
        }
예제 #3
0
        protected RideWithGPSClient(HttpClient client, RideWithGPSConnectionInfo connectionInfo)
        {
            this.Client = client;

            this.ConnectionInfo = connectionInfo;
        }