コード例 #1
0
        private HttpWebRequest CreateRequest(string requestMessage, IYandexApiAuthProvider authProvider)
        {
            var request = (HttpWebRequest)WebRequest.Create(Configuration.ServiceUrl);

            // Adding authentication information into the http-request

            if (authProvider != null)
            {
                authProvider.OnHttpRequest(this, request);
            }

            // Configuring request

            request.Method      = "POST";
            request.ContentType = "application/json; charset=utf-8";

            var data = Encoding.UTF8.GetBytes(requestMessage);

            request.ContentLength = data.Length;

            using (var requestStream = request.GetRequestStream())
            {
                requestStream.Write(data, 0, data.Length);
            }

            return(request);
        }
コード例 #2
0
        private void LoadFromConfigurationFile()
        {
            // Obtaining configuration section

            var configSection = (YandexDirectSection)ConfigurationManager.GetSection("yandex.direct");

            if (configSection == null)
            {
                return;
            }

            // Loading ServiceUrl and Language if specified

            if (!string.IsNullOrEmpty(configSection.ServiceUrl))
            {
                ServiceUrl = new Uri(configSection.ServiceUrl);
            }

            if (configSection.Language != null)
            {
                Language = configSection.Language.Value;
            }

            // Loading authentication provider if specified

            if (configSection.AuthProvider.Type != null)
            {
                var providerType = Type.GetType(configSection.AuthProvider.Type, true);
                var authProvider = (IYandexApiAuthProvider)Activator.CreateInstance(providerType);

                authProvider.LoadSettings(configSection.AuthProvider);

                AuthProvider = authProvider;
            }
        }
コード例 #3
0
        private string CreateRequestMessage(string method, object param, IYandexApiAuthProvider authProvider,
                                            bool financeTokenRequired)
        {
            // Creating request message

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["method"] = method;
            parameters["param"]  = param;
            parameters["locale"] = Configuration.Language;

            // Adding authentication information into the request message

            if (authProvider != null)
            {
                authProvider.OnRequestMessage(this, method, parameters, financeTokenRequired);
            }

            return(SerializeRequestMessage(parameters));
        }
コード例 #4
0
 public YandexDirectConfiguration(IYandexApiAuthProvider authProvider, YandexApiLanguage language)
     : this()
 {
     AuthProvider = authProvider;
     Language     = language;
 }
コード例 #5
0
 public YandexDirectConfiguration(IYandexApiAuthProvider authProvider)
     : this()
 {
     AuthProvider = authProvider;
 }
コード例 #6
0
 public YandexDirectConfiguration(IYandexApiAuthProvider authProvider, YandexApiLanguage language)
     : this()
 {
     AuthProvider = authProvider;
     Language = language;
 }
コード例 #7
0
 public YandexDirectConfiguration(IYandexApiAuthProvider authProvider)
     : this()
 {
     AuthProvider = authProvider;
 }
コード例 #8
0
 public YandexDirectService(IYandexApiAuthProvider authProvider, YandexApiLanguage language)
     : this(new YandexDirectConfiguration(authProvider, language))
 {
 }
コード例 #9
0
 public YandexDirectService(IYandexApiAuthProvider authProvider)
     : this(new YandexDirectConfiguration(authProvider))
 {
 }
コード例 #10
0
 public YandexDirectService(IYandexApiAuthProvider authProvider, YandexApiLanguage language)
     : this(new YandexDirectConfiguration(authProvider, language))
 {
 }
コード例 #11
0
 public YandexDirectService(IYandexApiAuthProvider authProvider)
     : this(new YandexDirectConfiguration(authProvider))
 {
 }