Example #1
0
        public static string DeployServerCode(BaseApp app, string code)
        {
            string        adminToken = GetAdminToken(app);
            string        url        = Utils.Path(Kii.BaseUrl, "apps", app.AppId, "server-code");
            KiiHttpClient client     = new KiiClientFactoryImpl().Create(url, app.AppId, app.AppKey, KiiHttpMethod.POST);

            client.Headers["Authorization"] = "Bearer " + adminToken;
            client.ContentType = "application/javascript";
            client.Body        = code;

            ApiResponse response = client.SendRequest();

            return(new JsonObject(response.Body).GetString("versionID"));
        }
Example #2
0
        public static string GetAdminToken(BaseApp app)
        {
            JsonObject body = new JsonObject();

            body.Put("grant_type", "client_credentials");
            body.Put("client_id", app.ClientId);
            body.Put("client_secret", app.ClientSecret);

            string        url    = Utils.Path(Kii.BaseUrl, "apps", app.AppId, "oauth2", "token");
            KiiHttpClient client = new KiiClientFactoryImpl().Create(url, app.AppId, app.AppKey, KiiHttpMethod.POST);

            client.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(app.AppId + ":" + app.AppKey));
            client.ContentType = "application/json";
            client.Body        = body.ToString();
            ApiResponse response = client.SendRequest();

            return(new JsonObject(response.Body).GetString("access_token"));
        }