예제 #1
0
        /// <summary>
        ///     Gets the second amount of Jodels (internal usage)
        /// </summary>
        /// <returns>List&lt;Jodels&gt;.</returns>
        public List <Jodels> GetNextJodels(string accessToken = null)
        {
            List <Jodels> temp = new List <Jodels>();

            for (int e = 0; e < 3; e++)
            {
                string plainJson;
                using (var client = new MyWebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    plainJson       = client.DownloadString(Constants.LinkSecondJodels.ToLinkSecond(_lastPostId, accessToken));
                }
                JsonJodelsLastRound.RootObject jlr = JsonConvert.DeserializeObject <JsonJodelsLastRound.RootObject>(plainJson);
                foreach (var item in jlr.posts)
                {
                    string image_url = "";
                    bool   isUrl     = false;

                    if (item.image_url != null)
                    {
                        image_url = "http:" + item.image_url;
                        isUrl     = true;
                    }

                    Jodels objJodels = new Jodels
                    {
                        PostId                = item.post_id,
                        Message               = item.message,
                        HexColor              = item.color,
                        IsImage               = isUrl,
                        ImageUrl              = image_url,
                        VoteCount             = item.vote_count,
                        LocationName          = item.location.name,
                        CommentsCount         = item.child_count ?? 0,
                        ChildCount            = item.child_count ?? 0,
                        CreatedAt             = DateTime.ParseExact(item.created_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                        UpdatedAt             = DateTime.ParseExact(item.updated_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                        Distance              = item.distance,
                        IsNotificationEnabled = item.notifications_enabled,
                        PinCount              = item.pin_count,
                        PostOwn               = item.post_own,
                        UserHandle            = item.user_handle
                    };

                    temp.Add(objJodels);
                }
                if (temp.Count == 0)
                {
                    return(temp);                 // not enough Jodels anymore.
                }
                _lastPostId = temp.Last().PostId; // Set the last post_id for next jodels
            }
            return(temp);
        }
예제 #2
0
        /// <summary>
        ///     Gets the first amount of Jodels Async (internal usage)
        /// </summary>
        /// <returns>List&lt;Jodels&gt;.</returns>
        public async Task <List <Jodels> > GetFirstJodelsAsync()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = await client.DownloadStringTaskAsync(new Uri(Constants.LinkFirstJodels.ToLink()));
            }
            JsonJodelsFirstRound.RootObject jfr =
                JsonConvert.DeserializeObject <JsonJodelsFirstRound.RootObject>(plainJson);
            List <Jodels> temp = new List <Jodels>(); // List<post_id,message>

            foreach (var item in jfr.recent)
            {
                string image_url = "";
                bool   isUrl     = false;

                if (item.image_url != null)
                {
                    image_url = "http:" + item.image_url;
                    isUrl     = true;
                }

                Jodels objJodels = new Jodels
                {
                    PostId                = item.post_id,
                    Message               = item.message,
                    HexColor              = item.color,
                    IsImage               = isUrl,
                    ImageUrl              = image_url,
                    VoteCount             = item.vote_count,
                    LocationName          = item.location.name,
                    CommentsCount         = item.child_count ?? 0,
                    ChildCount            = item.child_count ?? 0,
                    CreatedAt             = DateTime.ParseExact(item.created_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                    UpdatedAt             = DateTime.ParseExact(item.updated_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                    Distance              = item.distance,
                    IsNotificationEnabled = item.notifications_enabled,
                    PinCount              = item.pin_count,
                    PostOwn               = item.post_own,
                    UserHandle            = item.user_handle
                };

                temp.Add(objJodels);
            }

            lock (_lastPostId)
            {
                _lastPostId = temp.Last().PostId; // Set the last post_id for next jodels
            }

            return(temp);
        }