Пример #1
0
        public async Task <ExpandoObject> GetActivityMeasures(DateTime lastUpdate, string userId, string token, string secret)
        {
            var query = BaseUri.AppendPathSegment("measure")
                        .SetQueryParam("action", "getactivity")
                        .SetQueryParam("userid", userId)
                        .SetQueryParam("date", $"{lastUpdate:yyyy-MM-dd}");
            var    oAuth     = new OAuthBase();
            string nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            string timeStamp = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string parameters;
            string signature = oAuth.GenerateSignature(new Uri(query), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            query.SetQueryParam("oauth_consumer_key", _credentials.ConsumerKey);
            query.SetQueryParam("oauth_nonce", nonce);
            query.SetQueryParam("oauth_signature", signature);
            query.SetQueryParam("oauth_signature_method", "HMAC-SHA1");
            query.SetQueryParam("oauth_timestamp", timeStamp);
            query.SetQueryParam("oauth_token", token);
            query.SetQueryParam("oauth_version", "1.0");

            return(await query.GetJsonAsync().ConfigureAwait(false));
        }
Пример #2
0
        public async Task <ExpandoObject> GetSleepSummary(string startday, string endday, string token, string secret)
        {
            var query = BaseUri.AppendPathSegment("sleep")
                        .SetQueryParam("action", "getsummary")
                        .SetQueryParam("startdateymd", startday)
                        .SetQueryParam("enddateymd", endday);
            var    oAuth     = new OAuthBase();
            string nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            string timeStamp = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string parameters;
            string signature = oAuth.GenerateSignature(new Uri(query), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            query.SetQueryParam("oauth_consumer_key", _credentials.ConsumerKey);
            query.SetQueryParam("oauth_nonce", nonce);
            query.SetQueryParam("oauth_signature", signature);
            query.SetQueryParam("oauth_signature_method", "HMAC-SHA1");
            query.SetQueryParam("oauth_timestamp", timeStamp);
            query.SetQueryParam("oauth_token", token);
            query.SetQueryParam("oauth_version", "1.0");

            return(await query.GetJsonAsync().ConfigureAwait(false));
        }
Пример #3
0
        public async Task <ExpandoObject> GetBodyMeasures(string userid, DateTime start, DateTime end, string token, string secret)
        {
            var query = "https://wbsapi.withings.net".AppendPathSegment("measure")
                        .SetQueryParam("action", "getmeas")
                        .SetQueryParam("userid", userid)
                        .SetQueryParam("startdate", start.ToUnixTime())
                        .SetQueryParam("enddate", end.ToUnixTime());
            var    oAuth     = new OAuthBase();
            var    nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            var    timeStamp = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string parameters;
            var    signature = oAuth.GenerateSignature(new Uri(query), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            query.SetQueryParam("oauth_consumer_key", _credentials.ConsumerKey);
            query.SetQueryParam("oauth_nonce", nonce);
            query.SetQueryParam("oauth_signature", signature);
            query.SetQueryParam("oauth_signature_method", "HMAC-SHA1");
            query.SetQueryParam("oauth_timestamp", timeStamp);
            query.SetQueryParam("oauth_token", token);
            query.SetQueryParam("oauth_version", "1.0");

            return(await query.GetJsonAsync().ConfigureAwait(false));
        }
        public WithingsWeighInResponse GetActivityMeasures(DateTime lastUpdate, string userId, string token, string secret)
        {
            var oAuth   = new OAuthBase();
            var request = new RestRequest("measure", Method.GET);
            var uri     = $"{BaseUri}/measure?action=getactivity&userid={userId}&date={lastUpdate:yyyy-MM-dd}";

            var    nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            var    timeStamp = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string parameters;
            var    signature = oAuth.GenerateSignature(new Uri(uri), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            request
            .AddQueryParameter("action", "getactivity")
            .AddQueryParameter("userid", userId)
            .AddQueryParameter("date", lastUpdate.ToString("yyyy-MM-dd"));
            AddOAuthParameters(request, nonce, timeStamp, signature, token);


            IRestResponse <WithingsWeighInResponse> response = Client.Execute <WithingsWeighInResponse>(request);

            return(response.Data);
        }
        public string GetIntraDayActivity(string userId, DateTime start, DateTime end, string token, string secret)
        {
            var    oAuth     = new OAuthBase();
            var    request   = new RestRequest("measure", Method.GET);
            var    nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            var    timeStamp = oAuth.GenerateTimeStamp();
            var    uri       = $"{BaseUri}/v2/measure?action=getintradayactivity&userid={userId}&startdate={start.ToUnixTime()}&enddate={end.ToUnixTime()}";
            string normalizedUrl;
            string parameters;
            var    signature = oAuth.GenerateSignature(new Uri(uri), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            signature = HttpUtility.UrlEncode(signature);

            request
            .AddQueryParameter("action", "getintradayactivity")
            .AddQueryParameter("userid", userId)
            .AddQueryParameter("startdate", start.ToUnixTime().ToString())
            .AddQueryParameter("enddate", end.ToUnixTime().ToString());
            AddOAuthParameters(request, nonce, timeStamp, signature, token);

            var response = Client.Execute(request);

            return(response.Content);
        }
        public WithingsBody GetBodyMeasures(string userid, DateTime lastupdate, string token, string secret)
        {
            var    oAuth     = new OAuthBase();
            var    nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            var    timeStamp = oAuth.GenerateTimeStamp();
            var    uri       = $"https://wbsapi.withings.net/measure?action=getmeas&userid=29&lastupdate={lastupdate.ToUnixTime()}";
            string normalizedUrl;
            string parameters;
            var    signature = oAuth.GenerateSignature(new Uri(uri), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);
            var request = new RestRequest("measure", Method.GET);

            request
            .AddQueryParameter("action", "getactivity")
            .AddQueryParameter("userid", userid)
            .AddQueryParameter("lastupdate", lastupdate.ToUnixTime().ToString());
            AddOAuthParameters(request, nonce, timeStamp, signature, token);

            IRestResponse <WithingsBody> response = Client.Execute <WithingsBody>(request);

            return(response.Data);
        }
        public string GetSleepSummary(string startday, string endday, string token, string secret)
        {
            var oAuth = new OAuthBase();

            var    nonce     = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
            var    timeStamp = oAuth.GenerateTimeStamp();
            var    uri       = $"{BaseUri}/sleep?action=getsummary&startdateymd={startday}&enddateymd={endday}";
            string normalizedUrl;
            string parameters;
            var    signature = oAuth.GenerateSignature(new Uri(uri), _credentials.ConsumerKey, _credentials.ConsumerSecret,
                                                       token, secret, "GET", timeStamp, nonce,
                                                       OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out parameters);

            signature = HttpUtility.UrlEncode(signature);

            var requestUri = new StringBuilder(uri);

            requestUri.AppendFormat("&oauth_consumer_key={0}&", _credentials.ConsumerKey);
            requestUri.AppendFormat("oauth_nonce={0}&", nonce);
            requestUri.AppendFormat("oauth_signature={0}&", signature);
            requestUri.AppendFormat("oauth_signature_method={0}&", "HMAC-SHA1");
            requestUri.AppendFormat("oauth_timestamp={0}&", timeStamp);
            requestUri.AppendFormat("oauth_token={0}&", token);
            requestUri.AppendFormat("oauth_version={0}", "1.0");

            var          wrGeturl  = WebRequest.Create(requestUri.ToString());
            var          objStream = wrGeturl.GetResponse().GetResponseStream();
            const string sLine     = "";

            if (objStream == null)
            {
                return(sLine);
            }
            var objReader = new StreamReader(objStream);

            return(objReader.ReadLine());
        }