Пример #1
0
        public static OmdbResult Query(string name)
        {
            name = name.Replace(' ', '+');
            if (name.Contains("'"))
            {
                name = name.Replace("'", "'");
            }
            string     url    = $"http://www.omdbapi.com/?t={name}&plot=short&r=json&tomatoes=true";
            RestClient client = new RestClient();

            client.BaseUrl = new Uri(url);
            RestRequest req = new RestRequest();

            req.Method = Method.GET;

            var response = client.Execute <OmdbResult>(req);

            try
            {
                JsonDeserializer deserializer = new JsonDeserializer();
                OmdbResult       mov          = deserializer.Deserialize <OmdbResult>(response);
                Log(mov.ToString());
                return(mov);
            }
            catch (Exception e)
            {
                Error(e);
                return(new OmdbResult());
            }
        }
Пример #2
0
        private static OmdbResult PrivateQuery(string name, string year, bool fullPlot = true)
        {
            string     plotString = fullPlot ? "full" : "short";
            string     url        = $"http://www.omdbapi.com/?t={name}&y={year}&plot={plotString}&r=json&tomatoes=true";
            RestClient client     = new RestClient();

            client.BaseUrl = new Uri(url);
            RestRequest req = new RestRequest();

            req.Method = Method.GET;

            var response = client.Execute <OmdbResult>(req);

            try
            {
                JsonDeserializer deserializer = new JsonDeserializer();
                OmdbResult       mov          = deserializer.Deserialize <OmdbResult>(response);
                Log(mov.ToString());
                return(mov);
            }
            catch (Exception e)
            {
                Error(e);
                return(default(OmdbResult));
            }
        }