Exemplo n.º 1
0
        public VRChatApi(string username, string password)
        {
            Logger.Trace(() => $"Entering {nameof(VRChatApi)} constructor");
            Logger.Debug(() => $"Using username {username}");

            // initialize endpoint classes
            RemoteConfig   = new RemoteConfig();
            UserApi        = new UserApi(username, password);
            FriendsApi     = new FriendsApi();
            WorldApi       = new WorldApi();
            ModerationsApi = new ModerationsApi();
            AvatarApi      = new AvatarApi();

            // initialize http client
            // TODO: use the auth cookie
            if (Global.HttpClient == null)
            {
                Logger.Trace(() => $"Instantiating {nameof(HttpClient)}");
                Global.HttpClient             = new HttpClient();
                Global.HttpClient.BaseAddress = new Uri("https://api.vrchat.cloud/api/1/");
                Logger.Info(() => $"VRChat API base address set to {Global.HttpClient.BaseAddress}");
            }

            string authEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{UserApi.Username}:{UserApi.Password}"));

            var header = Global.HttpClient.DefaultRequestHeaders;

            if (header.Contains("Authorization"))
            {
                Logger.Debug(() => "Removing existing Authorization header");
                header.Remove("Authorization");
            }
            header.Add("Authorization", $"Basic {authEncoded}");
            Logger.Trace(() => $"Added new Authorization header");
        }
Exemplo n.º 2
0
        public void CanHandleInternalServerErrorHttpStatusPlayerModeratedResponse()
        {
            MockHttpMessageHandler.SetResponse(string.Empty, HttpStatusCode.InternalServerError);
            var api    = new ModerationsApi();
            var result = api.GetPlayerModerated().Result;

            result.Should().BeNull();
        }
Exemplo n.º 3
0
        public void CanHandleValidPlayerModeratedResponse()
        {
            MockHttpMessageHandler.SetResponse(new JArray(
                                                   new JObject(
                                                       new JProperty("id", "some id"),
                                                       new JProperty("type", "some type"),
                                                       new JProperty("sourceUserId", "source user id"),
                                                       new JProperty("sourceDisplayname", "source display name"),
                                                       new JProperty("targetUserId", "my user id"),
                                                       new JProperty("targetDisplayName", "my display name"),
                                                       new JProperty("created", "some timestamp"))));

            var api    = new ModerationsApi();
            var result = api.GetPlayerModerated().Result;

            result.Should().HaveCount(1);
            result[0].id.Should().Be("some id");
            result[0].type.Should().Be("some type");
            result[0].sourceUserId.Should().Be("source user id");
            result[0].sourceDisplayName.Should().Be("source display name");
            result[0].targetUserId.Should().Be("my user id");
            result[0].targetDisplayName.Should().Be("my display name");
            result[0].created.Should().Be("some timestamp");
        }