コード例 #1
0
        /// <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);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
 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");
 }
コード例 #4
0
        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");
        }
コード例 #5
0
ファイル: FilesApiTests.cs プロジェクト: gong0704/.net-sdk
 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");
 }
コード例 #6
0
ファイル: DatabaseApiTests.cs プロジェクト: gong0704/.net-sdk
 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");
 }
コード例 #7
0
 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");
 }
コード例 #8
0
ファイル: UserApiTests.cs プロジェクト: gong0704/.net-sdk
 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);
 }