Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
            /// <summary>
            ///     Get's all Jodels from this channel.
            /// </summary>
            /// <param name="channel">The channel.</param>
            /// <returns>List&lt;ChannelJodel&gt;.</returns>
            public async Task <List <ChannelJodel> > GetJodelsAsync(string channel)
            {
                string plainJson;

                using (var client = new MyWebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    var taskResult = await Task.FromResult(
                        client.DownloadStringTaskAsync(new Uri(Constants.LinkGetJodelsFromChannel.ToLink(channel))));

                    plainJson = taskResult.Result;
                }

                JsonGetJodelsFromChannel.RootObject myJodelsFromChannel =
                    JsonConvert.DeserializeObject <JsonGetJodelsFromChannel.RootObject>(plainJson);
                return(myJodelsFromChannel.recent.Select(item => new ChannelJodel
                {
                    PostId = item.post_id,
                    Message = item.message,
                    VoteCount = item.vote_count,
                    PinCount = item.pin_count,
                    IsOwn = item.post_own.Equals("own")
                }).ToList());
            }