コード例 #1
0
 public FindCustomerViewModel(IEndpointClient endpointClient, DbManager dbManager, IPreferenceManager preferenceManager, IFileClient fileClient)
 {
     this.endpointClient    = endpointClient;
     this.dbManager         = dbManager;
     this.preferenceManager = preferenceManager;
     this.fileClient        = fileClient;
 }
コード例 #2
0
        protected virtual void AssertRequest(CallInfo callInfo, IEndpointClient client, string pathAndQuery)
        {
            // Format the URI to how it's supposed to be
            var uri = new Uri(Gw2WebApiV2Client.UrlBase, $"{client.EndpointPath}{pathAndQuery}");
            var parameterProperties = client.GetType()
                                      .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                      .Where(p => p.GetCustomAttribute <EndpointQueryParameterAttribute>() != null);

            if (parameterProperties.Any())
            {
                var builder = new UriBuilder(uri);
                foreach (var parameter in parameterProperties)
                {
                    var attr  = parameter.GetCustomAttribute <EndpointQueryParameterAttribute>();
                    var value = parameter.GetValue(client);
                    if (value == null)
                    {
                        continue;
                    }

                    string toAppend = $"{attr.ParameterName}={value}";
                    builder.Query = builder.Query != null && builder.Query.Length > 1
                        ? $"{builder.Query.Substring(1)}&{toAppend}"
                        : toAppend;
                }
                uri = builder.Uri;
            }

            Assert.Equal(uri.AbsoluteUri, callInfo.ArgAt <IWebApiRequest>(0).Options.Url.AbsoluteUri);
            var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders;

            Assert.Contains(new KeyValuePair <string, string>("Accept", "application/json"), requestHeaders);
            Assert.Contains(new KeyValuePair <string, string>("User-Agent", ((Gw2WebApiBaseClient)client).Connection.UserAgent), requestHeaders);
        }
コード例 #3
0
 public FileManager(DbManager dbManager, IPreferenceManager preferenceManager, IEndpointClient endpointClient, IFileClient fileClient)
 {
     this.dbManager         = dbManager;
     this.preferenceManager = preferenceManager;
     this.endpointClient    = endpointClient;
     this.fileClient        = fileClient;
 }
コード例 #4
0
        protected virtual void AssertSchemaVersionRequest(CallInfo callInfo, IEndpointClient client)
        {
            var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders;

            if (!string.IsNullOrWhiteSpace(client.SchemaVersion))
            {
                Assert.Contains(new KeyValuePair <string, string>("X-Schema-Version", client.SchemaVersion), requestHeaders);
            }
            else
            {
                Assert.DoesNotContain(requestHeaders, h => h.Key == "X-Schema-Version");
            }
        }
コード例 #5
0
        protected virtual void AssertLocalizedRequest(CallInfo callInfo, IEndpointClient client)
        {
            var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders;

            if (client.IsLocalized)
            {
                Assert.Contains(new KeyValuePair <string, string>("Accept-Language", ((Gw2WebApiBaseClient)client).Connection.LocaleString), requestHeaders);
            }
            else
            {
                Assert.DoesNotContain(requestHeaders, h => h.Key == "Accept-Language");
            }
        }
コード例 #6
0
        protected virtual void AssertAuthenticatedRequest(CallInfo callInfo, IEndpointClient client)
        {
            var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders;

            if (client.IsAuthenticated)
            {
                Assert.Contains(new KeyValuePair <string, string>("Authorization", $"Bearer {((Gw2WebApiBaseClient)client).Connection.AccessToken}"), requestHeaders);
            }
            else
            {
                Assert.DoesNotContain(requestHeaders, h => h.Key == "Authorization");
            }
        }
コード例 #7
0
        public RequestBuilder(IEndpointClient endpointClient, IConnection connection, IGw2Client gw2Client)
        {
            this.baseUrl                   = endpointClient.BaseUrl;
            this.endpointPath              = endpointClient.EndpointPath;
            this.schemaVersion             = endpointClient.SchemaVersion;
            this.bulkQueryParameterIdName  = endpointClient.BulkEndpointIdParameterName;
            this.bulkQueryParameterIdsName = endpointClient.BulkEndpointIdsParameterName;
            this.bulkObjectIdName          = endpointClient.BulkEndpointIdObjectName;
#if NETSTANDARD
            this.queryParams = endpointClient.EndpointQueryParameters.ShallowCopy();
#else
            this.queryParams = endpointClient.EndpointQueryParameters.AsReadOnly();
#endif

            this.connection = connection;
            this.gw2Client  = gw2Client;

            this.authorization = endpointClient.IsAuthenticated ? $"{BEARER} {connection.AccessToken}" : null;
            this.locale        = endpointClient.IsLocalized ? connection.LocaleString : null;
            this.userAgent     = connection.UserAgent;
        }
コード例 #8
0
 public InventoryEndpoint(IEndpointClient client) : base(client)
 {
     feedApi        = new FeedEndpoint(apiClient);
     payloadFactory = new Payload.PayloadFactory();
 }
コード例 #9
0
 public BaseEndpoint(IEndpointClient apiClient)
 {
     this.apiClient = apiClient;
     client         = apiClient.GetHttpHandler();
     config         = apiClient.GetEndpointConfig();
 }
コード例 #10
0
 public FeedEndpoint(IEndpointClient apiClient) : base(apiClient)
 {
     payloadFactory = new Payload.PayloadFactory();
 }
コード例 #11
0
        protected virtual void AssertLocalizedRequest(CallInfo callInfo, IEndpointClient client)
        {
            var requestHeaders = callInfo.ArgAt <IHttpRequest>(0).RequestHeaders;

            Assert.Contains(new KeyValuePair <string, string>("Accept-Language", ((IClientInternal)client).Connection.LocaleString), requestHeaders);
        }
コード例 #12
0
 public PriceEndpoint(IEndpointClient apiClient) : base(apiClient)
 {
     feedApi        = new FeedEndpoint(apiClient);
     payloadFactory = new V2.Payload.PayloadFactory();
 }
コード例 #13
0
 public SigninViewModel(IEndpointClient endpointClient, IPreferenceManager preferenceManager)
 {
     this.endpointClient    = endpointClient;
     this.preferenceManager = preferenceManager;
 }
コード例 #14
0
 public CreateCustomerViewModel(IEndpointClient endpointClient)
 {
     this.endpointClient = endpointClient;
 }
コード例 #15
0
 public AddNewContactViewModel(IEndpointClient endpointClient)
 {
     this.endpointClient = endpointClient;
 }
コード例 #16
0
 /// <summary>
 /// Creates a new base endpoint client.
 /// </summary>
 /// <param name="client">The endpoint client.</param>
 /// <param name="connection">The connection used to make requests, see <see cref="IConnection"/>.</param>
 /// <param name="gw2Client">The Guild Wars 2 client.</param>
 /// <exception cref="ArgumentNullException"><paramref name="client"/>, <paramref name="connection"/> or <paramref name="gw2Client"/> is <c>null</c>.</exception>
 public DefaultEndpointClientImplementation(IEndpointClient client, IConnection connection, IGw2Client gw2Client)
 {
     this.client     = client ?? throw new ArgumentNullException(nameof(client));
     this.Connection = connection ?? throw new ArgumentNullException(nameof(connection));
     this.Gw2Client  = gw2Client ?? throw new ArgumentNullException(nameof(gw2Client));
 }