Example #1
0
		/// <constructor />
		public CouchApi(CouchApiSettings settings, HttpMessageHandler messageHandler = null)
			: base(messageHandler ?? new HttpClientHandler())
		{
			Settings = settings;

			uriConstructor = new UriConstructor(settings.ServerUri);
			synchronousCouchApi = new SynchronousCouchApi(this);
			replicatorApi = new ReplicatorApi(this);

			BaseAddress = settings.ServerUri;
			DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaType.Json));
			DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
			DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
			if (settings.Credentials != null)
				DefaultRequestHeaders.Authorization = settings.Credentials.ToAuthenticationHeader();
		}
Example #2
0
        /// <constructor />
        public CouchApi(CouchApiSettings settings, HttpMessageHandler messageHandler = null)
            : base(messageHandler ?? new HttpClientHandler())
        {
            Settings = settings;

            uriConstructor      = new UriConstructor(settings.ServerUri);
            synchronousCouchApi = new SynchronousCouchApi(this);
            replicatorApi       = new ReplicatorApi(this);

            BaseAddress = settings.ServerUri;
            DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaType.Json));
            DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
            if (settings.Credentials != null)
            {
                DefaultRequestHeaders.Authorization = settings.Credentials.ToAuthenticationHeader();
            }
        }
Example #3
0
		IDatabaseApi ConsturctDatabaseApi(Uri databaseUri, string userName, string password)
		{
			var serverUriString = databaseUri.GetComponents(
				UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);
			var databaseName = databaseUri.LocalPath.Trim('/');
			var settings = new CouchApiSettings(serverUriString);
			if(userName != null && password != null)
				settings.Credentials = new Credentials(userName, password);
			return settings.CreateCouchApi(messageHandler).Db(databaseName);
		}