Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Appwrite/Appwrite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<PackageId>Appwrite</PackageId>
<Version>5.0.0</Version>
<Version>5.1.0</Version>
<Authors>Appwrite Team</Authors>
<Company>Appwrite Team</Company>
<Description>
Expand Down
36 changes: 20 additions & 16 deletions Appwrite/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class Client
public string Endpoint => _endpoint;
public Dictionary<string, string> Config => _config;

public string GetConfig(string key)
{
return _config.TryGetValue(key, out var value) ? value : "";
}

private HttpClient _http;
private HttpClient _httpForRedirect;
private readonly Dictionary<string, string> _headers;
Expand Down Expand Up @@ -71,11 +76,11 @@ public Client(
_headers = new Dictionary<string, string>()
{
{ "content-type", "application/json" },
{ "user-agent" , $"AppwriteDotNetSDK/5.0.0 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
{ "user-agent" , $"AppwriteDotNetSDK/5.1.0 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
{ "x-sdk-name", ".NET" },
{ "x-sdk-platform", "server" },
{ "x-sdk-language", "dotnet" },
{ "x-sdk-version", "5.0.0"},
{ "x-sdk-version", "5.1.0"},
{ "X-Appwrite-Response-Format", "1.9.5" }
};

Expand Down Expand Up @@ -113,86 +118,85 @@ public Client SetEndpoint(string endpoint)

/// <summary>Your project ID</summary>
public Client SetProject(string value) {
_config.Add("project", value);
AddHeader("X-Appwrite-Project", value);
_config["project"] = value;

return this;
}

/// <summary>Your secret API key</summary>
public Client SetKey(string value) {
_config.Add("key", value);
_config["key"] = value;
AddHeader("X-Appwrite-Key", value);

return this;
}

/// <summary>Your secret JSON Web Token</summary>
public Client SetJWT(string value) {
_config.Add("jWT", value);
_config["jWT"] = value;
AddHeader("X-Appwrite-JWT", value);

return this;
}

public Client SetLocale(string value) {
_config.Add("locale", value);
_config["locale"] = value;
AddHeader("X-Appwrite-Locale", value);

return this;
}

/// <summary>The user session to authenticate with</summary>
public Client SetSession(string value) {
_config.Add("session", value);
_config["session"] = value;
AddHeader("X-Appwrite-Session", value);

return this;
}

/// <summary>The user agent string of the client that made the request</summary>
public Client SetForwardedUserAgent(string value) {
_config.Add("forwardedUserAgent", value);
_config["forwardedUserAgent"] = value;
AddHeader("X-Forwarded-User-Agent", value);

return this;
}

/// <summary>Your secret dev API key</summary>
public Client SetDevKey(string value) {
_config.Add("devKey", value);
_config["devKey"] = value;
AddHeader("X-Appwrite-Dev-Key", value);

return this;
}

/// <summary>The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes.</summary>
public Client SetCookie(string value) {
_config.Add("cookie", value);
_config["cookie"] = value;
AddHeader("Cookie", value);

return this;
}

/// <summary>Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.</summary>
public Client SetImpersonateUserId(string value) {
_config.Add("impersonateUserId", value);
_config["impersonateUserId"] = value;
AddHeader("X-Appwrite-Impersonate-User-Id", value);

return this;
}

/// <summary>Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.</summary>
public Client SetImpersonateUserEmail(string value) {
_config.Add("impersonateUserEmail", value);
_config["impersonateUserEmail"] = value;
AddHeader("X-Appwrite-Impersonate-User-Email", value);

return this;
}

/// <summary>Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.</summary>
public Client SetImpersonateUserPhone(string value) {
_config.Add("impersonateUserPhone", value);
_config["impersonateUserPhone"] = value;
AddHeader("X-Appwrite-Impersonate-User-Phone", value);

return this;
Expand All @@ -218,8 +222,8 @@ private HttpRequestMessage PrepareRequest(
{
var methodGet = "GET".Equals(method, StringComparison.OrdinalIgnoreCase);

var queryString = methodGet ?
"?" + parameters.ToQueryString() :
var queryString = methodGet && parameters.Count > 0 ?
(path.Contains("?") ? "&" : "?") + parameters.ToQueryString() :
string.Empty;

var request = new HttpRequestMessage(
Expand Down
4 changes: 2 additions & 2 deletions Appwrite/Converters/ValueClassConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Appwrite.Converters
{
public class ValueClassConverter : JsonConverter<object>
{
public override bool CanConvert(Type objectType)
public override bool CanConvert(System.Type objectType)
{
return typeof(IEnum).IsAssignableFrom(objectType);
}

public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override object Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
var constructor = typeToConvert.GetConstructor(new[] { typeof(string) });
Expand Down
2 changes: 2 additions & 0 deletions Appwrite/Enums/ProjectKeyScopes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public ProjectKeyScopes(string value)
public static ProjectKeyScopes DomainsRead => new ProjectKeyScopes("domains.read");
public static ProjectKeyScopes DomainsWrite => new ProjectKeyScopes("domains.write");
public static ProjectKeyScopes EventsRead => new ProjectKeyScopes("events.read");
public static ProjectKeyScopes AppsRead => new ProjectKeyScopes("apps.read");
public static ProjectKeyScopes AppsWrite => new ProjectKeyScopes("apps.write");
public static ProjectKeyScopes UsageRead => new ProjectKeyScopes("usage.read");
}
}
1 change: 1 addition & 0 deletions Appwrite/Enums/ProjectPolicyId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public ProjectPolicyId(string value)

public static ProjectPolicyId PasswordDictionary => new ProjectPolicyId("password-dictionary");
public static ProjectPolicyId PasswordHistory => new ProjectPolicyId("password-history");
public static ProjectPolicyId PasswordStrength => new ProjectPolicyId("password-strength");
public static ProjectPolicyId PasswordPersonalData => new ProjectPolicyId("password-personal-data");
public static ProjectPolicyId SessionAlert => new ProjectPolicyId("session-alert");
public static ProjectPolicyId SessionDuration => new ProjectPolicyId("session-duration");
Expand Down
26 changes: 26 additions & 0 deletions Appwrite/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ public static string ToQueryString(this Dictionary<string, object?> parameters)
return Uri.EscapeUriString(string.Join("&", query));
}

public static Dictionary<string, string> FromQueryString(this string queryString)
{
var query = new Dictionary<string, string>();
var trimmed = (queryString ?? string.Empty).TrimStart('?');

if (string.IsNullOrEmpty(trimmed))
{
return query;
}

foreach (var pair in trimmed.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries))
{
var parts = pair.Split(new[] { '=' }, 2);
var key = Uri.UnescapeDataString(parts[0]);

if (string.IsNullOrEmpty(key))
{
continue;
}

query[key] = parts.Length > 1 ? Uri.UnescapeDataString(parts[1]) : string.Empty;
}

return query;
}

private static readonly IDictionary<string, string> Mappings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) {

#region Mime Types
Expand Down
6 changes: 3 additions & 3 deletions Appwrite/Models/ActivityEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ActivityEvent(
string resourceType,
string resourceId,
string resource,
string xevent,
string @event,
string userAgent,
string ip,
string mode,
Expand Down Expand Up @@ -151,7 +151,7 @@ string countryName
ResourceType = resourceType;
ResourceId = resourceId;
Resource = resource;
Event = xevent;
Event = @event;
UserAgent = userAgent;
Ip = ip;
Mode = mode;
Expand Down Expand Up @@ -186,7 +186,7 @@ string countryName
resourceType: map["resourceType"].ToString(),
resourceId: map["resourceId"].ToString(),
resource: map["resource"].ToString(),
xevent: map["event"].ToString(),
@event: map["event"].ToString(),
userAgent: map["userAgent"].ToString(),
ip: map["ip"].ToString(),
mode: map["mode"].ToString(),
Expand Down
2 changes: 1 addition & 1 deletion Appwrite/Models/ActivityEventList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ List<ActivityEvent> events

public static ActivityEventList From(Dictionary<string, object> map) => new ActivityEventList(
total: Convert.ToInt64(map["total"]),
events: map["events"].ConvertToList<Dictionary<string, object>>().Select(it => ActivityEvent.From(map: it)).ToList()
events: map["events"].ConvertToList<Dictionary<string, object>>().Select(it => Appwrite.Models.ActivityEvent.From(map: it)).ToList()
);

public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
Expand Down
20 changes: 14 additions & 6 deletions Appwrite/Models/AttributeBigint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AttributeBigint(
string updatedAt,
long? min,
long? max,
long? xdefault
long? @default
)
{
Key = key;
Expand All @@ -68,7 +68,7 @@ public AttributeBigint(
UpdatedAt = updatedAt;
Min = min;
Max = max;
Default = xdefault;
Default = @default;
}

public static AttributeBigint From(Dictionary<string, object> map) => new AttributeBigint(
Expand All @@ -77,12 +77,20 @@ public AttributeBigint(
status: new AttributeStatus(map["status"].ToString()!),
error: map["error"].ToString(),
required: (bool)map["required"],
array: (bool?)map["array"],
array: map.TryGetValue("array", out var boolRaw6) && boolRaw6 != null
? (bool?)boolRaw6
: null,
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
min: map["min"] == null ? null : Convert.ToInt64(map["min"]),
max: map["max"] == null ? null : Convert.ToInt64(map["max"]),
xdefault: map["default"] == null ? null : Convert.ToInt64(map["default"])
min: map.TryGetValue("min", out var numberRaw9) && numberRaw9 != null
? Convert.ToInt64(numberRaw9)
: null,
max: map.TryGetValue("max", out var numberRaw10) && numberRaw10 != null
? Convert.ToInt64(numberRaw10)
: null,
@default: map.TryGetValue("default", out var numberRaw11) && numberRaw11 != null
? Convert.ToInt64(numberRaw11)
: null
);

public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
Expand Down
12 changes: 8 additions & 4 deletions Appwrite/Models/AttributeBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AttributeBoolean(
bool? array,
string createdAt,
string updatedAt,
bool? xdefault
bool? @default
)
{
Key = key;
Expand All @@ -58,7 +58,7 @@ public AttributeBoolean(
Array = array;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Default = xdefault;
Default = @default;
}

public static AttributeBoolean From(Dictionary<string, object> map) => new AttributeBoolean(
Expand All @@ -67,10 +67,14 @@ public AttributeBoolean(
status: new AttributeStatus(map["status"].ToString()!),
error: map["error"].ToString(),
required: (bool)map["required"],
array: (bool?)map["array"],
array: map.TryGetValue("array", out var boolRaw6) && boolRaw6 != null
? (bool?)boolRaw6
: null,
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
xdefault: (bool?)map["default"]
@default: map.TryGetValue("default", out var boolRaw9) && boolRaw9 != null
? (bool?)boolRaw9
: null
);

public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
Expand Down
10 changes: 6 additions & 4 deletions Appwrite/Models/AttributeDatetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AttributeDatetime(
string createdAt,
string updatedAt,
string format,
string? xdefault
string? @default
)
{
Key = key;
Expand All @@ -63,7 +63,7 @@ public AttributeDatetime(
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Format = format;
Default = xdefault;
Default = @default;
}

public static AttributeDatetime From(Dictionary<string, object> map) => new AttributeDatetime(
Expand All @@ -72,11 +72,13 @@ public AttributeDatetime(
status: new AttributeStatus(map["status"].ToString()!),
error: map["error"].ToString(),
required: (bool)map["required"],
array: (bool?)map["array"],
array: map.TryGetValue("array", out var boolRaw6) && boolRaw6 != null
? (bool?)boolRaw6
: null,
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
format: map["format"].ToString(),
xdefault: map.TryGetValue("default", out var xdefault) ? xdefault?.ToString() : null
@default: map.TryGetValue("default", out var @default) ? @default?.ToString() : null
);

public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
Expand Down
10 changes: 6 additions & 4 deletions Appwrite/Models/AttributeEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AttributeEmail(
string createdAt,
string updatedAt,
string format,
string? xdefault
string? @default
)
{
Key = key;
Expand All @@ -63,7 +63,7 @@ public AttributeEmail(
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Format = format;
Default = xdefault;
Default = @default;
}

public static AttributeEmail From(Dictionary<string, object> map) => new AttributeEmail(
Expand All @@ -72,11 +72,13 @@ public AttributeEmail(
status: new AttributeStatus(map["status"].ToString()!),
error: map["error"].ToString(),
required: (bool)map["required"],
array: (bool?)map["array"],
array: map.TryGetValue("array", out var boolRaw6) && boolRaw6 != null
? (bool?)boolRaw6
: null,
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
format: map["format"].ToString(),
xdefault: map.TryGetValue("default", out var xdefault) ? xdefault?.ToString() : null
@default: map.TryGetValue("default", out var @default) ? @default?.ToString() : null
);

public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
Expand Down
Loading
Loading