コード例 #1
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);
                }
            }
        }
コード例 #2
0
 public static string GetColor(PostColor color) => Colors[color];