コード例 #1
0
        public async Task <RelationshipStatus> GetUserRelationshipStatus(string authenticationToken, string friendId)
        {
            try
            {
                FriendService      friendService      = new FriendService();
                RelationshipStatus relationshipStatus = new RelationshipStatus();

                var response = await friendService.GetUserRelationshipStatus(authenticationToken, friendId);

                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(result))
                    {
                        Enum.TryParse(result, out relationshipStatus);

                        return(relationshipStatus);
                    }
                    else
                    {
                        return(RelationshipStatus.NotFriends);
                    }
                }
                else
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        throw new Exception("Unauthorized");
                    }
                    else
                    {
                        throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }