/// <summary>
        /// Initializes a new instance of the <see cref="RestContext"/> class.
        /// </summary>
        /// <param name="baseAddress">Base address (URL).</param>
        /// <param name="applicationName">Application name.</param>
        /// <param name="applicationApiKey">Application API key.</param>
        /// <param name="sessionId">SessionId to be added to base headers.</param>
        /// <param name="httpFacade">User defined instance of <see cref="IHttpFacade"/>.</param>
        /// <param name="serializer">User defined instance of <see cref="IContentSerializer"/>.</param>
        /// <param name="apiVersion">REST API version to use.</param>
        public RestContext(string baseAddress, string applicationName, string applicationApiKey, string sessionId, IHttpFacade httpFacade, IContentSerializer serializer, RestApiVersion apiVersion = RestApiVersion.V2)
        {
            HttpUtils.CheckUrlString(baseAddress);

            if (applicationName == null)
            {
                throw new ArgumentNullException("applicationName");
            }

            if (applicationApiKey == null)
            {
                throw new ArgumentNullException("applicationApiKey");
            }

            if (httpFacade == null)
            {
                throw new ArgumentNullException("httpFacade");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            address = new HttpAddress(baseAddress, apiVersion);

            HttpFacade = httpFacade;
            ContentSerializer = serializer;

            SetBaseHeaders(applicationName, applicationApiKey, sessionId);

            Factory = new ServiceFactory(address, HttpFacade, ContentSerializer, httpHeaders);
        }
 private static ISystemApi CreateSystemApi(out HttpHeaders headers, string suffix = null)
 {
     IHttpFacade httpFacade = new TestDataHttpFacade(suffix);
     HttpAddress address = new HttpAddress("http://base_address", RestApiVersion.V1);
     headers = new HttpHeaders();
     return new SystemApi(address, httpFacade, new JsonContentSerializer(), headers);
 }
 private static IEmailApi CreateEmailApi()
 {
     IHttpFacade httpFacade = new TestDataHttpFacade();
     HttpAddress address = new HttpAddress("http://base_address", RestApiVersion.V1);
     HttpHeaders headers = new HttpHeaders();
     return new EmailApi(address, httpFacade, new JsonContentSerializer(), headers, "email");
 }
        public void ShouldBuildAfterConstruction()
        {
            // Arrange
            List<string> resources = new List<string> { "user", "session" };
            Dictionary<string, object> parameters = new Dictionary<string, object>
            {
                { "one", 1 },
                { "two", true }
            };

            // Act
            HttpAddress addressV1 = new HttpAddress("http://base_address", RestApiVersion.V1, resources, parameters);
            HttpAddress addressV2 = new HttpAddress("http://base_address", RestApiVersion.V2, resources, parameters);

            // Assert
            addressV1.Build().ShouldBe("http://base_address" + "/rest/user/session?one=1&two=true");
            addressV2.Build().ShouldBe("http://base_address" + "/api/v2/user/session?one=1&two=true");
        }
Example #5
0
 private static IFilesApi CreateFilesApi()
 {
     IHttpFacade httpFacade = new TestDataHttpFacade();
     HttpAddress address = new HttpAddress(BaseAddress, RestApiVersion.V1);
     HttpHeaders headers = new HttpHeaders();
     return new FilesApi(address, httpFacade, new JsonContentSerializer(), headers, "files");
 }
Example #6
0
 private static IDatabaseApi CreateDatabaseApi(string alt = null)
 {
     IHttpFacade httpFacade = new TestDataHttpFacade(alt);
     HttpAddress address = new HttpAddress(BaseAddress, RestApiVersion.V1);
     HttpHeaders headers = new HttpHeaders();
     return new DatabaseApi(address, httpFacade, new JsonContentSerializer(), headers, "db");
 }
 private static ICustomSettingsApi CreateSettingsApi()
 {
     IHttpFacade httpFacade = new TestDataHttpFacade();
     HttpAddress address = new HttpAddress(BaseAddress, RestApiVersion.V1);
     return new CustomSettingsApi(address, httpFacade, new JsonContentSerializer(), new HttpHeaders(), "user");
 }
Example #8
0
 private static IUserApi CreateUserApi(out HttpHeaders headers, string suffix = null)
 {
     IHttpFacade httpFacade = new TestDataHttpFacade(suffix);
     HttpAddress address = new HttpAddress(BaseAddress, RestApiVersion.V1);
     headers = new HttpHeaders();
     return new UserApi(address, httpFacade, new JsonContentSerializer(), headers);
 }