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); }
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; } }
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)); }
public YandexDirectConfiguration(IYandexApiAuthProvider authProvider, YandexApiLanguage language) : this() { AuthProvider = authProvider; Language = language; }
public YandexDirectConfiguration(IYandexApiAuthProvider authProvider) : this() { AuthProvider = authProvider; }
public YandexDirectService(IYandexApiAuthProvider authProvider, YandexApiLanguage language) : this(new YandexDirectConfiguration(authProvider, language)) { }
public YandexDirectService(IYandexApiAuthProvider authProvider) : this(new YandexDirectConfiguration(authProvider)) { }