コード例 #1
0
ファイル: SenseApiClient.cs プロジェクト: Cisien/SenseClient
        private SenseApiClient(SenseClientOptions options)
        {
            _options = options ?? new SenseClientOptions();
            _client  = new HttpClient(_options.Handler, true)
            {
                BaseAddress = new Uri("https://api.sense.com/apiservice/api/v1/")
            };

            _client.DefaultRequestHeaders.UserAgent.Clear();
            var version = GetType().Assembly.GetName().Version.ToString();

            _client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(new ProductHeaderValue(HttpUtility.UrlEncode("https://github.com/cisien/SenseClient"), version)));
            _serializerOptions = new JsonSerializerOptions();
        }
コード例 #2
0
ファイル: SenseApiClient.cs プロジェクト: Cisien/SenseClient
        public static async Task <SenseApiClient> Create(string email, string password, Action <SenseClientOptions>?options = null)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException(nameof(email));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            var clientOptions = new SenseClientOptions();

            if (options != default)
            {
                options(clientOptions);
            }
            var senseClient = new SenseApiClient(clientOptions);
            await senseClient.Authenticate(email, password);

            return(senseClient);
        }