public Subscriber(AjusteeConnectionSettings settings, ReceiveCallbackHandler receiveCallback, DeletedCallbackHandler deletedCallback) : base() { Settings = settings; m_ReceiveCallback = receiveCallback; m_DeletedCallback = deletedCallback; }
public static void ValidateResponseStatus(int statusCode, AjusteeConnectionSettings settings, Exception innerException) { switch (statusCode) { case 400: // Bad Request throw Error.InvalidRequest(); case 401: // Unauthorized throw Error.InvalidApplication(settings.ApplicationId); case 402: // Payment Required throw Error.ReachedLimit(); case 403: // Forbidden throw Error.Forbidden(); case 404: // Not Found throw Error.NotFound("Key path"); case 503: // Service Unavailable throw Error.InvalidApiUrl(settings.ApiUrl); default: if (statusCode > 404) { throw Error.Unknown(innerException); } break; } }
private static WebRequest CreateGetRequest(AjusteeConnectionSettings settings, string path, IDictionary <string, string> properties) { // Creates get http request with api url and specified configuration path. var _request = WebRequest.Create(GetConfigurationKeysUrl(settings.ApiUrl, path ?? settings.DefaultPath)); // Sets method name. _request.Method = "GET"; // Adds headers of specify customers. _request.Headers.Add(AppIdName, settings.ApplicationId); // Validate properties. ValidateProperties(settings.DefaultProperties); ValidateProperties(properties); // Gets merged properties properties = GetMergedProperties(settings.TrackerId == null ? null : new Dictionary <string, string> { { TrackerIdName, FormatPropertyValue(settings.TrackerId) } }, settings.DefaultProperties, properties); // Adds the specified properties to the request message. if (properties != null) { foreach (var _property in properties) { _request.Headers.Add(_property.Key, _property.Value); } } return(_request); }
public async Task UpdateAsync(AjusteeConnectionSettings settings, string path, string value, CancellationToken cancellationToken = default) { // Initializes http client instance. m_Client = new HttpClient(); // Create message and send to a server. m_Response = await m_Client.SendAsync(CreateUpdateRequestMessage(settings, path, value)); // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)m_Response.StatusCode, settings, null); }
public void Update(AjusteeConnectionSettings settings, string path, string value) { // Initializes http client instance. m_Client = new HttpClient(); // Create message and send to a server. m_Response = m_Client.SendAsync(CreateUpdateRequestMessage(settings, path, value)).GetAwaiter().GetResult(); // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)m_Response.StatusCode, settings, null); }
private static WebRequest CreateUpdatRequest(AjusteeConnectionSettings settings, string path) { // Creates get http request with api url and specified configuration path. var _request = WebRequest.Create(GetUpdateUrl(settings.ApiUrl, path)); // Sets method name. _request.Method = "PUT"; // Adds headers of specify customers. _request.Headers.Add(AppIdName, settings.ApplicationId); _request.ContentType = "application/json"; return(_request); }
public async System.Threading.Tasks.Task <Stream> GetStreamAsync(AjusteeConnectionSettings settings, string path, IDictionary <string, string> properties, System.Threading.CancellationToken cancellationToken = default) { // Creates request. m_Request = CreateGetRequest(settings, path, properties); // Gets response. m_Response = await m_Request.GetResponseAsync(); // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)((HttpWebResponse)m_Response).StatusCode, settings, null); // Returns response's stream. return(m_Response.GetResponseStream()); }
public async Task <Stream> GetStreamAsync(AjusteeConnectionSettings settings, string path, IDictionary <string, string> properties, CancellationToken cancellationToken = default) { // Initializes http client istance. m_Client = new HttpClient(); // Create message and send to a server. m_Response = await m_Client.SendAsync(CreateGetRequestMessage(settings, path, properties)); // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)m_Response.StatusCode, settings, null); // Returns streamed payload of the configurations. return(await m_Response.Content.ReadAsStreamAsync()); }
private static HttpRequestMessage CreateUpdateRequestMessage(AjusteeConnectionSettings settings, string path, string value) { // Creates get http request with api url and specified configuration path. var _message = new HttpRequestMessage(HttpMethod.Put, GetUpdateUrl(settings.ApiUrl, path)); // Adds headers of specify customers. _message.Headers.Add(AppIdName, settings.ApplicationId); if (settings.TrackerId != null) { _message.Headers.Add(TrackerIdName, FormatPropertyValue(settings.TrackerId)); } // Sets update value payload. _message.Content = new StringContent(JsonSerializer.Serialize(new RequestUpdateContent(value)), MessageEncoding, "application/json"); return(_message); }
public Stream GetStream(AjusteeConnectionSettings settings, string path, IDictionary <string, string> properties) { // Creates request. m_Request = CreateGetRequest(settings, path, properties); try { // Gets response. m_Response = m_Request.GetResponse(); } catch (WebException _ex) { // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)((HttpWebResponse)_ex.Response).StatusCode, settings, _ex); } // Returns response's stream. return(m_Response.GetResponseStream()); }
public async System.Threading.Tasks.Task UpdateAsync(AjusteeConnectionSettings settings, string path, string value, System.Threading.CancellationToken cancellationToken = default) { // Creates request. m_Request = CreateUpdatRequest(settings, path); // Sets update value payload. JsonSerializer.Serialize(new RequestUpdateContent(value), await m_Request.GetRequestStreamAsync()); try { // Gets response. m_Response = await m_Request.GetResponseAsync(); } catch (WebException _ex) { // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)((HttpWebResponse)_ex.Response).StatusCode, settings, _ex); } }
public void Update(AjusteeConnectionSettings settings, string path, string value) { // Creates request. m_Request = CreateUpdatRequest(settings, path); // Sets update value payload. JsonSerializer.Serialize(new RequestUpdateContent(value), m_Request.GetRequestStream()); try { // Gets response. m_Response = m_Request.GetResponse(); } catch (WebException _ex) { // Validate status code, throw exception if it is not success. ValidateResponseStatus((int)((HttpWebResponse)_ex.Response).StatusCode, settings, _ex); } }
public FakeAjusteeClient(AjusteeConnectionSettings settings) : base(settings) { ATL.Enabled = true; }
/// <summary> /// Initializes a new instance of the class <see cref="AjusteeClient"/> class. /// <paramref name="settings">Client connection settings.</paramref> /// </summary> public AjusteeClient(AjusteeConnectionSettings settings) : base() { Settings = settings ?? throw new ArgumentException(nameof(settings)); }