Ejemplo n.º 1
0
        /// <summary>
        /// Converts the account to sign in through another network.
        /// For instance, you might have created an anonymous account, that you later want to convert to an account
        /// logged on through a facebook account. Or, should you later want to convert this account to simply use an
        /// e-mail address, this is the method that you will want to call.
        /// In order to convert the account successfully, the provided network credentials need to be acceptable,
        /// just as when calling #CotcSdk.Cloud.Login.
        /// </summary>
        /// <returns>Promise resolved when the operation has completed.</returns>
        /// <param name="network">The target network to connect with later on.</param>
        /// <param name="networkId">The ID on the network. For example, with the facebook network, this would be the User ID.
        ///     On e-mail accounts e-mail then, this would be the e-mail address.</param>
        /// <param name="networkSecret">The secret for the network. For e-mail accounts, this would be the passord. For
        ///     facebook or other SNS accounts, this would be the user token.</param>
        public Promise<Done> Convert(LoginNetwork network, string networkId, string networkSecret)
        {
            Bundle config = Bundle.CreateObject();
            config["network"] = network.Describe();
            config["id"] = networkId;
            config["secret"] = networkSecret;

            HttpRequest req = Gamer.MakeHttpRequest("/v1/gamer/convert");
            req.BodyJson = config;
            return Common.RunInTask<Done>(req, (response, task) => {
                // Update the linked gamer instance with the additional parameters
                if (response.BodyJson.Has("gamer")) {
                    Gamer.Update(response.BodyJson["gamer"]);
                }
                task.PostResult(new Done(response.BodyJson));
            });
        }
Ejemplo n.º 2
0
 /// <summary>Logs the current user in, using any supported social network.</summary>
 /// <returns>Promise resolved when the login has finished. The resulting Gamer object can then be used for many
 ///     purposes related to the signed in account.</returns>
 /// <param name="network">The network to connect with. If an user is recognized on a given network (same network ID),
 ///     then it will be signed back in and its user data will be used.</param>
 /// <param name="networkId">The ID on the network. For example, with the facebook network, this would be the User ID.
 ///     On e-mail accounts e-mail then, this would be the e-mail address.</param>
 /// <param name="networkSecret">The secret for the network. For e-mail accounts, this would be the passord. For
 ///     facebook or other SNS accounts, this would be the user token. For the LoginNetwork.GameCenter, the password
 ///     is not used, so you may pass "n/a".</param>
 /// <param name="preventRegistration">Fail instead of silently creating an account in case it doesn't already exist on
 ///     the CotC servers.</param>
 /// <param name="additionalOptions">Additional options can be passed, such as `thenBatch` to execute a batch after
 ///     login. Pass it as a Bundle with the additional keys. May not override `preventRegistration` key since it is
 ///     defined by the parameter of the same name.</param>
 public Promise<Gamer> Login(LoginNetwork network, string networkId, string networkSecret, bool preventRegistration = false, Bundle additionalOptions = null)
 {
     return Login(network.Describe(), networkId, networkSecret, preventRegistration, additionalOptions);
 }
Ejemplo n.º 3
0
 /// <summary>Checks that an user exists on a given network.</summary>
 /// <returns>Promise resolved when the user is found. If the user does not exist, it fails with
 ///     an HTTP status code of 400.</returns>
 /// <param name="network">Network used to log in (scoping the networkId).</param>
 /// <param name="networkId">The ID of the user on the network, like the e-mail address.</param>
 public Promise<Done> UserExists(LoginNetwork network, string networkId)
 {
     UrlBuilder url = new UrlBuilder("/v1/users")
         .Path(network.Describe()).Path(networkId);
     HttpRequest req = MakeUnauthenticatedHttpRequest(url);
     return Common.RunInTask<Done>(req, (response, task) => {
         task.PostResult(new Done(true, response.BodyJson));
     });
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Links the account with another social network. Note that unlike Convert, this doesn't change the way the
        /// user would then sign in (the credentials remain the same).
        /// For instance, one may want to link their facebook account while keeping e-mail credentials in order to
        /// be able to share and play against gamers from their facebook social circle.
        /// In order to link the account successfully, the provided network credentials need to be acceptable,
        /// just as when calling #CotcSdk.Cloud.Login.
        /// </summary>
        /// <returns>Promise resolved when the operation has completed.</returns>
        /// <param name="network">The target network to link the account with.</param>
        /// <param name="networkId">The ID on the network. For example, with the facebook network, this would be the User ID.
        ///     On e-mail accounts e-mail then, this would be the e-mail address.</param>
        /// <param name="networkSecret">The secret for the network. For e-mail accounts, this would be the passord. For
        ///     facebook or other SNS accounts, this would be the user token.</param>
        public Promise<Done> Link(LoginNetwork network, string networkId, string networkSecret)
        {
            Bundle config = Bundle.CreateObject();
            config["network"] = network.Describe();
            config["id"] = networkId;
            config["secret"] = networkSecret;

            HttpRequest req = Gamer.MakeHttpRequest("/v1/gamer/link");
            req.BodyJson = config;
            return Common.RunInTask<Done>(req, (response, task) => {
                task.PostResult(new Done(response.BodyJson));
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// When you have data about friends from another social network, you can post them to CotC servers using
        /// these function.
        /// This will automatically add them as a friend on CotC as they get recognized on our servers.
        /// The friends get associated to the domain of this object.
        /// Note: this function was once called PostSocialNetworkFriends but renamed due to it being misleading.
        /// </summary>
        /// <returns>Promise resolved when the operation has completed. The attached value is the same list as passed,
        ///     enriched with potential information about the gamer (member #CotcSdk.SocialNetworkFriend.ClanInfo) for
        ///     gamers who are already registered on CotC servers.</returns>
        /// <param name="network">The network with which these friends are associated.</param>
        /// <param name="friends">A list of data about the friends fetched on the social network.</param>
        /// <param name="automatching">If true, synchronizes the CotC friends with the list. That is, the provided
        /// social network friends become your friends on CotC as well (reported on ListFriends and such).</param>
        public Promise<SocialNetworkFriendResponse> ListNetworkFriends(LoginNetwork network, List<SocialNetworkFriend> friends, bool automatching = false)
        {
            var task = new Promise<SocialNetworkFriendResponse>();
            UrlBuilder url = new UrlBuilder("/v2.12/gamer/friends").Path(domain).QueryParam("network", network.Describe());
            HttpRequest req = Gamer.MakeHttpRequest(url);
            Bundle body = Bundle.CreateObject();
            Bundle friendData = (body["friends"] = Bundle.CreateObject());
            foreach (SocialNetworkFriend f in friends) {
                friendData[f.Id] = f.ToBundle();
            }
            body["automatching"] = automatching;

            req.BodyJson = body;
            return Common.RunRequest(req, task, (HttpResponse response) => {
                task.PostResult(new SocialNetworkFriendResponse(response.BodyJson));
            });
        }