public static object DeserializeFromString(this ITMDbSerializer serializer, string json, Type type)
        {
            // TODO: Better method
            byte[] bytes = Encoding.UTF8.GetBytes(json);
            using MemoryStream ms = new MemoryStream(bytes);

            return(serializer.Deserialize(ms, type));
        }
        public static T DeserializeFromString <T>(this ITMDbSerializer serializer, string json)
        {
            // TODO: Better method
            byte[] bytes = Encoding.UTF8.GetBytes(json);
            using MemoryStream ms = new MemoryStream(bytes);

            return(serializer.ObsoleteDeserialize <T>(ms));
        }
        public static byte[] SerializeToBytes <T>(this ITMDbSerializer serializer, T @object)
        {
            using MemoryStream ms = new MemoryStream();

            serializer.Serialize(ms, @object, typeof(T));

            return(ms.ToArray());
        }
        public static string SerializeToString <T>(this ITMDbSerializer serializer, T @object)
        {
            using MemoryStream ms = new MemoryStream();

            serializer.Serialize(ms, @object, typeof(T));

            ms.Seek(0, SeekOrigin.Begin);

            using StreamReader sr = new StreamReader(ms, Encoding.UTF8);

            return(sr.ReadToEnd());
        }
Example #5
0
        public TestConfig(bool useSsl = false, ITMDbSerializer serializer = null, IWebProxy proxy = null)
        {
            if (APIKey.Length == 0)
            {
                throw new ConfigurationErrorsException("You need to configure the API Key before running any tests. Look at the TestConfig class.");
            }

            Client = new TMDbClient(APIKey, useSsl, serializer: serializer, proxy: proxy)
            {
                MaxRetryCount = 1
            };
        }
Example #6
0
        public TMDbClient(string apiKey, bool useSsl = true, string baseUrl = ProductionUrl, ITMDbSerializer serializer = null, IWebProxy proxy = null)
        {
            DefaultLanguage      = null;
            DefaultImageLanguage = null;
            DefaultCountry       = null;

            _serializer = serializer ?? TMDbJsonSerializer.Instance;

            //Setup proxy to use during requests
            //Proxy is optional. If passed, will be used in every request.
            WebProxy = proxy;

            Initialize(baseUrl, useSsl, apiKey);
        }
Example #7
0
        public RestClient(Uri baseUrl, ITMDbSerializer serializer, IWebProxy proxy = null)
        {
            BaseUrl            = baseUrl;
            Serializer         = serializer;
            DefaultQueryString = new List <KeyValuePair <string, string> >();

            MaxRetryCount = 0;
            Proxy         = proxy;

            HttpClientHandler handler = new HttpClientHandler();

            if (proxy != null)
            {
                // Blazor apparently throws on the Proxy setter.
                // https://github.com/LordMike/TMDbLib/issues/354
                handler.Proxy = proxy;
            }

            HttpClient = new HttpClient(handler);
        }
 public static void Serialize <T>(this ITMDbSerializer serializer, Stream target, T @object)
 {
     serializer.Serialize(target, @object, typeof(T));
 }
 public static T ObsoleteDeserialize <T>(this ITMDbSerializer serializer, Stream source)
 {
     return((T)serializer.Deserialize(source, typeof(T)));
 }