/* Code generated by openapi-gen/main.go. DO NOT EDIT. */
using UnityEngine;
namespace Nakama
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using TinyJson;
///
/// An exception generated for HttpResponse objects don't return a success status.
///
public sealed class ApiResponseException : Exception
{
public HttpStatusCode StatusCode { get; }
public int GrpcStatusCode { get; }
public ApiResponseException(HttpStatusCode statusCode, string content, int grpcCode) : base(content)
{
StatusCode = statusCode;
GrpcStatusCode = grpcCode;
}
public override string ToString()
{
return
$"ApiResponseException(StatusCode={StatusCode}, Message='{Message}', GrpcStatusCode={GrpcStatusCode})";
}
}
///
/// A single user-role pair.
///
public interface IGroupUserListGroupUser
{
///
/// Their relationship to the group.
///
int State { get; }
///
/// User.
///
IApiUser User { get; }
}
///
internal class GroupUserListGroupUser : IGroupUserListGroupUser
{
///
[DataMember(Name = "state")]
public int State { get; set; }
///
public IApiUser User => _user;
[DataMember(Name = "user")] public ApiUser _user { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "State: ", State, ", ");
output = string.Concat(output, "User: ", User, ", ");
return output;
}
}
///
/// A single group-role pair.
///
public interface IUserGroupListUserGroup
{
///
/// Group.
///
IApiGroup Group { get; }
///
/// The user's relationship to the group.
///
int State { get; }
}
///
internal class UserGroupListUserGroup : IUserGroupListUserGroup
{
///
public IApiGroup Group => _group;
[DataMember(Name = "group")] public ApiGroup _group { get; set; }
///
[DataMember(Name = "state")]
public int State { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Group: ", Group, ", ");
output = string.Concat(output, "State: ", State, ", ");
return output;
}
}
///
/// Record values to write.
///
public interface IWriteLeaderboardRecordRequestLeaderboardRecordWrite
{
///
/// Optional record metadata.
///
string Metadata { get; }
///
/// The score value to submit.
///
string Score { get; }
///
/// An optional secondary value.
///
string Subscore { get; }
}
///
internal class
WriteLeaderboardRecordRequestLeaderboardRecordWrite : IWriteLeaderboardRecordRequestLeaderboardRecordWrite
{
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "score")]
public string Score { get; set; }
///
[DataMember(Name = "subscore")]
public string Subscore { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "Score: ", Score, ", ");
output = string.Concat(output, "Subscore: ", Subscore, ", ");
return output;
}
}
///
/// Record values to write.
///
public interface IWriteTournamentRecordRequestTournamentRecordWrite
{
///
/// A JSON object of additional properties (optional).
///
string Metadata { get; }
///
/// The score value to submit.
///
string Score { get; }
///
/// An optional secondary value.
///
string Subscore { get; }
}
///
internal class
WriteTournamentRecordRequestTournamentRecordWrite : IWriteTournamentRecordRequestTournamentRecordWrite
{
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "score")]
public string Score { get; set; }
///
[DataMember(Name = "subscore")]
public string Subscore { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "Score: ", Score, ", ");
output = string.Concat(output, "Subscore: ", Subscore, ", ");
return output;
}
}
///
/// A user with additional account details. Always the current user.
///
public interface IApiAccount
{
///
/// The custom id in the user's account.
///
string CustomId { get; }
///
/// The devices which belong to the user's account.
///
IEnumerable Devices { get; }
///
/// The email address of the user.
///
string Email { get; }
///
/// The user object.
///
IApiUser User { get; }
///
/// The UNIX time when the user's email was verified.
///
string VerifyTime { get; }
///
/// The user's wallet data.
///
string Wallet { get; }
}
///
internal class ApiAccount : IApiAccount
{
///
[DataMember(Name = "custom_id")]
public string CustomId { get; set; }
///
public IEnumerable Devices => _devices ?? new List(0);
[DataMember(Name = "devices")] public List _devices { get; set; }
///
[DataMember(Name = "email")]
public string Email { get; set; }
///
public IApiUser User => _user;
[DataMember(Name = "user")] public ApiUser _user { get; set; }
///
[DataMember(Name = "verify_time")]
public string VerifyTime { get; set; }
///
[DataMember(Name = "wallet")]
public string Wallet { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "CustomId: ", CustomId, ", ");
output = string.Concat(output, "Devices: [", string.Join(", ", Devices), "], ");
output = string.Concat(output, "Email: ", Email, ", ");
output = string.Concat(output, "User: ", User, ", ");
output = string.Concat(output, "VerifyTime: ", VerifyTime, ", ");
output = string.Concat(output, "Wallet: ", Wallet, ", ");
return output;
}
}
///
/// Send a custom ID to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountCustom
{
///
/// A custom identifier.
///
string Id { get; }
}
///
internal class ApiAccountCustom : IApiAccountCustom
{
///
[DataMember(Name = "id")]
public string Id { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Id: ", Id, ", ");
return output;
}
}
///
/// Send a device to the server. Used with authenticate/link/unlink and user.
///
public interface IApiAccountDevice
{
///
/// A device identifier. Should be obtained by a platform-specific device API.
///
string Id { get; }
}
///
internal class ApiAccountDevice : IApiAccountDevice
{
///
[DataMember(Name = "id")]
public string Id { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Id: ", Id, ", ");
return output;
}
}
///
/// Send an email with password to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountEmail
{
///
/// A valid RFC-5322 email address.
///
string Email { get; }
///
/// A password for the user account.
///
string Password { get; }
}
///
internal class ApiAccountEmail : IApiAccountEmail
{
///
[DataMember(Name = "email")]
public string Email { get; set; }
///
[DataMember(Name = "password")]
public string Password { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Email: ", Email, ", ");
output = string.Concat(output, "Password: ", Password, ", ");
return output;
}
}
///
/// Send a Facebook token to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountFacebook
{
///
/// The OAuth token received from Facebook to access their profile API.
///
string Token { get; }
}
///
internal class ApiAccountFacebook : IApiAccountFacebook
{
///
[DataMember(Name = "token")]
public string Token { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Token: ", Token, ", ");
return output;
}
}
///
/// Send Apple's Game Center account credentials to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountGameCenter
{
///
/// Bundle ID (generated by GameCenter).
///
string BundleId { get; }
///
/// Player ID (generated by GameCenter).
///
string PlayerId { get; }
///
/// The URL for the public encryption key.
///
string PublicKeyUrl { get; }
///
/// A random "NSString" used to compute the hash and keep it randomized.
///
string Salt { get; }
///
/// The verification signature data generated.
///
string Signature { get; }
///
/// Time since UNIX epoch when the signature was created.
///
string TimestampSeconds { get; }
}
///
internal class ApiAccountGameCenter : IApiAccountGameCenter
{
///
[DataMember(Name = "bundle_id")]
public string BundleId { get; set; }
///
[DataMember(Name = "player_id")]
public string PlayerId { get; set; }
///
[DataMember(Name = "public_key_url")]
public string PublicKeyUrl { get; set; }
///
[DataMember(Name = "salt")]
public string Salt { get; set; }
///
[DataMember(Name = "signature")]
public string Signature { get; set; }
///
[DataMember(Name = "timestamp_seconds")]
public string TimestampSeconds { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "BundleId: ", BundleId, ", ");
output = string.Concat(output, "PlayerId: ", PlayerId, ", ");
output = string.Concat(output, "PublicKeyUrl: ", PublicKeyUrl, ", ");
output = string.Concat(output, "Salt: ", Salt, ", ");
output = string.Concat(output, "Signature: ", Signature, ", ");
output = string.Concat(output, "TimestampSeconds: ", TimestampSeconds, ", ");
return output;
}
}
///
/// Send a Google token to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountGoogle
{
///
/// The OAuth token received from Google to access their profile API.
///
string Token { get; }
}
///
internal class ApiAccountGoogle : IApiAccountGoogle
{
///
[DataMember(Name = "token")]
public string Token { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Token: ", Token, ", ");
return output;
}
}
///
/// Send a Steam token to the server. Used with authenticate/link/unlink.
///
public interface IApiAccountSteam
{
///
/// The account token received from Steam to access their profile API.
///
string Token { get; }
}
///
internal class ApiAccountSteam : IApiAccountSteam
{
///
[DataMember(Name = "token")]
public string Token { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Token: ", Token, ", ");
return output;
}
}
///
/// A message sent on a channel.
///
public interface IApiChannelMessage
{
///
/// The channel this message belongs to.
///
string ChannelId { get; }
///
/// The code representing a message type or category.
///
int Code { get; }
///
/// The content payload.
///
string Content { get; }
///
/// The UNIX time when the message was created.
///
string CreateTime { get; }
///
/// The unique ID of this message.
///
string MessageId { get; }
///
/// True if the message was persisted to the channel's history, false otherwise.
///
bool Persistent { get; }
///
/// Message sender, usually a user ID.
///
string SenderId { get; }
///
/// The UNIX time when the message was last updated.
///
string UpdateTime { get; }
///
/// The username of the message sender, if any.
///
string Username { get; }
}
///
internal class ApiChannelMessage : IApiChannelMessage
{
///
[DataMember(Name = "channel_id")]
public string ChannelId { get; set; }
///
[DataMember(Name = "code")]
public int Code { get; set; }
///
[DataMember(Name = "content")]
public string Content { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "message_id")]
public string MessageId { get; set; }
///
[DataMember(Name = "persistent")]
public bool Persistent { get; set; }
///
[DataMember(Name = "sender_id")]
public string SenderId { get; set; }
///
[DataMember(Name = "update_time")]
public string UpdateTime { get; set; }
///
[DataMember(Name = "username")]
public string Username { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "ChannelId: ", ChannelId, ", ");
output = string.Concat(output, "Code: ", Code, ", ");
output = string.Concat(output, "Content: ", Content, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "MessageId: ", MessageId, ", ");
output = string.Concat(output, "Persistent: ", Persistent, ", ");
output = string.Concat(output, "SenderId: ", SenderId, ", ");
output = string.Concat(output, "UpdateTime: ", UpdateTime, ", ");
output = string.Concat(output, "Username: ", Username, ", ");
return output;
}
}
///
/// A list of channel messages, usually a result of a list operation.
///
public interface IApiChannelMessageList
{
///
/// A list of messages.
///
IEnumerable Messages { get; }
///
/// The cursor to send when retireving the next page, if any.
///
string NextCursor { get; }
///
/// The cursor to send when retrieving the previous page, if any.
///
string PrevCursor { get; }
}
///
internal class ApiChannelMessageList : IApiChannelMessageList
{
///
public IEnumerable Messages => _messages ?? new List(0);
[DataMember(Name = "messages")] public List _messages { get; set; }
///
[DataMember(Name = "next_cursor")]
public string NextCursor { get; set; }
///
[DataMember(Name = "prev_cursor")]
public string PrevCursor { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Messages: [", string.Join(", ", Messages), "], ");
output = string.Concat(output, "NextCursor: ", NextCursor, ", ");
output = string.Concat(output, "PrevCursor: ", PrevCursor, ", ");
return output;
}
}
///
/// Create a group with the current user as owner.
///
public interface IApiCreateGroupRequest
{
///
/// A URL for an avatar image.
///
string AvatarUrl { get; }
///
/// A description for the group.
///
string Description { get; }
///
/// The language expected to be a tag which follows the BCP-47 spec.
///
string LangTag { get; }
///
/// A unique name for the group.
///
string Name { get; }
///
/// Mark a group as open or not where only admins can accept members.
///
bool Open { get; }
}
///
internal class ApiCreateGroupRequest : IApiCreateGroupRequest
{
///
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
///
[DataMember(Name = "description")]
public string Description { get; set; }
///
[DataMember(Name = "lang_tag")]
public string LangTag { get; set; }
///
[DataMember(Name = "name")]
public string Name { get; set; }
///
[DataMember(Name = "open")]
public bool Open { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "AvatarUrl: ", AvatarUrl, ", ");
output = string.Concat(output, "Description: ", Description, ", ");
output = string.Concat(output, "LangTag: ", LangTag, ", ");
output = string.Concat(output, "Name: ", Name, ", ");
output = string.Concat(output, "Open: ", Open, ", ");
return output;
}
}
///
/// Storage objects to delete.
///
public interface IApiDeleteStorageObjectId
{
///
/// The collection which stores the object.
///
string Collection { get; }
///
/// The key of the object within the collection.
///
string Key { get; }
///
/// The version hash of the object.
///
string Version { get; }
}
///
internal class ApiDeleteStorageObjectId : IApiDeleteStorageObjectId
{
///
[DataMember(Name = "collection")]
public string Collection { get; set; }
///
[DataMember(Name = "key")]
public string Key { get; set; }
///
[DataMember(Name = "version")]
public string Version { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Collection: ", Collection, ", ");
output = string.Concat(output, "Key: ", Key, ", ");
output = string.Concat(output, "Version: ", Version, ", ");
return output;
}
}
///
/// Batch delete storage objects.
///
public interface IApiDeleteStorageObjectsRequest
{
///
/// Batch of storage objects.
///
IEnumerable ObjectIds { get; }
}
///
internal class ApiDeleteStorageObjectsRequest : IApiDeleteStorageObjectsRequest
{
///
public IEnumerable ObjectIds => _objectIds ?? new List(0);
[DataMember(Name = "object_ids")] public List _objectIds { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "ObjectIds: [", string.Join(", ", ObjectIds), "], ");
return output;
}
}
///
/// A friend of a user.
///
public interface IApiFriend
{
///
/// The friend status.
///
int State { get; }
///
/// The user object.
///
IApiUser User { get; }
}
///
internal class ApiFriend : IApiFriend
{
///
[DataMember(Name = "state")]
public int State { get; set; }
///
public IApiUser User => _user;
[DataMember(Name = "user")] public ApiUser _user { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "State: ", State, ", ");
output = string.Concat(output, "User: ", User, ", ");
return output;
}
}
///
/// A collection of zero or more friends of the user.
///
public interface IApiFriends
{
///
/// The Friend objects.
///
IEnumerable Friends { get; }
}
///
internal class ApiFriends : IApiFriends
{
///
public IEnumerable Friends => _friends ?? new List(0);
[DataMember(Name = "friends")] public List _friends { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Friends: [", string.Join(", ", Friends), "], ");
return output;
}
}
///
/// A group in the server.
///
public interface IApiGroup
{
///
/// A URL for an avatar image.
///
string AvatarUrl { get; }
///
/// The UNIX time when the group was created.
///
string CreateTime { get; }
///
/// The id of the user who created the group.
///
string CreatorId { get; }
///
/// A description for the group.
///
string Description { get; }
///
/// The current count of all members in the group.
///
int EdgeCount { get; }
///
/// The id of a group.
///
string Id { get; }
///
/// The language expected to be a tag which follows the BCP-47 spec.
///
string LangTag { get; }
///
/// The maximum number of members allowed.
///
int MaxCount { get; }
///
/// Additional information stored as a JSON object.
///
string Metadata { get; }
///
/// The unique name of the group.
///
string Name { get; }
///
/// Anyone can join open groups, otherwise only admins can accept members.
///
bool Open { get; }
///
/// The UNIX time when the group was last updated.
///
string UpdateTime { get; }
}
///
internal class ApiGroup : IApiGroup
{
///
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "creator_id")]
public string CreatorId { get; set; }
///
[DataMember(Name = "description")]
public string Description { get; set; }
///
[DataMember(Name = "edge_count")]
public int EdgeCount { get; set; }
///
[DataMember(Name = "id")]
public string Id { get; set; }
///
[DataMember(Name = "lang_tag")]
public string LangTag { get; set; }
///
[DataMember(Name = "max_count")]
public int MaxCount { get; set; }
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "name")]
public string Name { get; set; }
///
[DataMember(Name = "open")]
public bool Open { get; set; }
///
[DataMember(Name = "update_time")]
public string UpdateTime { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "AvatarUrl: ", AvatarUrl, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "CreatorId: ", CreatorId, ", ");
output = string.Concat(output, "Description: ", Description, ", ");
output = string.Concat(output, "EdgeCount: ", EdgeCount, ", ");
output = string.Concat(output, "Id: ", Id, ", ");
output = string.Concat(output, "LangTag: ", LangTag, ", ");
output = string.Concat(output, "MaxCount: ", MaxCount, ", ");
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "Name: ", Name, ", ");
output = string.Concat(output, "Open: ", Open, ", ");
output = string.Concat(output, "UpdateTime: ", UpdateTime, ", ");
return output;
}
}
///
/// One or more groups returned from a listing operation.
///
public interface IApiGroupList
{
///
/// A cursor used to get the next page.
///
string Cursor { get; }
///
/// One or more groups.
///
IEnumerable Groups { get; }
}
///
internal class ApiGroupList : IApiGroupList
{
///
[DataMember(Name = "cursor")]
public string Cursor { get; set; }
///
public IEnumerable Groups => _groups ?? new List(0);
[DataMember(Name = "groups")] public List _groups { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Cursor: ", Cursor, ", ");
output = string.Concat(output, "Groups: [", string.Join(", ", Groups), "], ");
return output;
}
}
///
/// A list of users belonging to a group, along with their role.
///
public interface IApiGroupUserList
{
///
/// User-role pairs for a group.
///
IEnumerable GroupUsers { get; }
}
///
internal class ApiGroupUserList : IApiGroupUserList
{
///
public IEnumerable GroupUsers => _groupUsers ?? new List(0);
[DataMember(Name = "group_users")] public List _groupUsers { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "GroupUsers: [", string.Join(", ", GroupUsers), "], ");
return output;
}
}
///
/// Represents a complete leaderboard record with all scores and associated metadata.
///
public interface IApiLeaderboardRecord
{
///
/// The UNIX time when the leaderboard record was created.
///
string CreateTime { get; }
///
/// The UNIX time when the leaderboard record expires.
///
string ExpiryTime { get; }
///
/// The ID of the leaderboard this score belongs to.
///
string LeaderboardId { get; }
///
/// The maximum number of score updates allowed by the owner.
///
int MaxNumScore { get; }
///
/// Metadata.
///
string Metadata { get; }
///
/// The number of submissions to this score record.
///
int NumScore { get; }
///
/// The ID of the score owner, usually a user or group.
///
string OwnerId { get; }
///
/// The rank of this record.
///
string Rank { get; }
///
/// The score value.
///
string Score { get; }
///
/// An optional subscore value.
///
string Subscore { get; }
///
/// The UNIX time when the leaderboard record was updated.
///
string UpdateTime { get; }
///
/// The username of the score owner, if the owner is a user.
///
string Username { get; }
}
///
internal class ApiLeaderboardRecord : IApiLeaderboardRecord
{
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "expiry_time")]
public string ExpiryTime { get; set; }
///
[DataMember(Name = "leaderboard_id")]
public string LeaderboardId { get; set; }
///
[DataMember(Name = "max_num_score")]
public int MaxNumScore { get; set; }
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "num_score")]
public int NumScore { get; set; }
///
[DataMember(Name = "owner_id")]
public string OwnerId { get; set; }
///
[DataMember(Name = "rank")]
public string Rank { get; set; }
///
[DataMember(Name = "score")]
public string Score { get; set; }
///
[DataMember(Name = "subscore")]
public string Subscore { get; set; }
///
[DataMember(Name = "update_time")]
public string UpdateTime { get; set; }
///
[DataMember(Name = "username")]
public string Username { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "ExpiryTime: ", ExpiryTime, ", ");
output = string.Concat(output, "LeaderboardId: ", LeaderboardId, ", ");
output = string.Concat(output, "MaxNumScore: ", MaxNumScore, ", ");
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "NumScore: ", NumScore, ", ");
output = string.Concat(output, "OwnerId: ", OwnerId, ", ");
output = string.Concat(output, "Rank: ", Rank, ", ");
output = string.Concat(output, "Score: ", Score, ", ");
output = string.Concat(output, "Subscore: ", Subscore, ", ");
output = string.Concat(output, "UpdateTime: ", UpdateTime, ", ");
output = string.Concat(output, "Username: ", Username, ", ");
return output;
}
}
///
/// A set of leaderboard records, may be part of a leaderboard records page or a batch of individual records.
///
public interface IApiLeaderboardRecordList
{
///
/// The cursor to send when retireving the next page, if any.
///
string NextCursor { get; }
///
/// A batched set of leaderobard records belonging to specified owners.
///
IEnumerable OwnerRecords { get; }
///
/// The cursor to send when retrieving the previous page, if any.
///
string PrevCursor { get; }
///
/// A list of leaderboard records.
///
IEnumerable Records { get; }
}
///
internal class ApiLeaderboardRecordList : IApiLeaderboardRecordList
{
///
[DataMember(Name = "next_cursor")]
public string NextCursor { get; set; }
///
public IEnumerable OwnerRecords => _ownerRecords ?? new List(0);
[DataMember(Name = "owner_records")] public List _ownerRecords { get; set; }
///
[DataMember(Name = "prev_cursor")]
public string PrevCursor { get; set; }
///
public IEnumerable Records => _records ?? new List(0);
[DataMember(Name = "records")] public List _records { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "NextCursor: ", NextCursor, ", ");
output = string.Concat(output, "OwnerRecords: [", string.Join(", ", OwnerRecords), "], ");
output = string.Concat(output, "PrevCursor: ", PrevCursor, ", ");
output = string.Concat(output, "Records: [", string.Join(", ", Records), "], ");
return output;
}
}
///
/// Represents a realtime match.
///
public interface IApiMatch
{
///
/// True if it's an server-managed authoritative match, false otherwise.
///
bool Authoritative { get; }
///
/// Match label, if any.
///
string Label { get; }
///
/// The ID of the match, can be used to join.
///
string MatchId { get; }
///
/// Current number of users in the match.
///
int Size { get; }
}
///
internal class ApiMatch : IApiMatch
{
///
[DataMember(Name = "authoritative")]
public bool Authoritative { get; set; }
///
[DataMember(Name = "label")]
public string Label { get; set; }
///
[DataMember(Name = "match_id")]
public string MatchId { get; set; }
///
[DataMember(Name = "size")]
public int Size { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Authoritative: ", Authoritative, ", ");
output = string.Concat(output, "Label: ", Label, ", ");
output = string.Concat(output, "MatchId: ", MatchId, ", ");
output = string.Concat(output, "Size: ", Size, ", ");
return output;
}
}
///
/// A list of realtime matches.
///
public interface IApiMatchList
{
///
/// A number of matches corresponding to a list operation.
///
IEnumerable Matches { get; }
}
///
internal class ApiMatchList : IApiMatchList
{
///
public IEnumerable Matches => _matches ?? new List(0);
[DataMember(Name = "matches")] public List _matches { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Matches: [", string.Join(", ", Matches), "], ");
return output;
}
}
///
/// A notification in the server.
///
public interface IApiNotification
{
///
/// Category code for this notification.
///
int Code { get; }
///
/// Content of the notification in JSON.
///
string Content { get; }
///
/// The UNIX time when the notification was created.
///
string CreateTime { get; }
///
/// ID of the Notification.
///
string Id { get; }
///
/// True if this notification was persisted to the database.
///
bool Persistent { get; }
///
/// ID of the sender, if a user. Otherwise 'null'.
///
string SenderId { get; }
///
/// Subject of the notification.
///
string Subject { get; }
}
///
internal class ApiNotification : IApiNotification
{
///
[DataMember(Name = "code")]
public int Code { get; set; }
///
[DataMember(Name = "content")]
public string Content { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "id")]
public string Id { get; set; }
///
[DataMember(Name = "persistent")]
public bool Persistent { get; set; }
///
[DataMember(Name = "sender_id")]
public string SenderId { get; set; }
///
[DataMember(Name = "subject")]
public string Subject { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Code: ", Code, ", ");
output = string.Concat(output, "Content: ", Content, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "Id: ", Id, ", ");
output = string.Concat(output, "Persistent: ", Persistent, ", ");
output = string.Concat(output, "SenderId: ", SenderId, ", ");
output = string.Concat(output, "Subject: ", Subject, ", ");
return output;
}
}
///
/// A collection of zero or more notifications.
///
public interface IApiNotificationList
{
///
/// Use this cursor to paginate notifications. Cache this to catch up to new notifications.
///
string CacheableCursor { get; }
///
/// Collection of notifications.
///
IEnumerable Notifications { get; }
}
///
internal class ApiNotificationList : IApiNotificationList
{
///
[DataMember(Name = "cacheable_cursor")]
public string CacheableCursor { get; set; }
///
public IEnumerable Notifications => _notifications ?? new List(0);
[DataMember(Name = "notifications")] public List _notifications { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "CacheableCursor: ", CacheableCursor, ", ");
output = string.Concat(output, "Notifications: [", string.Join(", ", Notifications), "], ");
return output;
}
}
///
/// Storage objects to get.
///
public interface IApiReadStorageObjectId
{
///
/// The collection which stores the object.
///
string Collection { get; }
///
/// The key of the object within the collection.
///
string Key { get; }
///
/// The user owner of the object.
///
string UserId { get; }
}
///
internal class ApiReadStorageObjectId : IApiReadStorageObjectId
{
///
[DataMember(Name = "collection")]
public string Collection { get; set; }
///
[DataMember(Name = "key")]
public string Key { get; set; }
///
[DataMember(Name = "user_id")]
public string UserId { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Collection: ", Collection, ", ");
output = string.Concat(output, "Key: ", Key, ", ");
output = string.Concat(output, "UserId: ", UserId, ", ");
return output;
}
}
///
/// Batch get storage objects.
///
public interface IApiReadStorageObjectsRequest
{
///
/// Batch of storage objects.
///
IEnumerable ObjectIds { get; }
}
///
internal class ApiReadStorageObjectsRequest : IApiReadStorageObjectsRequest
{
///
public IEnumerable ObjectIds => _objectIds ?? new List(0);
[DataMember(Name = "object_ids")] public List _objectIds { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "ObjectIds: [", string.Join(", ", ObjectIds), "], ");
return output;
}
}
///
/// Execute an Lua function on the server.
///
public interface IApiRpc
{
///
/// The authentication key used when executed as a non-client HTTP request.
///
string HttpKey { get; }
///
/// The identifier of the function.
///
string Id { get; }
///
/// The payload of the function which must be a JSON object.
///
string Payload { get; }
}
///
internal class ApiRpc : IApiRpc
{
///
[DataMember(Name = "http_key")]
public string HttpKey { get; set; }
///
[DataMember(Name = "id")]
public string Id { get; set; }
///
[DataMember(Name = "payload")]
public string Payload { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "HttpKey: ", HttpKey, ", ");
output = string.Concat(output, "Id: ", Id, ", ");
output = string.Concat(output, "Payload: ", Payload, ", ");
return output;
}
}
///
/// A user's session used to authenticate messages.
///
public interface IApiSession
{
///
/// True if the corresponding account was just created, false otherwise.
///
bool Created { get; }
///
/// Authentication credentials.
///
string Token { get; }
///
/// rUDP specific authentication credentials.
///
string UdpToken { get; }
}
///
internal class ApiSession : IApiSession
{
///
[DataMember(Name = "created")]
public bool Created { get; set; }
///
[DataMember(Name = "token")]
public string Token { get; set; }
///
[DataMember(Name = "udp_token")]
public string UdpToken { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Created: ", Created, ", ");
output = string.Concat(output, "Token: ", Token, ", ");
output = string.Concat(output, "UdpToken: ", UdpToken, ", ");
return output;
}
}
///
/// An object within the storage engine.
///
public interface IApiStorageObject
{
///
/// The collection which stores the object.
///
string Collection { get; }
///
/// The UNIX time when the object was created.
///
string CreateTime { get; }
///
/// The key of the object within the collection.
///
string Key { get; }
///
/// The read access permissions for the object.
///
int PermissionRead { get; }
///
/// The write access permissions for the object.
///
int PermissionWrite { get; }
///
/// The UNIX time when the object was last updated.
///
string UpdateTime { get; }
///
/// The user owner of the object.
///
string UserId { get; }
///
/// The value of the object.
///
string Value { get; }
///
/// The version hash of the object.
///
string Version { get; }
}
///
internal class ApiStorageObject : IApiStorageObject
{
///
[DataMember(Name = "collection")]
public string Collection { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "key")]
public string Key { get; set; }
///
[DataMember(Name = "permission_read")]
public int PermissionRead { get; set; }
///
[DataMember(Name = "permission_write")]
public int PermissionWrite { get; set; }
///
[DataMember(Name = "update_time")]
public string UpdateTime { get; set; }
///
[DataMember(Name = "user_id")]
public string UserId { get; set; }
///
[DataMember(Name = "value")]
public string Value { get; set; }
///
[DataMember(Name = "version")]
public string Version { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Collection: ", Collection, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "Key: ", Key, ", ");
output = string.Concat(output, "PermissionRead: ", PermissionRead, ", ");
output = string.Concat(output, "PermissionWrite: ", PermissionWrite, ", ");
output = string.Concat(output, "UpdateTime: ", UpdateTime, ", ");
output = string.Concat(output, "UserId: ", UserId, ", ");
output = string.Concat(output, "Value: ", Value, ", ");
output = string.Concat(output, "Version: ", Version, ", ");
return output;
}
}
///
/// A storage acknowledgement.
///
public interface IApiStorageObjectAck
{
///
/// The collection which stores the object.
///
string Collection { get; }
///
/// The key of the object within the collection.
///
string Key { get; }
///
/// The owner of the object.
///
string UserId { get; }
///
/// The version hash of the object.
///
string Version { get; }
}
///
internal class ApiStorageObjectAck : IApiStorageObjectAck
{
///
[DataMember(Name = "collection")]
public string Collection { get; set; }
///
[DataMember(Name = "key")]
public string Key { get; set; }
///
[DataMember(Name = "user_id")]
public string UserId { get; set; }
///
[DataMember(Name = "version")]
public string Version { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Collection: ", Collection, ", ");
output = string.Concat(output, "Key: ", Key, ", ");
output = string.Concat(output, "UserId: ", UserId, ", ");
output = string.Concat(output, "Version: ", Version, ", ");
return output;
}
}
///
/// Batch of acknowledgements for the storage object write.
///
public interface IApiStorageObjectAcks
{
///
/// Batch of storage write acknowledgements.
///
IEnumerable Acks { get; }
}
///
internal class ApiStorageObjectAcks : IApiStorageObjectAcks
{
///
public IEnumerable Acks => _acks ?? new List(0);
[DataMember(Name = "acks")] public List _acks { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Acks: [", string.Join(", ", Acks), "], ");
return output;
}
}
///
/// List of storage objects.
///
public interface IApiStorageObjectList
{
///
/// The cursor associated with the query a page of results.
///
string Cursor { get; }
///
/// The list of storage objects.
///
IEnumerable Objects { get; }
}
///
internal class ApiStorageObjectList : IApiStorageObjectList
{
///
[DataMember(Name = "cursor")]
public string Cursor { get; set; }
///
public IEnumerable Objects => _objects ?? new List(0);
[DataMember(Name = "objects")] public List _objects { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Cursor: ", Cursor, ", ");
output = string.Concat(output, "Objects: [", string.Join(", ", Objects), "], ");
return output;
}
}
///
/// Batch of storage objects.
///
public interface IApiStorageObjects
{
///
/// The batch of storage objects.
///
IEnumerable Objects { get; }
}
///
internal class ApiStorageObjects : IApiStorageObjects
{
///
public IEnumerable Objects => _objects ?? new List(0);
[DataMember(Name = "objects")] public List _objects { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Objects: [", string.Join(", ", Objects), "], ");
return output;
}
}
///
/// A tournament on the server.
///
public interface IApiTournament
{
///
/// True if the tournament is active and can enter. A computed value.
///
bool CanEnter { get; }
///
/// The category of the tournament. e.g. "vip" could be category 1.
///
int Category { get; }
///
/// The UNIX time when the tournament was created.
///
string CreateTime { get; }
///
/// The description of the tournament. May be blank.
///
string Description { get; }
///
/// The UNIX timestamp for duration of a tournament.
///
int Duration { get; }
///
/// The UNIX timestamp when the tournament stops being active until next reset. A computed value.
///
int EndActive { get; }
///
/// The UNIX time when the tournament will be stopped.
///
string EndTime { get; }
///
/// The ID of the tournament.
///
string Id { get; }
///
/// The maximum score updates allowed per player for the current tournament.
///
int MaxNumScore { get; }
///
/// The maximum number of players for the tournament.
///
int MaxSize { get; }
///
/// Additional information stored as a JSON object.
///
string Metadata { get; }
///
/// The UNIX timestamp when the tournament is next playable. A computed value.
///
int NextReset { get; }
///
/// The current number of players in the tournament.
///
int Size { get; }
///
/// ASC or DESC sort mode of scores in the tournament.
///
int SortOrder { get; }
///
/// The UNIX time when the tournament will start.
///
string StartTime { get; }
///
/// The title for the tournament.
///
string Title { get; }
}
///
internal class ApiTournament : IApiTournament
{
///
[DataMember(Name = "can_enter")]
public bool CanEnter { get; set; }
///
[DataMember(Name = "category")]
public int Category { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "description")]
public string Description { get; set; }
///
[DataMember(Name = "duration")]
public int Duration { get; set; }
///
[DataMember(Name = "end_active")]
public int EndActive { get; set; }
///
[DataMember(Name = "end_time")]
public string EndTime { get; set; }
///
[DataMember(Name = "id")]
public string Id { get; set; }
///
[DataMember(Name = "max_num_score")]
public int MaxNumScore { get; set; }
///
[DataMember(Name = "max_size")]
public int MaxSize { get; set; }
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "next_reset")]
public int NextReset { get; set; }
///
[DataMember(Name = "size")]
public int Size { get; set; }
///
[DataMember(Name = "sort_order")]
public int SortOrder { get; set; }
///
[DataMember(Name = "start_time")]
public string StartTime { get; set; }
///
[DataMember(Name = "title")]
public string Title { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "CanEnter: ", CanEnter, ", ");
output = string.Concat(output, "Category: ", Category, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "Description: ", Description, ", ");
output = string.Concat(output, "Duration: ", Duration, ", ");
output = string.Concat(output, "EndActive: ", EndActive, ", ");
output = string.Concat(output, "EndTime: ", EndTime, ", ");
output = string.Concat(output, "Id: ", Id, ", ");
output = string.Concat(output, "MaxNumScore: ", MaxNumScore, ", ");
output = string.Concat(output, "MaxSize: ", MaxSize, ", ");
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "NextReset: ", NextReset, ", ");
output = string.Concat(output, "Size: ", Size, ", ");
output = string.Concat(output, "SortOrder: ", SortOrder, ", ");
output = string.Concat(output, "StartTime: ", StartTime, ", ");
output = string.Concat(output, "Title: ", Title, ", ");
return output;
}
}
///
/// A list of tournaments.
///
public interface IApiTournamentList
{
///
/// A pagination cursor (optional).
///
string Cursor { get; }
///
/// The list of tournaments returned.
///
IEnumerable Tournaments { get; }
}
///
internal class ApiTournamentList : IApiTournamentList
{
///
[DataMember(Name = "cursor")]
public string Cursor { get; set; }
///
public IEnumerable Tournaments => _tournaments ?? new List(0);
[DataMember(Name = "tournaments")] public List _tournaments { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Cursor: ", Cursor, ", ");
output = string.Concat(output, "Tournaments: [", string.Join(", ", Tournaments), "], ");
return output;
}
}
///
/// A set of tournament records which may be part of a tournament records page or a batch of individual records.
///
public interface IApiTournamentRecordList
{
///
/// The cursor to send when retireving the next page (optional).
///
string NextCursor { get; }
///
/// A batched set of tournament records belonging to specified owners.
///
IEnumerable OwnerRecords { get; }
///
/// The cursor to send when retrieving the previous page (optional).
///
string PrevCursor { get; }
///
/// A list of tournament records.
///
IEnumerable Records { get; }
}
///
internal class ApiTournamentRecordList : IApiTournamentRecordList
{
///
[DataMember(Name = "next_cursor")]
public string NextCursor { get; set; }
///
public IEnumerable OwnerRecords => _ownerRecords ?? new List(0);
[DataMember(Name = "owner_records")] public List _ownerRecords { get; set; }
///
[DataMember(Name = "prev_cursor")]
public string PrevCursor { get; set; }
///
public IEnumerable Records => _records ?? new List(0);
[DataMember(Name = "records")] public List _records { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "NextCursor: ", NextCursor, ", ");
output = string.Concat(output, "OwnerRecords: [", string.Join(", ", OwnerRecords), "], ");
output = string.Concat(output, "PrevCursor: ", PrevCursor, ", ");
output = string.Concat(output, "Records: [", string.Join(", ", Records), "], ");
return output;
}
}
///
/// Update a user's account details.
///
public interface IApiUpdateAccountRequest
{
///
/// A URL for an avatar image.
///
string AvatarUrl { get; }
///
/// The display name of the user.
///
string DisplayName { get; }
///
/// The language expected to be a tag which follows the BCP-47 spec.
///
string LangTag { get; }
///
/// The location set by the user.
///
string Location { get; }
///
/// The timezone set by the user.
///
string Timezone { get; }
///
/// The username of the user's account.
///
string Username { get; }
}
///
internal class ApiUpdateAccountRequest : IApiUpdateAccountRequest
{
///
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
///
[DataMember(Name = "display_name")]
public string DisplayName { get; set; }
///
[DataMember(Name = "lang_tag")]
public string LangTag { get; set; }
///
[DataMember(Name = "location")]
public string Location { get; set; }
///
[DataMember(Name = "timezone")]
public string Timezone { get; set; }
///
[DataMember(Name = "username")]
public string Username { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "AvatarUrl: ", AvatarUrl, ", ");
output = string.Concat(output, "DisplayName: ", DisplayName, ", ");
output = string.Concat(output, "LangTag: ", LangTag, ", ");
output = string.Concat(output, "Location: ", Location, ", ");
output = string.Concat(output, "Timezone: ", Timezone, ", ");
output = string.Concat(output, "Username: ", Username, ", ");
return output;
}
}
///
/// Update fields in a given group.
///
public interface IApiUpdateGroupRequest
{
///
/// Avatar URL.
///
string AvatarUrl { get; }
///
/// Description string.
///
string Description { get; }
///
/// The ID of the group to update.
///
string GroupId { get; }
///
/// Lang tag.
///
string LangTag { get; }
///
/// Name.
///
string Name { get; }
///
/// Open is true if anyone should be allowed to join, or false if joins must be approved by a group admin.
///
bool Open { get; }
}
///
internal class ApiUpdateGroupRequest : IApiUpdateGroupRequest
{
///
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
///
[DataMember(Name = "description")]
public string Description { get; set; }
///
[DataMember(Name = "group_id")]
public string GroupId { get; set; }
///
[DataMember(Name = "lang_tag")]
public string LangTag { get; set; }
///
[DataMember(Name = "name")]
public string Name { get; set; }
///
[DataMember(Name = "open")]
public bool Open { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "AvatarUrl: ", AvatarUrl, ", ");
output = string.Concat(output, "Description: ", Description, ", ");
output = string.Concat(output, "GroupId: ", GroupId, ", ");
output = string.Concat(output, "LangTag: ", LangTag, ", ");
output = string.Concat(output, "Name: ", Name, ", ");
output = string.Concat(output, "Open: ", Open, ", ");
return output;
}
}
///
/// A user in the server.
///
public interface IApiUser
{
///
/// A URL for an avatar image.
///
string AvatarUrl { get; }
///
/// The UNIX time when the user was created.
///
string CreateTime { get; }
///
/// The display name of the user.
///
string DisplayName { get; }
///
/// Number of related edges to this user.
///
int EdgeCount { get; }
///
/// The Facebook id in the user's account.
///
string FacebookId { get; }
///
/// The Apple Game Center in of the user's account.
///
string GamecenterId { get; }
///
/// The Google id in the user's account.
///
string GoogleId { get; }
///
/// The id of the user's account.
///
string Id { get; }
///
/// The language expected to be a tag which follows the BCP-47 spec.
///
string LangTag { get; }
///
/// The location set by the user.
///
string Location { get; }
///
/// Additional information stored as a JSON object.
///
string Metadata { get; }
///
/// Indicates whether the user is currently online.
///
bool Online { get; }
///
/// The Steam id in the user's account.
///
string SteamId { get; }
///
/// The timezone set by the user.
///
string Timezone { get; }
///
/// The UNIX time when the user was last updated.
///
string UpdateTime { get; }
///
/// The username of the user's account.
///
string Username { get; }
}
///
internal class ApiUser : IApiUser
{
///
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
///
[DataMember(Name = "create_time")]
public string CreateTime { get; set; }
///
[DataMember(Name = "display_name")]
public string DisplayName { get; set; }
///
[DataMember(Name = "edge_count")]
public int EdgeCount { get; set; }
///
[DataMember(Name = "facebook_id")]
public string FacebookId { get; set; }
///
[DataMember(Name = "gamecenter_id")]
public string GamecenterId { get; set; }
///
[DataMember(Name = "google_id")]
public string GoogleId { get; set; }
///
[DataMember(Name = "id")]
public string Id { get; set; }
///
[DataMember(Name = "lang_tag")]
public string LangTag { get; set; }
///
[DataMember(Name = "location")]
public string Location { get; set; }
///
[DataMember(Name = "metadata")]
public string Metadata { get; set; }
///
[DataMember(Name = "online")]
public bool Online { get; set; }
///
[DataMember(Name = "steam_id")]
public string SteamId { get; set; }
///
[DataMember(Name = "timezone")]
public string Timezone { get; set; }
///
[DataMember(Name = "update_time")]
public string UpdateTime { get; set; }
///
[DataMember(Name = "username")]
public string Username { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "AvatarUrl: ", AvatarUrl, ", ");
output = string.Concat(output, "CreateTime: ", CreateTime, ", ");
output = string.Concat(output, "DisplayName: ", DisplayName, ", ");
output = string.Concat(output, "EdgeCount: ", EdgeCount, ", ");
output = string.Concat(output, "FacebookId: ", FacebookId, ", ");
output = string.Concat(output, "GamecenterId: ", GamecenterId, ", ");
output = string.Concat(output, "GoogleId: ", GoogleId, ", ");
output = string.Concat(output, "Id: ", Id, ", ");
output = string.Concat(output, "LangTag: ", LangTag, ", ");
output = string.Concat(output, "Location: ", Location, ", ");
output = string.Concat(output, "Metadata: ", Metadata, ", ");
output = string.Concat(output, "Online: ", Online, ", ");
output = string.Concat(output, "SteamId: ", SteamId, ", ");
output = string.Concat(output, "Timezone: ", Timezone, ", ");
output = string.Concat(output, "UpdateTime: ", UpdateTime, ", ");
output = string.Concat(output, "Username: ", Username, ", ");
return output;
}
}
///
/// A list of groups belonging to a user, along with the user's role in each group.
///
public interface IApiUserGroupList
{
///
/// Group-role pairs for a user.
///
IEnumerable UserGroups { get; }
}
///
internal class ApiUserGroupList : IApiUserGroupList
{
///
public IEnumerable UserGroups => _userGroups ?? new List(0);
[DataMember(Name = "user_groups")] public List _userGroups { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "UserGroups: [", string.Join(", ", UserGroups), "], ");
return output;
}
}
///
/// A collection of zero or more users.
///
public interface IApiUsers
{
///
/// The User objects.
///
IEnumerable Users { get; }
}
///
internal class ApiUsers : IApiUsers
{
///
public IEnumerable Users => _users ?? new List(0);
[DataMember(Name = "users")] public List _users { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Users: [", string.Join(", ", Users), "], ");
return output;
}
}
///
/// The object to store.
///
public interface IApiWriteStorageObject
{
///
/// The collection to store the object.
///
string Collection { get; }
///
/// The key for the object within the collection.
///
string Key { get; }
///
/// The read access permissions for the object.
///
int PermissionRead { get; }
///
/// The write access permissions for the object.
///
int PermissionWrite { get; }
///
/// The value of the object.
///
string Value { get; }
///
/// The version hash of the object to check. Possible values are: ["", "*", "#hash#"].
///
string Version { get; }
}
///
internal class ApiWriteStorageObject : IApiWriteStorageObject
{
///
[DataMember(Name = "collection")]
public string Collection { get; set; }
///
[DataMember(Name = "key")]
public string Key { get; set; }
///
[DataMember(Name = "permission_read")]
public int PermissionRead { get; set; }
///
[DataMember(Name = "permission_write")]
public int PermissionWrite { get; set; }
///
[DataMember(Name = "value")]
public string Value { get; set; }
///
[DataMember(Name = "version")]
public string Version { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Collection: ", Collection, ", ");
output = string.Concat(output, "Key: ", Key, ", ");
output = string.Concat(output, "PermissionRead: ", PermissionRead, ", ");
output = string.Concat(output, "PermissionWrite: ", PermissionWrite, ", ");
output = string.Concat(output, "Value: ", Value, ", ");
output = string.Concat(output, "Version: ", Version, ", ");
return output;
}
}
///
/// Write objects to the storage engine.
///
public interface IApiWriteStorageObjectsRequest
{
///
/// The objects to store on the server.
///
IEnumerable Objects { get; }
}
///
internal class ApiWriteStorageObjectsRequest : IApiWriteStorageObjectsRequest
{
///
public IEnumerable Objects => _objects ?? new List(0);
[DataMember(Name = "objects")] public List _objects { get; set; }
public override string ToString()
{
var output = "";
output = string.Concat(output, "Objects: [", string.Join(", ", Objects), "], ");
return output;
}
}
///
/// The low level client for the Nakama API.
///
internal class ApiClient
{
private readonly Uri _baseUri;
private readonly HttpClient _httpClient;
public ApiClient(Uri baseUri, HttpClient httpClient)
{
_baseUri = baseUri;
_httpClient = httpClient;
}
///
/// A healthcheck which load balancers can use to check the service.
///
public async Task HealthcheckAsync(
string bearerToken)
{
var urlpath = "/healthcheck?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Fetch the current user's account.
///
public async Task GetAccountAsync(
string bearerToken)
{
var urlpath = "/v2/account?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Update fields in the current user's account.
///
public async Task UpdateAccountAsync(
string bearerToken,
ApiUpdateAccountRequest body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("PUT"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with a custom id against the server.
///
public async Task AuthenticateCustomAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountCustom body,
bool create,
string username)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/custom?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with a device id against the server.
///
public async Task AuthenticateDeviceAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountDevice body,
bool create,
string username)
{
Debug.Log("Authen 1");
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/device?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
Debug.Log($"Authen 2 :{header} ");
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
Debug.Log($"Authen 3 :{request.RequestUri.AbsoluteUri}");
Debug.Log($"Authen 4: {body.ToJson()}");
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
Debug.Log("Authen 5");
response.Content?.Dispose();
var decoded = contents.FromJson>();
Debug.Log("Authen 6");
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with an email+password against the server.
///
public async Task AuthenticateEmailAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountEmail body,
bool create,
string username)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/email?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with a Facebook OAuth token against the server.
///
public async Task AuthenticateFacebookAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountFacebook body,
bool create,
string username,
bool sync)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/facebook?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
urlpath = string.Concat(urlpath, "sync=", sync.ToString()
.ToLower(), "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with Apple's GameCenter against the server.
///
public async Task AuthenticateGameCenterAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountGameCenter body,
bool create,
string username)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/gamecenter?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with Google against the server.
///
public async Task AuthenticateGoogleAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountGoogle body,
bool create,
string username)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/google?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Authenticate a user with Steam against the server.
///
public async Task AuthenticateSteamAsync(
string basicAuthUsername,
string basicAuthPassword,
ApiAccountSteam body,
bool create,
string username)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/authenticate/steam?";
urlpath = string.Concat(urlpath, "create=", create.ToString()
.ToLower(), "&");
if (username != null)
{
urlpath = string.Concat(urlpath, "username=", Uri.EscapeDataString(username), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var credentials = Encoding.UTF8.GetBytes(basicAuthUsername + ":" + basicAuthPassword);
var header = string.Concat("Basic ", Convert.ToBase64String(credentials));
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add a custom ID to the social profiles on the current user's account.
///
public async Task LinkCustomAsync(
string bearerToken,
ApiAccountCustom body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/custom?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add a device ID to the social profiles on the current user's account.
///
public async Task LinkDeviceAsync(
string bearerToken,
ApiAccountDevice body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/device?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add an email+password to the social profiles on the current user's account.
///
public async Task LinkEmailAsync(
string bearerToken,
ApiAccountEmail body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/email?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add Facebook to the social profiles on the current user's account.
///
public async Task LinkFacebookAsync(
string bearerToken,
ApiAccountFacebook body,
bool sync)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/facebook?";
urlpath = string.Concat(urlpath, "sync=", sync.ToString()
.ToLower(), "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add Apple's GameCenter to the social profiles on the current user's account.
///
public async Task LinkGameCenterAsync(
string bearerToken,
ApiAccountGameCenter body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/gamecenter?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add Google to the social profiles on the current user's account.
///
public async Task LinkGoogleAsync(
string bearerToken,
ApiAccountGoogle body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/google?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add Steam to the social profiles on the current user's account.
///
public async Task LinkSteamAsync(
string bearerToken,
ApiAccountSteam body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/link/steam?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove the custom ID from the social profiles on the current user's account.
///
public async Task UnlinkCustomAsync(
string bearerToken,
ApiAccountCustom body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/custom?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove the device ID from the social profiles on the current user's account.
///
public async Task UnlinkDeviceAsync(
string bearerToken,
ApiAccountDevice body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/device?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove the email+password from the social profiles on the current user's account.
///
public async Task UnlinkEmailAsync(
string bearerToken,
ApiAccountEmail body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/email?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove Facebook from the social profiles on the current user's account.
///
public async Task UnlinkFacebookAsync(
string bearerToken,
ApiAccountFacebook body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/facebook?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove Apple's GameCenter from the social profiles on the current user's account.
///
public async Task UnlinkGameCenterAsync(
string bearerToken,
ApiAccountGameCenter body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/gamecenter?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove Google from the social profiles on the current user's account.
///
public async Task UnlinkGoogleAsync(
string bearerToken,
ApiAccountGoogle body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/google?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Remove Steam from the social profiles on the current user's account.
///
public async Task UnlinkSteamAsync(
string bearerToken,
ApiAccountSteam body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/account/unlink/steam?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List a channel's message history.
///
public async Task ListChannelMessagesAsync(
string bearerToken,
string channelId,
int limit,
bool forward,
string cursor)
{
if (channelId == null)
{
throw new ArgumentException("'channelId' is required but was null.");
}
var urlpath = "/v2/channel/{channel_id}?";
urlpath = urlpath.Replace("{channel_id}", Uri.EscapeDataString(channelId));
urlpath = string.Concat(urlpath, "limit=", limit, "&");
urlpath = string.Concat(urlpath, "forward=", forward.ToString()
.ToLower(), "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Delete one or more users by ID or username.
///
public async Task DeleteFriendsAsync(
string bearerToken,
IEnumerable ids,
IEnumerable usernames)
{
var urlpath = "/v2/friend?";
foreach (var elem in ids ?? new string[0])
{
urlpath = string.Concat(urlpath, "ids=", elem, "&");
}
foreach (var elem in usernames ?? new string[0])
{
urlpath = string.Concat(urlpath, "usernames=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("DELETE"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List all friends for the current user.
///
public async Task ListFriendsAsync(
string bearerToken)
{
var urlpath = "/v2/friend?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add friends by ID or username to a user's account.
///
public async Task AddFriendsAsync(
string bearerToken,
IEnumerable ids,
IEnumerable usernames)
{
var urlpath = "/v2/friend?";
foreach (var elem in ids ?? new string[0])
{
urlpath = string.Concat(urlpath, "ids=", elem, "&");
}
foreach (var elem in usernames ?? new string[0])
{
urlpath = string.Concat(urlpath, "usernames=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Block one or more users by ID or username.
///
public async Task BlockFriendsAsync(
string bearerToken,
IEnumerable ids,
IEnumerable usernames)
{
var urlpath = "/v2/friend/block?";
foreach (var elem in ids ?? new string[0])
{
urlpath = string.Concat(urlpath, "ids=", elem, "&");
}
foreach (var elem in usernames ?? new string[0])
{
urlpath = string.Concat(urlpath, "usernames=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Import Facebook friends and add them to a user's account.
///
public async Task ImportFacebookFriendsAsync(
string bearerToken,
ApiAccountFacebook body,
bool reset)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/friend/facebook?";
urlpath = string.Concat(urlpath, "reset=", reset.ToString()
.ToLower(), "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List groups based on given filters.
///
public async Task ListGroupsAsync(
string bearerToken,
string name,
string cursor,
int limit)
{
var urlpath = "/v2/group?";
if (name != null)
{
urlpath = string.Concat(urlpath, "name=", Uri.EscapeDataString(name), "&");
}
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
urlpath = string.Concat(urlpath, "limit=", limit, "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Create a new group with the current user as the owner.
///
public async Task CreateGroupAsync(
string bearerToken,
ApiCreateGroupRequest body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/group?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Delete a group by ID.
///
public async Task DeleteGroupAsync(
string bearerToken,
string groupId)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("DELETE"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Update fields in a given group.
///
public async Task UpdateGroupAsync(
string bearerToken,
string groupId,
ApiUpdateGroupRequest body)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/group/{group_id}?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("PUT"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Add users to a group.
///
public async Task AddGroupUsersAsync(
string bearerToken,
string groupId,
IEnumerable userIds)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/add?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
foreach (var elem in userIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "user_ids=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Immediately join an open group, or request to join a closed one.
///
public async Task JoinGroupAsync(
string bearerToken,
string groupId)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/join?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Kick a set of users from a group.
///
public async Task KickGroupUsersAsync(
string bearerToken,
string groupId,
IEnumerable userIds)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/kick?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
foreach (var elem in userIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "user_ids=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Leave a group the user is a member of.
///
public async Task LeaveGroupAsync(
string bearerToken,
string groupId)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/leave?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Promote a set of users in a group to the next role up.
///
public async Task PromoteGroupUsersAsync(
string bearerToken,
string groupId,
IEnumerable userIds)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/promote?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
foreach (var elem in userIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "user_ids=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List all users that are part of a group.
///
public async Task ListGroupUsersAsync(
string bearerToken,
string groupId)
{
if (groupId == null)
{
throw new ArgumentException("'groupId' is required but was null.");
}
var urlpath = "/v2/group/{group_id}/user?";
urlpath = urlpath.Replace("{group_id}", Uri.EscapeDataString(groupId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Delete a leaderboard record.
///
public async Task DeleteLeaderboardRecordAsync(
string bearerToken,
string leaderboardId)
{
if (leaderboardId == null)
{
throw new ArgumentException("'leaderboardId' is required but was null.");
}
var urlpath = "/v2/leaderboard/{leaderboard_id}?";
urlpath = urlpath.Replace("{leaderboard_id}", Uri.EscapeDataString(leaderboardId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("DELETE"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List leaderboard records.
///
public async Task ListLeaderboardRecordsAsync(
string bearerToken,
string leaderboardId,
IEnumerable ownerIds,
int limit,
string cursor)
{
if (leaderboardId == null)
{
throw new ArgumentException("'leaderboardId' is required but was null.");
}
var urlpath = "/v2/leaderboard/{leaderboard_id}?";
urlpath = urlpath.Replace("{leaderboard_id}", Uri.EscapeDataString(leaderboardId));
foreach (var elem in ownerIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "owner_ids=", elem, "&");
}
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Write a record to a leaderboard.
///
public async Task WriteLeaderboardRecordAsync(
string bearerToken,
string leaderboardId,
WriteLeaderboardRecordRequestLeaderboardRecordWrite body)
{
if (leaderboardId == null)
{
throw new ArgumentException("'leaderboardId' is required but was null.");
}
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/leaderboard/{leaderboard_id}?";
urlpath = urlpath.Replace("{leaderboard_id}", Uri.EscapeDataString(leaderboardId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List leaderboard records that belong to a user.
///
public async Task ListLeaderboardRecordsAroundOwnerAsync(
string bearerToken,
string leaderboardId,
string ownerId,
int limit)
{
if (leaderboardId == null)
{
throw new ArgumentException("'leaderboardId' is required but was null.");
}
if (ownerId == null)
{
throw new ArgumentException("'ownerId' is required but was null.");
}
var urlpath = "/v2/leaderboard/{leaderboard_id}/owner/{owner_id}?";
urlpath = urlpath.Replace("{leaderboard_id}", Uri.EscapeDataString(leaderboardId));
urlpath = urlpath.Replace("{owner_id}", Uri.EscapeDataString(ownerId));
urlpath = string.Concat(urlpath, "limit=", limit, "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Fetch list of running matches.
///
public async Task ListMatchesAsync(
string bearerToken,
int limit,
bool authoritative,
string label,
int minSize,
int maxSize,
string query)
{
var urlpath = "/v2/match?";
urlpath = string.Concat(urlpath, "limit=", limit, "&");
urlpath = string.Concat(urlpath, "authoritative=", authoritative.ToString()
.ToLower(), "&");
if (label != null)
{
urlpath = string.Concat(urlpath, "label=", Uri.EscapeDataString(label), "&");
}
urlpath = string.Concat(urlpath, "min_size=", minSize, "&");
urlpath = string.Concat(urlpath, "max_size=", maxSize, "&");
if (query != null)
{
urlpath = string.Concat(urlpath, "query=", Uri.EscapeDataString(query), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Delete one or more notifications for the current user.
///
public async Task DeleteNotificationsAsync(
string bearerToken,
IEnumerable ids)
{
var urlpath = "/v2/notification?";
foreach (var elem in ids ?? new string[0])
{
urlpath = string.Concat(urlpath, "ids=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("DELETE"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Fetch list of notifications.
///
public async Task ListNotificationsAsync(
string bearerToken,
int limit,
string cacheableCursor)
{
var urlpath = "/v2/notification?";
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cacheableCursor != null)
{
urlpath = string.Concat(urlpath, "cacheable_cursor=", Uri.EscapeDataString(cacheableCursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Execute a Lua function on the server.
///
public async Task RpcFunc2Async(
string bearerToken,
string id,
string payload,
string httpKey)
{
if (id == null)
{
throw new ArgumentException("'id' is required but was null.");
}
var urlpath = "/v2/rpc/{id}?";
urlpath = urlpath.Replace("{id}", Uri.EscapeDataString(id));
if (payload != null)
{
urlpath = string.Concat(urlpath, "payload=", Uri.EscapeDataString(payload), "&");
}
if (httpKey != null)
{
urlpath = string.Concat(urlpath, "http_key=", Uri.EscapeDataString(httpKey), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
if (!string.IsNullOrEmpty(bearerToken))
{
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
}
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Execute a Lua function on the server.
///
public async Task RpcFuncAsync(
string bearerToken,
string id,
string body)
{
if (id == null)
{
throw new ArgumentException("'id' is required but was null.");
}
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/rpc/{id}?";
urlpath = urlpath.Replace("{id}", Uri.EscapeDataString(id));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
if (!string.IsNullOrEmpty(bearerToken))
{
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
}
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Get storage objects.
///
public async Task ReadStorageObjectsAsync(
string bearerToken,
ApiReadStorageObjectsRequest body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/storage?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Write objects into the storage engine.
///
public async Task WriteStorageObjectsAsync(
string bearerToken,
ApiWriteStorageObjectsRequest body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/storage?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("PUT"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Delete one or more objects by ID or username.
///
public async Task DeleteStorageObjectsAsync(
string bearerToken,
ApiDeleteStorageObjectsRequest body)
{
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/storage/delete?";
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("PUT"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List publicly readable storage objects in a given collection.
///
public async Task ListStorageObjectsAsync(
string bearerToken,
string collection,
string userId,
int limit,
string cursor)
{
if (collection == null)
{
throw new ArgumentException("'collection' is required but was null.");
}
var urlpath = "/v2/storage/{collection}?";
urlpath = urlpath.Replace("{collection}", Uri.EscapeDataString(collection));
if (userId != null)
{
urlpath = string.Concat(urlpath, "user_id=", Uri.EscapeDataString(userId), "&");
}
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List publicly readable storage objects in a given collection.
///
public async Task ListStorageObjects2Async(
string bearerToken,
string collection,
string userId,
int limit,
string cursor)
{
if (collection == null)
{
throw new ArgumentException("'collection' is required but was null.");
}
if (userId == null)
{
throw new ArgumentException("'userId' is required but was null.");
}
var urlpath = "/v2/storage/{collection}/{user_id}?";
urlpath = urlpath.Replace("{collection}", Uri.EscapeDataString(collection));
urlpath = urlpath.Replace("{user_id}", Uri.EscapeDataString(userId));
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List current or upcoming tournaments.
///
public async Task ListTournamentsAsync(
string bearerToken,
int categoryStart,
int categoryEnd,
int startTime,
int endTime,
int limit,
string cursor)
{
var urlpath = "/v2/tournament?";
urlpath = string.Concat(urlpath, "category_start=", categoryStart, "&");
urlpath = string.Concat(urlpath, "category_end=", categoryEnd, "&");
urlpath = string.Concat(urlpath, "start_time=", startTime, "&");
urlpath = string.Concat(urlpath, "end_time=", endTime, "&");
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List tournament records.
///
public async Task ListTournamentRecordsAsync(
string bearerToken,
string tournamentId,
IEnumerable ownerIds,
int limit,
string cursor)
{
if (tournamentId == null)
{
throw new ArgumentException("'tournamentId' is required but was null.");
}
var urlpath = "/v2/tournament/{tournament_id}?";
urlpath = urlpath.Replace("{tournament_id}", Uri.EscapeDataString(tournamentId));
foreach (var elem in ownerIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "owner_ids=", elem, "&");
}
urlpath = string.Concat(urlpath, "limit=", limit, "&");
if (cursor != null)
{
urlpath = string.Concat(urlpath, "cursor=", Uri.EscapeDataString(cursor), "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Write a record to a tournament.
///
public async Task WriteTournamentRecordAsync(
string bearerToken,
string tournamentId,
WriteTournamentRecordRequestTournamentRecordWrite body)
{
if (tournamentId == null)
{
throw new ArgumentException("'tournamentId' is required but was null.");
}
if (body == null)
{
throw new ArgumentException("'body' is required but was null.");
}
var urlpath = "/v2/tournament/{tournament_id}?";
urlpath = urlpath.Replace("{tournament_id}", Uri.EscapeDataString(tournamentId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("PUT"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
request.Content = new StringContent(body.ToJson());
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Attempt to join an open and running tournament.
///
public async Task JoinTournamentAsync(
string bearerToken,
string tournamentId)
{
if (tournamentId == null)
{
throw new ArgumentException("'tournamentId' is required but was null.");
}
var urlpath = "/v2/tournament/{tournament_id}/join?";
urlpath = urlpath.Replace("{tournament_id}", Uri.EscapeDataString(tournamentId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("POST"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return;
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List tournament records for a given owner.
///
public async Task ListTournamentRecordsAroundOwnerAsync(
string bearerToken,
string tournamentId,
string ownerId,
int limit)
{
if (tournamentId == null)
{
throw new ArgumentException("'tournamentId' is required but was null.");
}
if (ownerId == null)
{
throw new ArgumentException("'ownerId' is required but was null.");
}
var urlpath = "/v2/tournament/{tournament_id}/owner/{owner_id}?";
urlpath = urlpath.Replace("{tournament_id}", Uri.EscapeDataString(tournamentId));
urlpath = urlpath.Replace("{owner_id}", Uri.EscapeDataString(ownerId));
urlpath = string.Concat(urlpath, "limit=", limit, "&");
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// Fetch zero or more users by ID and/or username.
///
public async Task GetUsersAsync(
string bearerToken,
IEnumerable ids,
IEnumerable usernames,
IEnumerable facebookIds)
{
var urlpath = "/v2/user?";
foreach (var elem in ids ?? new string[0])
{
urlpath = string.Concat(urlpath, "ids=", elem, "&");
}
foreach (var elem in usernames ?? new string[0])
{
urlpath = string.Concat(urlpath, "usernames=", elem, "&");
}
foreach (var elem in facebookIds ?? new string[0])
{
urlpath = string.Concat(urlpath, "facebook_ids=", elem, "&");
}
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
///
/// List groups the current user belongs to.
///
public async Task ListUserGroupsAsync(
string bearerToken,
string userId)
{
if (userId == null)
{
throw new ArgumentException("'userId' is required but was null.");
}
var urlpath = "/v2/user/{user_id}/group?";
urlpath = urlpath.Replace("{user_id}", Uri.EscapeDataString(userId));
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseUri, urlpath),
Method = new HttpMethod("GET"),
Headers =
{
Accept = {new MediaTypeWithQualityHeaderValue("application/json")}
}
};
var header = string.Concat("Bearer ", bearerToken);
request.Headers.Authorization = AuthenticationHeaderValue.Parse(header);
var response = await _httpClient.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return contents.FromJson();
}
response.Content?.Dispose();
var decoded = contents.FromJson>();
throw new ApiResponseException(response.StatusCode, decoded["error"]
.ToString(), (int) decoded["code"]);
}
}
}