Beispiel #1
0
        async void AddItem(string contentUrl)
        {
            string          url    = host + "/v3/add";
            FakeJsonBuilder jsonSB = new FakeJsonBuilder();

            jsonSB.AppendItem("consumer_key", consumer_key);
            jsonSB.AppendItem("access_token", AccessToken);
            jsonSB.AppendItem("url", contentUrl);
            string data   = jsonSB.Output();
            string result = await HttpTool.PostStringAsync(url, data);

            var match = statusReg.Match(result);

            if (match.Success && match.Groups[1].Value == "1")
            {
                var response = Newtonsoft.Json.JsonConvert.DeserializeObject <AddResponsePackage>(result);
                var item     = response.item;
                App.localFileCache.UpdateItem(item.normal_url, item.title, item.item_id);
            }
            else
            {
                Debug.WriteLine("Error in AddItem, result = {0}", result);
            }
            IsSync = true;
        }
Beispiel #2
0
        async void ModifyItem(string item_id, string action)
        {
            //return; // TEST

            string          url    = host + "/v3/send";
            FakeJsonBuilder jsonSB = new FakeJsonBuilder();

            jsonSB.AppendItem("action", action);
            jsonSB.AppendItem("item_id", item_id);
//            string time = "";
            string content = "[" + jsonSB.Output() + "]";

            jsonSB.Clear();
            jsonSB.AppendItem("actions", content, true);
            jsonSB.AppendItem("access_token", AccessToken);
            jsonSB.AppendItem("consumer_key", consumer_key);

            string result = await HttpTool.PostStringAsync(url, jsonSB.Output());

            var match = statusReg.Match(result);

            if (!(match.Success && match.Groups[1].Value == "1"))
            {
                Debug.WriteLine("Error in ModifyItem, result = {0}", result);
            }
            IsSync = true;
        }
Beispiel #3
0
        async Task <string> GetRequestToken()
        {
            string url    = host + "/v3/oauth/request";
            string data   = "{\"consumer_key\":\"" + consumer_key + "\",\"redirect_uri\":\"" + redirect_uri + "\"}";
            string result = await HttpTool.PostStringAsync(url, data);

            var match = tokenCodeReg.Match(result);

            if (match.Success)
            {
                return(match.Groups[1].Value);
            }
            else
            {
                return("");
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取AccessToken,需要有RequestToken
        /// </summary>
        public async Task <bool> GetAccessToken()
        {
            string url    = host + "/v3/oauth/authorize";
            string data   = "{\"consumer_key\":\"" + consumer_key + "\",\"code\":\"" + RequestToken + "\"}";
            string result = await HttpTool.PostStringAsync(url, data);

            var match = accessTokenReg.Match(result);

            if (match.Success)
            {
                SetAccount(match.Groups[2].Value, match.Groups[1].Value);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        async Task <List <PocketItem> > GetPocketList(int start, int count, bool isDetail = true, bool?isRead = null, bool?isFavorite = null)
        {
            string          url    = host + "/v3/get";
            FakeJsonBuilder jsonSB = new FakeJsonBuilder();

            jsonSB.AppendItem("consumer_key", consumer_key);
            jsonSB.AppendItem("access_token", AccessToken);
            jsonSB.AppendItem("offset", start);
            jsonSB.AppendItem("count", count);
            jsonSB.AppendItem("detailType", isDetail ? "complete" : "simple");
            jsonSB.AppendItem("state", isRead == null ? "all" : (isRead == true ? "archive" : "unread"));
            if (isFavorite != null)
            {
                jsonSB.AppendItem("favorite", isFavorite == true ? "1" : "0");
            }

            string data = jsonSB.Output();
            //Stream result = await HttpTool.PostStreamAsync(url, data);
            //GetResponsePackage response = getResponsePackage_ser.ReadObject(result) as GetResponsePackage;
            //result.Close();
            string result = await HttpTool.PostStringAsync(url, data);

            GetResponsePackage response = null;
            var match = statusReg.Match(result);

            if (match.Success && match.Groups[1].Value == "1")
            {
                response = Newtonsoft.Json.JsonConvert.DeserializeObject <GetResponsePackage>(result);
            }
            else
            {
                Debug.WriteLine("Warning in GetPocketList: not recognized json string = {0}", result);
            }
            IsSync = true;
            return(response == null ? new List <PocketItem>() : response.list.Values.ToList());
        }