Example #1
0
            /// <summary>
            ///     Unfollows a channel.
            /// </summary>
            /// <param name="channel"></param>
            public void UnfollowChannel()
            {
                DateTime dt = DateTime.UtcNow;

                string payload            = "{}";
                string stringifiedPayload = @"PUT%api.go-tellm.com%443%/api/v3/user/unfollowChannel?channel=" + ChannelName + "%" + $"{dt:s}Z" + "%%" + payload;

                using (var client = new MyWebClient())
                {
                    client.Headers.Add(Constants.Header.ToHeader(stringifiedPayload, dt, true));
                    client.Encoding = Encoding.UTF8;
                    client.UploadString(Constants.LinkUnfollowChannel.ToLinkSecond(ChannelName), "PUT", payload);
                }
            }
Example #2
0
        /// <summary>
        ///     Posts a jodel.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="colorParam">The color parameter.</param>
        /// <param name="postId">The post identifier.</param>
        public string PostJodel(string message, PostColor colorParam = PostColor.Random, string postId = null)
        {
            DateTime dt = DateTime.UtcNow;

            var color = Helpers.GetColor(colorParam);

            string jsonCommentFragment = string.Empty;

            if (postId != null)
            {
                jsonCommentFragment = @"""ancestor"": """ + postId + @""", ";
            }

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

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

            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, dt, true));
                    client.Encoding = Encoding.UTF8;
                    string newJodels = client.UploadString(Constants.LinkPostJodel, payload);
                    JsonPostJodels.RootObject temp = JsonConvert.DeserializeObject <JsonPostJodels.RootObject>(newJodels);
                    return(temp.posts[0].post_id);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Initial Load of all Followed Channels
        /// </summary>
        public void LoadFollowedChannels()
        {
            if (_user.Config == null)
            {
                return;
            }

            DateTime dt = DateTime.UtcNow;
            string   jsonString;


            string payload = "{";

            List <string> channelnames = _user.Config.FollowedChannels.Select(x => x.ChannelName).ToList();

            if (channelnames.Count != 0)
            {
                for (int i = 0; i < channelnames.Count; i++)
                {
                    channelnames[i] = @"""" + channelnames[i] + @""":-1";
                }
                payload += channelnames.Aggregate((i, j) => i + "," + j);
            }


            payload += "}";


            string stringifiedPayload = "POST%api.go-tellm.com%443%/api/v3/user/followedChannelsMeta%%" + $"{dt:s}Z" + "%%" + payload;

            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, DateTime.UtcNow));
                    client.Encoding = Encoding.UTF8;
                    jsonString      = client.UploadString(Constants.LinkLoadFollowedChannels.ToLink(), payload);
                }
            }

            //TODO: Channels laden
        }
Example #4
0
        /// <summary>
        ///     Flags the jodel.
        /// </summary>
        /// <param name="taskId">The task identifier.</param>
        /// <param name="decision">The decision.</param>
        public void FlagJodel(int taskId, Decision decision)
        {
            DateTime dt = DateTime.UtcNow;

            string dec = Convert.ChangeType(decision, decision.GetTypeCode())?.ToString(); // get int from enum.
            string stringifiedPayload = @"POST%api.go-tellm.com%443%/api/v3/moderation/%%" + $"{dt:s}Z" +
                                        @"%%{""decision"": " + dec +
                                        @", ""task_id"": """ + taskId +
                                        @"""}";

            string payload = @"{""decision"": " + dec +
                             @", ""task_id"": """ + taskId +
                             @"""}";

            using (var client = new MyWebClient())
            {
                client.Headers.Add(Constants.Header.ToHeader(stringifiedPayload, dt));
                client.Encoding = Encoding.UTF8;
                client.UploadString(Constants.LinkModeration.ToLink(), payload);
            }
        }
Example #5
0
        /// <summary>
        ///     Generates an access token.
        /// </summary>
        /// <returns>System.String.</returns>
        public static Tokens GenerateAccessToken()
        {
            DateTime dt = DateTime.UtcNow;
            string   jsonString;
            string   deviceUid = Helpers.Sha256(Helpers.RandomString(20, true));

            string stringifiedPayload = @"POST%api.go-tellm.com%443%/api/v2/users/%%" + $"{dt:s}Z" +
                                        @"%%{""device_uid"": """ + deviceUid + @""", ""location"": {""City"": """ + _user.City +
                                        @""", ""loc_accuracy"": 0, ""loc_coordinates"": {""lat"": " + _user.Latitude +
                                        @", ""lng"": " + _user.Longitude + @"}, ""country"": """ + _user.CountryCode + @"""}, " +
                                        @"""client_id"": """ + Constants.ClientId + @"""}";

            string payload = @"{""device_uid"": """ + deviceUid + @""", ""location"": {""City"": """ + _user.City +
                             @""", ""loc_accuracy"": 0, ""loc_coordinates"": " + @"{""lat"": " + _user.Latitude +
                             @", ""lng"": " + _user.Longitude + @"}, ""country"": """ + _user.CountryCode +
                             @"""}, ""client_id"": """ + Constants.ClientId + @"""}";

            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, DateTime.UtcNow));
                    client.Encoding = Encoding.UTF8;
                    jsonString      = client.UploadString(Constants.LinkGenAt, payload);
                }
            }

            JsonTokens.RootObject objTokens = JsonConvert.DeserializeObject <JsonTokens.RootObject>(jsonString);

            return(new Tokens
            {
                AccessToken = objTokens.access_token,
                RefreshToken = objTokens.refresh_token,
                ExpireTimestamp = objTokens.expiration_date
            });
        }
Example #6
0
        /// <summary>
        ///     Refreshes the access token.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="refreshToken">The refresh token.</param>
        /// <returns>Tokens.</returns>
        public Tokens RefreshAccessToken(string accessToken, string refreshToken)
        {
            string       plainJson;
            const string payload = @"{""refresh_token"": ""{RT}""}";

            using (var client = new MyWebClient())
            {
                client.Encoding = Encoding.UTF8;
                client.Headers.Add("Content-Type", "application/json");
                plainJson = client.UploadString(Constants.LinkRefreshToken.Replace("{AT}", accessToken),
                                                payload.Replace("{RT}", refreshToken));
            }

            JsonRefreshTokens.RootObject objRefToken =
                JsonConvert.DeserializeObject <JsonRefreshTokens.RootObject>(plainJson);

            return(new Tokens
            {
                AccessToken = objRefToken.access_token,
                ExpireTimestamp = objRefToken.expiration_date,
                RefreshToken = refreshToken
            });
        }