Ejemplo n.º 1
0
        /// <summary>
        ///     Gets my jodels.
        /// </summary>
        /// <returns>List&lt;MyJodels&gt;.</returns>
        public List <MyJodels> GetMyJodels()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkGetMyJodels.ToLink());
            }

            JsonMyJodels.RootObject myJodels = JsonConvert.DeserializeObject <JsonMyJodels.RootObject>(plainJson);
            return(myJodels.posts.Select(item => new MyJodels
            {
                PostId = item.post_id,
                Message = item.message,
                HexColor = item.color,
                VoteCount = item.vote_count,
                Latitude = item.location.loc_coordinates.lat,
                Longitude = item.location.loc_coordinates.lng,
                LocationName = item.location.name,
                ChildCount = item.child_count,
                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
            }).ToList());
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets the karma.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public int GetKarma()
        {
            string resp;

            using (var client = new MyWebClient())
            {
                resp = client.DownloadString(Constants.LinkGetKarma.ToLink());
            }
            string result = resp.Substring(resp.LastIndexOf(':') + 1);

            return(Convert.ToInt32(result.Replace("}", "").Replace("\"", "")));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the UserConfig
        /// </summary>
        public User.UserConfig GetUserConfig()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkConfig.ToLink());
            }

            JsonConfig.RootObject config = JsonConvert.DeserializeObject <JsonConfig.RootObject>(plainJson);

            List <User.Experiment> experiments = new List <User.Experiment>(config.experiments.Count);

            foreach (JsonConfig.Experiment experiment in config.experiments)
            {
                experiments.Add(new User.Experiment
                {
                    Features = experiment.features,
                    Group    = experiment.group,
                    Name     = experiment.name
                });
            }

            List <Channel> channels = new List <Channel>(config.followed_hashtags.Count);

            foreach (string channelname in config.followed_channels)
            {
                channels.Add(new Channel(channelname));
            }

            User.UserConfig uconfig = new User.UserConfig
            {
                ChannelsFollowLimit = config.channels_follow_limit,
                Experiments         = experiments,
                HomeName            = config.home_name,
                HomeSet             = config.home_set,
                FollowedHashtags    = config.followed_hashtags,
                Location            = config.location,
                Moderator           = config.moderator,
                TripleFeedEnabled   = config.triple_feed_enabled,
                UserType            = config.user_type,
                Verified            = config.verified,
                FollowedChannels    = channels
            };
            _user.Config = uconfig;
            return(uconfig);
        }
Ejemplo n.º 5
0
            /// <summary>
            ///     Get's the recommended channels.
            /// </summary>
            /// <returns>List&lt;RecommendedChannel&gt;.</returns>
            public List <RecommendedChannel> GetRecommendedChannels()
            {
                string plainJson;

                using (var client = new MyWebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    plainJson       = client.DownloadString(Constants.LinkGetRecommendedChannels.ToLink());
                }

                JsonRecommendedChannels.RootObject recommendedChannels =
                    JsonConvert.DeserializeObject <JsonRecommendedChannels.RootObject>(plainJson);
                return(recommendedChannels.recommended.Select(item => new RecommendedChannel
                {
                    Name = item.channel,
                    Followers = item.followers
                }).ToList());
            }
