Beispiel #1
0
        public static MFPWeightData ImportFromFile(string fileName)
        {
            MFPWeightData weightData = new MFPWeightData();

            weightData.WeightEntries.Add(new MFPWeightEntry(DateTime.Now.AddDays(2), 175.5));

            return(weightData);
        }
Beispiel #2
0
        public void Export(MFPWeightData weightData)
        {
            //DoAuthStuff();

            string token        = "b70eba355e344b36957749d70f4dc7f8";
            string token_secret = "718b836cb6f446349de85d031cbb3572";

            RestClient updateWeightClient = new RestClient(SERVER_API_URL);

            RestRequest request = new RestRequest(string.Empty, Method.POST);

            string nonce     = string.Empty;
            string timestamp = string.Empty;

            timestamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
            nonce     = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(timestamp + timestamp + timestamp));

            request.AddParameter("oauth_consumer_key", REST_API_CONSUMER_KEY);
            request.AddParameter("oauth_signature_method", "HMAC-SHA1");
            request.AddParameter("oauth_timestamp", timestamp);
            request.AddParameter("oauth_nonce", nonce);
            request.AddParameter("oauth_version", "1.0");
            request.AddParameter("method", "weight.update");
            request.AddParameter("oauth_token", token);
            request.AddParameter("current_weight_kg", 100.0);

            request.AddParameter("format", "json");
            request.AddParameter("date", TransformDate(DateTime.Now.AddMonths(-1)));
            request.AddParameter("weight_type", "lb");
            //request.AddParameter("comment", "imported through API from MFP"); //this causes an issue with signature, I think spaces are being encoded incorrectlywalle

            request = SignRequest(request, updateWeightClient.BaseUrl.ToString(), token_secret);

            IRestResponse <RequestTokenResponse> response = updateWeightClient.Execute <RequestTokenResponse>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
            }
        }