Skip to content

Commit

Permalink
feat: Renamed folders and added LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
Mondonno committed Feb 3, 2022
1 parent ed56442 commit 73c28d8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Airly.Net/Airly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Airly : IDisposable
public AirlyConfiguration Configuration { get; set; } = new AirlyConfiguration();

/// <summary>
/// Used when sending request to API. Specfies in what language the response will return.
/// Used when sending request to API. Specifies in what language the response will return.
/// </summary>
public AirlyLanguage Language {
get => Rest.Language;
Expand Down
File renamed without changes.
File renamed without changes.
34 changes: 15 additions & 19 deletions Airly.Net/utils/Utils.cs → Airly.Net/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ public static string FormatQuery(string query)
.Replace("#", "%23")
.Replace("@", "%40"))));

string Query = constructedQuery.Query;
return Query;
return constructedQuery.Query;
}

public static string GetVersion(int version, bool slash)
{
string sreperator = (slash ? "/" : string.Empty);
return $"{sreperator}v{version}{sreperator}";
string separator = slash ? "/" : string.Empty;
return $"{separator}v{version}{separator}";
}

public class QueryProperty
{
public QueryProperty(string name, object value)
{
this.name = name;
this.value = value;
Name = name;
Value = value;
}

public string name { get; set; }
public object value { get; set; }
public string Name { get; set; }
public object Value { get; set; }
}

public static List<QueryProperty> GetClassProperties<T>(T classObject)
Expand Down Expand Up @@ -72,18 +71,16 @@ public static List<QueryProperty> GetClassProperties<T>(T classObject)

public static bool IsDouble(object obj)
{
double? result;
try
{
result = (double)obj;
_ = (double) obj;
}
catch (InvalidCastException)
{
return false;
}

if (result != null) return true;
else return false;
return true;
}

public static List<List<string>> ParseQuery(dynamic query)
Expand All @@ -101,11 +98,11 @@ public static List<List<string>> ParseQuery(dynamic query)

foreach (var p in properties)
{
string name = p.name;
string name = p.Name;
string value; // Converting the object value to string (without the explict type)

if (IsDouble(p.value)) value = ((double)p.value).ToString(numberInfo);
else value = p.value.ToString();
if (IsDouble(p.Value)) value = ((double)p.Value).ToString(numberInfo);
else value = p.Value.ToString();

List<string> constructedArray = new List<string>() { name, value };
convertedQuery.Add(constructedArray);
Expand All @@ -114,7 +111,7 @@ public static List<List<string>> ParseQuery(dynamic query)
return convertedQuery;
}

public static T GetFirstEnumarable<T>(IEnumerable<T> enumarable) => enumarable.First((e) => true);
public static T GetFirstEnumarable<T>(IEnumerable<T> enumarable) => enumarable.First((_) => true);

public static void ValidateKey(string key)
{
Expand All @@ -123,7 +120,6 @@ public static void ValidateKey(string key)

if (string.IsNullOrEmpty(toValidate) || string.IsNullOrEmpty(validatedKey) || validatedKey != toValidate)
throw new InvalidApiKeyException();
else return;
}

public static string GetRoute(string url)
Expand All @@ -132,7 +128,7 @@ public static string GetRoute(string url)
string[] routes = url.Split('/');

if (routes.Length == 0) return url;
else return routes[0].ToString();
else return routes[0];
}
}

Expand Down Expand Up @@ -254,7 +250,7 @@ public static void ThrowIfInfinity(params double[] numbers)
if (!AreFinity(numbers)) throw new IndexOutOfRangeException("The specified parameters must be finity double");
}

public static bool CheckIfNegativeNumber(int number) => number.ToString().StartsWith("-");
private static bool CheckIfNegativeNumber(int number) => number < 0;

public static void ThrowIfNegativeNumber(int number)
{
Expand Down
2 changes: 1 addition & 1 deletion Airly.Net/common/AirlyConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class AirlyEndpoints
}

/// <summary>
/// Airly Configuration, used if you want to change the deafult settings.
/// Airly Configuration, used if you want to change the default settings.
/// </summary>
public sealed class AirlyConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions Airly.Net/interactions/structures/Installations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public async Task<AirInstallation> Info(int id, bool redirect = false) {
AirInstallation installationData;
try
{
installationData = await Info(id);
installationData = await Info(id); // not recursive because passing redirect = false;
}
catch(ElementPermentlyReplacedException error)
{
var newSuccesor = (int?) error.Data["succesorId"]; // null is begin handled in the RequestQueuer
var newInstallationData = await Info((int) newSuccesor);
var newInstallationData = await Info((int) newSuccesor); // not recursive because passing redirect = false;

return newInstallationData;
}
Expand Down
12 changes: 6 additions & 6 deletions Airly.Net/rest/api/RequestModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DefaultRestRequest : IRequest, IDisposable

public Uri RequestUri { get; set; }
private string RawUrl {
get => RawUrl;
get => RequestUri.AbsoluteUri;
set => RequestUri = new Uri(value);
}
private string RawMethod {
Expand Down Expand Up @@ -91,19 +91,19 @@ public async Task<RawRestResponse> Send()
double requestTimeout = restTimeout == 0 ? 60000 : restTimeout;

HttpClient.Timeout = TimeSpan.FromMilliseconds(requestTimeout);

HttpRequestMessage RequestMessage = new(Method, RequestUri);
HttpRequestMessage requestMessage = new(Method, RequestUri);
if(RestOptions.Body != null)
{
StringContent content = new StringContent(RestOptions.Body.ToString(), Encoding.UTF8, "application/json");
RequestMessage.Content = content;
requestMessage.Content = content;
}

HttpResponseMessage httpResponse = await HttpClient.SendAsync(RequestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None); // Error (capture)
HttpResponseMessage httpResponse = await HttpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None); // Error (capture)
string httpContent = await httpResponse.Content.ReadAsStringAsync();

httpResponse.Dispose();
RequestMessage.Dispose();
requestMessage.Dispose();

RawRestResponse restResponse = new(httpResponse, httpContent);
return restResponse;
Expand Down
5 changes: 1 addition & 4 deletions Airly.Net/rest/queue/RequestQueuer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private async Task<RestResponse> Make(RestRequest request)
else if (succesor != null) {
throw new ElementPermentlyReplacedException(succesor.ToString(), "New succesor found");
}
else throw new HttpException("301 thrown but isn't begin handled");
}

string rawJson = res.RawJson;
Expand All @@ -130,10 +129,8 @@ private async Task<RestResponse> Make(RestRequest request)

var convertedJson = ConvertJsonString(rawJson);
bool jsonValidCheck = !string.IsNullOrEmpty(convertedJson.ToString());

if (jsonValidCheck) return constructedResponse;
else if(!jsonValidCheck)
throw new HttpException("Returned JSON is null or empty");

ThrowIfJsonError(res.HttpResponse, res.RawJson);
return null; // Fallback value (when all other statments do not react with the response)
Expand Down
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2022 Mondonno

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

0 comments on commit 73c28d8

Please sign in to comment.