public User Update(int userId, Dictionary <string, string> attributes, bool webhook = false)
        {
            string   path     = "/users/" + userId;
            JsonArgs query    = null;
            JsonArgs userData = new JsonArgs {
            };

            foreach (KeyValuePair <string, string> entry in attributes)
            {
                userData.Add(entry.Key, entry.Value);
            }
            NestedJsonArgs data = new NestedJsonArgs
            {
                { "user", userData }
            };

            if (webhook)
            {
                query = new JsonArgs
                {
                    { "webhook", "true" }
                };
            }
            return(this.Client.Put <User>(path, data, query));
        }
Esempio n. 2
0
        public Appointment Update(int scheduleId, int appointmentId, Dictionary <string, string> attributes, bool form = false, bool webhook = false)
        {
            string   path            = "/bookings/" + appointmentId.ToString();
            JsonArgs appointmentData = new JsonArgs {
            };

            foreach (KeyValuePair <string, string> entry in attributes)
            {
                appointmentData.Add(entry.Key, entry.Value);
            }
            NestedJsonArgs data = new NestedJsonArgs
            {
                { "booking", appointmentData }
            };
            JsonArgs query = new JsonArgs {
                { "schedule_id", scheduleId.ToString() }
            };

            if (webhook)
            {
                query.Add("webhook", "true");
            }
            if (form)
            {
                query.Add("form", "true");
            }
            return(this.Client.Put <Appointment>(path, data, query));
        }
        public void Create(Dictionary <string, string> attributes, string userId = null, bool webhook = false)
        {
            string path = "/users";

            if (userId != null)
            {
                path += "/" + userId;
            }
            JsonArgs userData = new JsonArgs {
            };

            foreach (KeyValuePair <string, string> entry in attributes)
            {
                userData.Add(entry.Key, entry.Value);
            }
            NestedJsonArgs data = new NestedJsonArgs
            {
                { "user", userData }
            };
            JsonArgs query = null;

            if (webhook)
            {
                query = new JsonArgs
                {
                    { "webhook", "true" }
                };
            }
            this.Client.Post <User>(path, data, query);
        }
Esempio n. 4
0
        public Appointment[] Available(int scheduleId, DateTime fromTime, int lengthMinutes = 0, string resource = null, bool full = false, int limit = 0)
        {
            string   path = "/bookings";
            JsonArgs data = new JsonArgs {
                { "schedule_id", scheduleId.ToString() },
                { "from", fromTime.ToString("yyyy-MM-dd HH:mm:ss") }
            };

            if (lengthMinutes > 0)
            {
                data.Add("length", lengthMinutes.ToString());
            }
            if (resource != null)
            {
                data.Add("resource", resource);
            }
            if (full)
            {
                data.Add("full", "true");
            }
            if (limit > 0)
            {
                data.Add("limit", limit.ToString());
            }
            return(this.Client.Get <Appointment[]>(path, data));
        }
        public void DeleteTest()
        {
            JsonArgs data = new JsonArgs {
                { "id", "123" }
            };

            Assert.AreEqual(default(object), this.Client.Delete <object>("/test", null, data));
        }
        public void GetTest()
        {
            JsonArgs data = new JsonArgs {
                { "test", "true" }
            };

            Assert.AreEqual(default(object), this.Client.Get <object>("/test", data));
        }
Esempio n. 7
0
        public Changes Changes(int scheduleId, DateTime fromTime)
        {
            string   path = "/changes/" + scheduleId.ToString();
            JsonArgs data = new JsonArgs {
                { "from", fromTime.ToString("yyyy-MM-dd HH:mm:ss") }
            };

            return(this.Client.Get <Changes>(path, data));
        }
Esempio n. 8
0
        public void Delete(int scheduleId, int appointmentId)
        {
            JsonArgs query = new JsonArgs {
                { "schedule_id", scheduleId.ToString() }
            };
            string path = "/bookings/" + appointmentId;

            this.Client.Delete <Appointment>(path, null, query);
        }
Esempio n. 9
0
        public Resource[] Resources(int scheduleId)
        {
            string   path = "/resources";
            JsonArgs data = new JsonArgs
            {
                { "schedule_id", scheduleId.ToString() }
            };

            return(this.Client.Get <Resource[]>(path, data));
        }
        public Form Get(int formId)
        {
            string   path = "/forms";
            JsonArgs data = new JsonArgs
            {
                { "id", formId.ToString() }
            };

            return(this.Client.Get <Form>(path, data));
        }
Esempio n. 11
0
        public Appointment Get(int scheduleId, int appointmentId)
        {
            string   path = "/bookings/" + appointmentId;
            JsonArgs data = new JsonArgs
            {
                { "schedule_id", scheduleId.ToString() }
            };

            return(this.Client.Get <Appointment>(path, data));
        }
Esempio n. 12
0
        public Slot[] ChangesSlots(int scheduleId, DateTime fromTime)
        {
            string   path = "/changes/" + scheduleId.ToString();
            JsonArgs data = new JsonArgs {
                { "from", fromTime.ToString("yyyy-MM-dd HH:mm:ss") },
                { "slot", "true" }
            };

            return(this.Client.Get <Slot[]>(path, data));
        }
