Ejemplo n.º 1
0
        //GraphQL doesnt wanna work and I hate it
        internal async Task <IEnumerable <UserLike>?> GetUserLikesAsync(string?after = null)
        {
            using var stream = Assembly.GetExecutingAssembly()?.GetManifestResourceStream("OKCSharp.Schema.UserLikes.graphql");
            if (stream == null)
            {
                throw new NullReferenceException("Could not find resource");
            }
            using var sr = new StreamReader(stream);
            var schema = await sr.ReadToEndAsync().ConfigureAwait(false);

            var gqlpay = new GraphQLPayload()
            {
                OperationName = "userrowsIncomingLikes",//"userrowsOutgoingLikes",
                Query         = schema,
                Variables     = new Dictionary <string, string>()
                {
                    {
                        "userid",
                        this.UserLoginData?.UserId.ToString() ?? ""
                    }
                }
            };

            if (after != null)
            {
                gqlpay.Variables.Add("after", after);
            }
            var req = new HttpRequestMessage(HttpMethod.Post, new Uri($"https://www.okcupid.com/graphql"))
            {
                Content = new StringContent(JsonConvert.SerializeObject(gqlpay), Encoding.Default, "application/json")
            };
            var res = await this.Http.SendAsync(req).ConfigureAwait(false);

            var cont = await res.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (res.IsSuccessStatusCode)
            {
                return((JsonConvert.DeserializeObject <ApiResponse <UserLikesNotification> >(cont)).ApiData?.NotificationData?.Likes?.Data);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        internal async Task <CurrentUserProfile?> GetCurrentUserProfileAsync()
        {
            using var stream = Assembly.GetExecutingAssembly()?.GetManifestResourceStream("OKCSharp.Schema.UserProfile.graphql");
            if (stream == null)
            {
                throw new NullReferenceException("Could not find resource");
            }
            using var sr = new StreamReader(stream);
            var schema = await sr.ReadToEndAsync().ConfigureAwait(false);

            var gqlpay = new GraphQLPayload()
            {
                OperationName = "profileEditDesktop",
                Query         = schema,
                Variables     = new Dictionary <string, string>()
                {
                    {
                        "id",
                        this.UserLoginData?.UserId.ToString() ?? ""
                    }
                }
            };

            var jsonbody = JsonConvert.SerializeObject(gqlpay, Formatting.Indented);

            var req = new HttpRequestMessage(HttpMethod.Post, new Uri($"https://www.okcupid.com/graphql"))
            {
                Content = new StringContent(jsonbody, Encoding.Default, "application/json")
            };
            var res = await this.Http.SendAsync(req).ConfigureAwait(false);

            var cont = await res.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (res.IsSuccessStatusCode)
            {
                return((JsonConvert.DeserializeObject <ApiResponse <CurrentUserProfile> >(cont)).ApiData);
            }
            else
            {
                return(null);
            }
        }