public void ExecuteUserPost_v2()
        {
            //
            var isDebug = true;

            var request = new UserPostRequest
            {
                app_key = this.app_key,
                user_key = this.user_key,
                body = "body test",
                title = "title test",
                networks = String.Empty,
                poi_lat = String.Empty,
                poi_long = String.Empty,
                poi_name = String.Empty,
                scheduled_time = DateTime.Now.AddMinutes(10).ToString("s")
            };

            // Comment this in if you are running MSTEST in Visual Studio
            var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var fileName = System.IO.Path.Combine(path, "cute.jpg");
            request.image = new System.IO.FileInfo(fileName);

            //
            request.debug = (isDebug) ? "1" : "0";

            ServiceResponse rsp = api.PostRequest<UserPostRequest, ServiceResponse>("user.post", request);

            Assert.AreEqual(rsp.status, (isDebug) ? "DEBUG" : "OK");
        }
Example #2
0
        /// <summary>
        /// Posts a message to the user’s Hellotxt services.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>OK. Error message on failure.</returns>
        public ServiceResponse Post(UserPostRequest request)
        {
            using (var client = GetDefaultClient())
            {
                // build form data post
                HttpMultipartMimeForm form = new HttpMultipartMimeForm();
                form.Add("app_key", this.AppKey);
                form.Add("user_key", this.UserKey);
                form.Add("body", request.body);
                if (!String.IsNullOrWhiteSpace(request.title)) form.Add("title", request.title);
                if (!String.IsNullOrWhiteSpace(request.networks)) form.Add("networks", request.networks);
                if (!String.IsNullOrWhiteSpace(request.poi_lat)) form.Add("poi_lat", request.poi_lat);
                if (!String.IsNullOrWhiteSpace(request.poi_long)) form.Add("poi_long", request.poi_long);
                if (!String.IsNullOrWhiteSpace(request.poi_name)) form.Add("poi_name", request.poi_name);
                if (!String.IsNullOrWhiteSpace(request.scheduled_time)) form.Add("scheduled_time", request.scheduled_time);
                if (!String.IsNullOrWhiteSpace(request.debug)) form.Add("debug", request.debug);

                if (request.image != null)
                {
                    HttpFormFile file = new HttpFormFile();
                    file.Content = HttpContent.Create(request.image, "application/octet-stream");
                    file.FileName = request.image.Name;
                    file.Name = "image";

                    form.Files.Add(file);
                }

                // call method
                using (HttpResponseMessage response = client.Post("user.post", form.CreateHttpContent()))
                {
                    response.EnsureStatusIsSuccessful();
                    return response.Content.ReadAsXmlSerializable<ServiceResponse>();
                }
            }
        }
        public void ExecuteUserPost_v1()
        {
            //
            bool isDebug = true;

            UserPostRequest request = new UserPostRequest();
            request.body = "body test";
            request.title = "title test";
            request.networks = String.Empty;
            request.poi_lat = String.Empty;
            request.poi_long = String.Empty;
            request.poi_name = String.Empty;
            request.scheduled_time = DateTime.Now.AddMinutes(10).ToString("s");

            // Comment this in if you are running MSTEST in Visual Studio
            /*var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var fileName = System.IO.Path.Combine(path, "cute.jpg");
            request.image = new System.IO.FileInfo(fileName);*/

            //
            request.debug = (isDebug) ? "1" : "0";

            ServiceResponse rsp = api.Post(request);

            //
            Assert.AreEqual(rsp.status, (isDebug) ? "DEBUG" : "OK");
        }