Esempio n. 13
0
        public Appointment[] Agenda(int scheduleId, int userId, DateTime fromTime)
        {
            string   path = "/agenda/" + scheduleId.ToString();
            JsonArgs data = new JsonArgs {
                { "user", userId.ToString() }
            };

            if (fromTime > DateTime.MinValue)
            {
                data.Add("from", fromTime.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            return(this.Client.Get <Appointment[]>(path, data));
        }
        public Form[] List(int formId, DateTime fromTime)
        {
            string   path = "/forms";
            JsonArgs data = new JsonArgs
            {
                { "form_id", formId.ToString() }
            };

            if (fromTime > DateTime.MinValue)
            {
                data.Add("from", fromTime.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            return(this.Client.Get <Form[]>(path, data));
        }
Esempio n. 15
0
        static public int Main(string[] args)
        {
            Directory.SetCurrentDirectory(IOUtil.GetProcessDirectory());

            JsonArgs commandLine = new JsonArgs(args);

            if (!commandLine.HasParam("?"))
            {
                string server = args[0];
                int    port   = int.Parse(args[1]);
                string gameId = args[2];
                string userId = args[3];

                while (true)
                {
                    try
                    {
                        Console.WriteLine("Starting game ...");
                        TankClient client = new HttpTankClient(server, port, gameId, userId);
                        using (Game game = new Game(client, true))
                        {
                            game.Run(new SignalWeights());
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR: " + ex);
                    }

                    ConsoleKey key = ConsoleKey.N;
                    while (key != ConsoleKey.Y)
                    {
                        Console.WriteLine("\n\nWould you like to play again (y, or n)?\n");
                        key = Console.ReadKey(true).Key;
                        if (key == ConsoleKey.N)
                        {
                            Console.WriteLine("Thanks for playing!");
                            return(0);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine(Syntax);
            }

            return(0);
        }
        public User[] List(bool form = false, int limit = 0, int offset = 0)
        {
            string   path = "/users";
            JsonArgs data = new JsonArgs {
            };

            if (form)
            {
                data.Add("form", "true");
            }
            if (limit > 0)
            {
                data.Add("limit", limit.ToString());
            }
            if (offset > 0)
            {
                data.Add("offset", offset.ToString());
            }
            return(this.Client.Get <User[]>(path, data));
        }
Esempio n. 17
0
        public Appointment[] List(int scheduleId, bool form, DateTime startTime, int limit = 0)
        {
            string   path = "/bookings";
            JsonArgs data = new JsonArgs {
                { "schedule_id", scheduleId.ToString() },
            };

            if (startTime > DateTime.MinValue)
            {
                data.Add("from", startTime.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            if (form)
            {
                data.Add("form", "true");
            }
            if (limit > 0)
            {
                data.Add("limit", limit.ToString());
            }
            return(this.Client.Get <Appointment[]>(path, data));
        }
Esempio n. 18
0
        public Appointment Create(int scheduleId, int userId, Dictionary <string, string> attributes, bool form = false, bool webhook = false)
        {
            string   path            = "/bookings";
            JsonArgs appointmentData = new JsonArgs {
            };

            foreach (KeyValuePair <string, string> entry in attributes)
            {
                appointmentData.Add(entry.Key, entry.Value);
            }
            NestedJsonArgs data = new NestedJsonArgs
            {
                { "booking", appointmentData }
            };
            JsonArgs query = new JsonArgs {
                { "schedule_id", scheduleId.ToString() },
                { "user_id", userId.ToString() }
            };

            if (webhook)
            {
                query.Add("webhook", "true");
            }
            if (form)
            {
                query.Add("form", "true");
            }
            Client.Post <Appointment>(path, data, query);
            Appointment model = new Appointment();
            int         id    = Client.GetResourceIdFromHeader();

            if (id > 0)
            {
                model.id = id;
            }
            return(model);
        }
Esempio n. 19
0
        private T Request <T>(string httpMethod, string path, NestedJsonArgs postData = null, JsonArgs queryData = null)
        {
            string         url     = this.Host + "/" + path + ".json" + this.dictionaryToQuerystring(queryData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = httpMethod;
            request.Accept      = "application/json";
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", this.basicAuth());
            request.UserAgent = this.userAgent();
            request.Timeout   = TIMEOUT_SECONDS;

            string json = null;

            if (postData != null)
            {
                json = JsonConvert.SerializeObject(postData);
            }

            this.LastRequest = request;
            if (this.Test)
            {
                return(default(T));
            }

            if (json != null)
            {
                using (Stream stream = request.GetRequestStream())
                {
                    using (StreamWriter streamOut = new StreamWriter(stream, System.Text.Encoding.ASCII))
                    {
                        streamOut.Write(json);
                    }
                }
            }

            string body = "";

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (StreamReader streamIn = new StreamReader(stream))
                            {
                                body = streamIn.ReadToEnd();
                                streamIn.Close();
                            }
                            stream.Close();
                        }
                    }
                    response.Close();
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException && ((WebException)ex).Status == WebExceptionStatus.ProtocolError)
                {
                    using (WebResponse response = ((WebException)ex).Response)
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            if (stream != null)
                            {
                                using (StreamReader r = new StreamReader(stream))
                                {
                                    body = r.ReadToEnd();
                                    r.Close();
                                }
                                stream.Close();
                            }
                        }
                        response.Close();
                    }
                    throw new SSSException(body);
                }
                else
                {
                    throw new SSSException(ex.Message);
                }
            }

            if (body.Length > 0)
            {
                JsonSerializerSettings settings = new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                };
                T result = JsonConvert.DeserializeObject <T>(body, settings);
                return(result);
            }
            else
            {
                return(default(T));
            }
        }
Esempio n. 20
0
 public T Delete <T>(string path, NestedJsonArgs postData = null, JsonArgs queryData = null)
 {
     return(this.Request <T>(HttpMethod.DELETE, path, postData));
 }
Esempio n. 21
0
 public T Put <T>(string path, NestedJsonArgs postData = null, JsonArgs queryData = null)
 {
     return(this.Request <T>(HttpMethod.PUT, path, postData));
 }
Esempio n. 22
0
 public T Get <T>(string path, JsonArgs queryData = null)
 {
     return(this.Request <T>(HttpMethod.GET, path, null, queryData));
 }