Ejemplo n.º 6
0
        /// <summary>
        ///     Determines whether the specified token is from a moderator.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns><c>true</c> if the specified token is moderator; otherwise, <c>false</c>.</returns>
        public bool IsModerator(string token)
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkConfig.ToLink());
            }

            JsonConfig.RootObject config = JsonConvert.DeserializeObject <JsonConfig.RootObject>(plainJson);

            if (config.moderator)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        //TODO: FIXME!
        //public static string PostJodel(Image image, PostColor colorParam = PostColor.Random, string postId = null)
        //{
        //    DateTime dt = DateTime.UtcNow;

        //    var color = Helpers.GetColor(colorParam);

        //    ImageConverter ic = new ImageConverter();
        //    byte[] buffer = (byte[]) ic.ConvertTo(image, typeof(byte[]));
        //    string base64 = Convert.ToBase64String(buffer, Base64FormattingOptions.InsertLineBreaks);

        //    string stringifiedPayload = @"POST%api.go-tellm.com%443%/api/v2/posts/%" + _user.AccessToken + "%" +
        //                                $"{dt:s}Z" +
        //                                "%%{\"color\": \"" + color +
        //                                "\", \"message\": \"\", \"location\": {\"loc_accuracy\": 1, \"city\": \"" +
        //                                _user.City +
        //                                "\", \"loc_coordinates\": " + "{\"lat\": " + _user.Latitude + ", \"lng\": " +
        //                                _user.Longitude + "}, \"country\": \"" + _user.CountryCode +
        //                                "\", \"name\": \"" + _user.City + "\"}, \"image\": \"" + base64 + "\"}";

        //    string payload = "{\"color\": \"" + color +
        //                     "\", \"message\": \"\", \"location\": {\"loc_accuracy\": 1, \"city\": \"" + _user.City +
        //                     "\", \"loc_coordinates\": " + "{\"lat\": " + _user.Latitude + ", \"lng\": " +
        //                     _user.Longitude + "}, \"country\": \"" + _user.CountryCode +
        //                     "\", \"name\": \"" + _user.City + "\"}, \"image\": \"" + base64 + "\"}";

        //    var keyByte = Encoding.UTF8.GetBytes(Constants.Key);
        //    using (var hmacsha1 = new HMACSHA1(keyByte))
        //    {
        //        hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(stringifiedPayload));

        //        using (var client = new MyWebClient())
        //        {
        //            client.Headers.Add(Constants.Header.ToHeader(stringifiedPayload, true));
        //            client.Encoding = Encoding.UTF8;
        //            string newJodels = client.UploadString(Constants.LinkPostImage, payload);
        //            JsonPostJodels.RootObject temp = JsonConvert.DeserializeObject<JsonPostJodels.RootObject>(newJodels);
        //            return temp.posts[0].post_id;
        //        }
        //    }
        //}

        /// <summary>
        ///     Gets the comments.
        /// </summary>
        /// <param name="postId">The post identifier.</param>
        /// <returns>List&lt;Comments&gt;.</returns>
        public List <Comments> GetComments(string postId)
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkGetComments.ToLink(_user.AccessToken, postId));
            }
            JsonComments.RootObject com = JsonConvert.DeserializeObject <JsonComments.RootObject>(plainJson);

            var result = new List <Comments>();

            if (com.children != null)
            {
                foreach (var child in com.children)
                {
                    string image_url = "";
                    bool   isUrl     = false;

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

                    result.Add(new Comments
                    {
                        Message    = child.message,
                        PostId     = child.post_id,
                        CreatedAt  = DateTime.ParseExact(child.created_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                        UpdatedAt  = DateTime.ParseExact(child.updated_at.Replace("Z", "").Replace("T", " "), "yyyy-MM-dd HH:mm:ss.fff", null),
                        IsImage    = isUrl,
                        ImageUrl   = image_url,
                        UserHandle = child.user_handle,
                        VoteCount  = child.vote_count
                    });
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Get's all pinned Jodels.
        /// </summary>
        /// <returns>List&lt;MyPins&gt;.</returns>
        public List <MyPins> GetMyPins()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkMyPins.ToLink());
            }

            JsonMyPins.RootObject myPins = JsonConvert.DeserializeObject <JsonMyPins.RootObject>(plainJson);
            return(myPins.posts.Select(item => new MyPins
            {
                PostId = item.post_id,
                Message = item.message,
                VoteCount = item.vote_count,
                PinCount = item.pin_count,
                IsOwn = item.post_own.Equals("own")
            }).ToList());
        }
Ejemplo n.º 9
0
            /// <summary>
            ///     Get's all Jodels from this channel.
            /// </summary>
            /// <param name="channel">The channel.</param>
            /// <returns>List&lt;ChannelJodel&gt;.</returns>
            public List <ChannelJodel> GetJodels(string channel)
            {
                string plainJson;

                using (var client = new MyWebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    plainJson       = client.DownloadString(Constants.LinkGetJodelsFromChannel.ToLink(channel));
                }

                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());
            }
Ejemplo n.º 10
0
        /// <summary>
        ///     Gets my votes.
        /// </summary>
        /// <returns>List&lt;MyVotes&gt;.</returns>
        public List <MyVotes> GetMyVotes()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkGetMyVotes.ToLink());
            }

            JsonMyVotes.RootObject myVotes = JsonConvert.DeserializeObject <JsonMyVotes.RootObject>(plainJson);
            return(myVotes.posts.Select(item => new MyVotes
            {
                PostId = item.post_id,
                Message = item.message,
                HexColor = item.color,
                VoteCount = item.vote_count,
                IsOwn = item.post_own.Equals("own"),
                LocationName = item.location.name
            }).ToList());
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Gets the reported Jodels
        /// </summary>
        /// <returns>List&lt;ModerationQueue&gt;.</returns>
        public List <ModerationQueue> GetModerationQueue()
        {
            string plainJson;

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                plainJson       = client.DownloadString(Constants.LinkModeration.ToLink());
            }
            JsonModeration.RootObject queue = JsonConvert.DeserializeObject <JsonModeration.RootObject>(plainJson);
            return(queue.posts.Select(item => new ModerationQueue
            {
                PostId = item.post_id,
                FlagCount = item.flag_count,
                FlagReason = item.flag_reason,
                HexColor = item.color,
                Message = item.message,
                ParentId = item.parent_id,
                TaskId = item.task_id,
                UserHandle = item.user_handle,
                VoteCount = item.vote_count
            }).ToList());
        }