Example #1
0
 public void TestBuildRequestUriUnmatchedPathTemplateThrows()
 {
     Assert.Throws <KeyNotFoundException>(() => Marshalling.BuildRequestUri("/test/{foo}/{some}",
                                                                            new Dictionary <string, object>
     {
         { "foo", "bar" },
     },
                                                                            new Dictionary <string, object>()
                                                                            ));
 }
Example #2
0
        /// <summary>
        /// Modify alias details. Modify alias details.
        /// </summary>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="id">Name of AppBundle (unqualified).</param>/// <param name="aliasId">Name of alias.</param>/// <param name="alias">Alias details to be modified.</param>
        /// <returns>Task of ApiResponse<Alias></returns>

        public async System.Threading.Tasks.Task <ApiResponse <Alias> > ModifyAppBundleAliasAsync(string id, string aliasId, AliasPatch alias, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/appbundles/{id}/aliases/{aliasId}",
                                                routeParameters: new Dictionary <string, object> {
                    { "id", id },
                    { "aliasId", aliasId },
                },
                                                queryParameters: new Dictionary <string, object> {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }

                request.Content = Marshalling.Serialize(alias); // http body (model) parameter

                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("PATCH");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(new ApiResponse <Alias>(response, default(Alias)));
                }

                return(new ApiResponse <Alias>(response, await Marshalling.DeserializeAsync <Alias>(response.Content)));
            } // using
        }
Example #3
0
        /// <summary>
        /// Creates/updates the nickname for the current Forge app.
        /// </summary>
        /// <remarks>
        /// Creates/updates the nickname for the current Forge app.  The nickname is  used as a clearer alternative name when identifying AppBundles and Activities, as  compared to using the Forge app ID.  Once you have defined a nickname,  it MUST be used instead of the Forge app ID.                The new nickname cannot be in use by any other Forge app.                The Forge app cannot have any data when this endpoint is invoked.  Use the &#39;DELETE /forgeapps/me&#39;  endpoint (cautiously!!!) to remove all data from this Forge app.  &#39;DELETE /forgeapps/me&#39; is  also the only way to remove the nickname.                Note the nickname is supplied in the body, not as a query-parameter.
        /// </remarks>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="id">Must be \&quot;me\&quot; for the call to succeed.</param>/// <param name="nicknameRecord">new nickname (public key is for internal use only).</param>

        /// <returns>Task of HttpResponseMessage</returns>
        public async System.Threading.Tasks.Task <HttpResponseMessage> CreateNicknameAsync(string id, NicknameRecord nicknameRecord, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/forgeapps/{id}",
                                                routeParameters: new Dictionary <string, object> {
                    { "id", id },
                },
                                                queryParameters: new Dictionary <string, object> {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }

                request.Content = Marshalling.Serialize(nicknameRecord); // http body (model) parameter

                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("PATCH");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(response);
                }

                return(response);
            } // using
        }
Example #4
0
        /// <summary>
        /// Deletes the specified version of the AppBundle. Deletes the specified version of the AppBundle.
        /// </summary>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="id">Name of AppBundle (unqualified).</param>/// <param name="version">Version to delete (as integer).</param>

        /// <returns>Task of HttpResponseMessage</returns>
        public async System.Threading.Tasks.Task <HttpResponseMessage> DeleteAppBundleVersionAsync(string id, int version, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/appbundles/{id}/versions/{version}",
                                                routeParameters: new Dictionary <string, object> {
                    { "id", id },
                    { "version", version },
                },
                                                queryParameters: new Dictionary <string, object> {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }


                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("DELETE");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(response);
                }

                return(response);
            } // using
        }
        /// <summary>
        /// Lists all versions of the specified Activity.
        /// </summary>
        /// <remarks>
        /// Lists all versions of the specified Activity.
        /// </remarks>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="id">Name of Activity (unqualified).</param>/// <param name="page">Access an additional &#39;page&#39; of data when necessary, based on the &#39;paginationToken&#39; returned from a previous invocation. (optional)</param>
        /// <returns>Task of ApiResponse<Page&lt;int&gt;></returns>

        public async System.Threading.Tasks.Task <ApiResponse <Page <int> > > GetActivityVersionsAsync(string id, string page = null, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/activities/{id}/versions",
                                                routeParameters: new Dictionary <string, object> {
                    { "id", id },
                },
                                                queryParameters: new Dictionary <string, object> {
                    { "page", page },
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }


                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("GET");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(new ApiResponse <Page <int> >(response, default(Page <int>)));
                }

                return(new ApiResponse <Page <int> >(response, await Marshalling.DeserializeAsync <Page <int> >(response.Content)));
            } // using
        }
        /// <summary>
        /// Creates a new service limits configuration or updates an exiting one.
        /// </summary>
        /// <remarks>
        /// User can only update the following 2 properties:                - frontendLimits.limitMonthlyProcessingTimeInHours  - backendLimits[/engine/].limitProcessingTimeSec                LimitProcessingTimeSec cannot be set greater than the maximum processing time limit specified by the engine.
        /// </remarks>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="owner">The user to associate the configuration to.</param>/// <param name="item"></param>
        /// <returns>Task of ApiResponse<ServiceLimit></returns>

        public async System.Threading.Tasks.Task <ApiResponse <ServiceLimit> > ModifyServiceLimitsAsync(string owner, ServiceLimit item, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/servicelimits/{owner}",
                                                routeParameters: new Dictionary <string, object> {
                    { "owner", owner },
                },
                                                queryParameters: new Dictionary <string, object> {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }

                request.Content = Marshalling.Serialize(item); // http body (model) parameter

                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("PUT");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(new ApiResponse <ServiceLimit>(response, default(ServiceLimit)));
                }

                return(new ApiResponse <ServiceLimit>(response, await Marshalling.DeserializeAsync <ServiceLimit>(response.Content)));
            } // using
        }
Example #7
0
        /// <summary>
        /// Creates new WorkItems and queues them for processing.
        /// </summary>
        /// <remarks>
        /// The new WorkItems are always placed on the queue and later picked up by an engine.                The following limits apply:                Per-engine. These limits are enforced when the engine processes the workitem.                1. Number of downloads (LimitDownloads)  2. Number of uploads (LimitUploads)  3. Total download size (LimitDownloadSize)  4. Total upload size (LimitUploadSize)  5. Processing time (LimitProcessingTime)  6. Total size of uncompressed bits for all referenced appbundles (LimitTotalUncompressedAppsSizePerActivity).                Service wide. These limits are enforced during workitem submission.                7. Total processing time per month (LimitMonthlyProcessingTimeInHours).
        /// </remarks>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="workItems"></param>
        /// <returns>Task of ApiResponse<List&lt;WorkItemStatus&gt;></returns>

        public async System.Threading.Tasks.Task <ApiResponse <List <WorkItemStatus> > > CreateWorkItemsBatchAsync(List <WorkItem> workItems, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/workitems/batch",
                                                routeParameters: new Dictionary <string, object> {
                },
                                                queryParameters: new Dictionary <string, object> {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }

                request.Content = Marshalling.Serialize(workItems); // http body (model) parameter

                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Properties.Add(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("POST");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(new ApiResponse <List <WorkItemStatus> >(response, default(List <WorkItemStatus>)));
                }

                return(new ApiResponse <List <WorkItemStatus> >(response, await Marshalling.DeserializeAsync <List <WorkItemStatus> >(response.Content)));
            } // using
        }
Example #8
0
        public void TestBuildRequestUriValid()
        {
            var uri = Marshalling.BuildRequestUri("/test/{foo}/{some}",
                                                  new Dictionary <string, object>
            {
                { "foo", "bar" },
                { "some", "stuff" },
            },
                                                  new Dictionary <string, object>
            {
                { "page", "blabla" },
                { "count", "3" }
            }
                                                  );

            Assert.Equal("test/bar/stuff?page=blabla&count=3&", uri.OriginalString);
        }
        /// <summary>
        /// Returns the app's nickname and optional public key.
        /// </summary>
        /// <remarks>
        /// Return the given Forge app's nickname and public key if one has been uploaded
        /// If the app has no nickname, this route will return its id.
        /// </remarks>
        /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
        /// <param name="id">Must be "me" for the call to succeed.</param>
        /// <returns>Task of ApiResponse<string></returns>
        public async System.Threading.Tasks.Task <ApiResponse <NicknameRecord> > GetNicknameRecordAsync(string id, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true)
        {
            using (var request = new HttpRequestMessage())
            {
                request.RequestUri =
                    Marshalling.BuildRequestUri("/v3/forgeapps/{id}",
                                                routeParameters: new Dictionary <string, object> {
                    { "id", id },
                },
                                                queryParameters: new Dictionary <string, object>
                {
                }
                                                );

                request.Headers.TryAddWithoutValidation("Accept", "application/json");
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        request.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    }
                }


                // tell the underlying pipeline what scope we'd like to use
                if (scopes == null)
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, "code:all");
                }
                else
                {
                    request.Options.Set(ForgeConfiguration.ScopeKey, scopes);
                }

                request.Method = new HttpMethod("GET");

                // make the HTTP request
                var response = await this.Service.Client.SendAsync(request);

                if (throwOnError)
                {
                    await response.EnsureSuccessStatusCodeAsync();
                }
                else if (!response.IsSuccessStatusCode)
                {
                    return(new ApiResponse <NicknameRecord>(response, default(NicknameRecord)));
                }
                // response.Content is either simply a nickname or a JSON of the form {nickname:<nickname>, publicKey:<publicKey>}. We must handle both.
                var str = await response.Content.ReadAsStringAsync();

                str = str.Trim();
                if (str.StartsWith("{"))
                {
                    return(new ApiResponse <NicknameRecord>(response, JsonConvert.DeserializeObject <NicknameRecord>(str)));
                }
                else
                {
                    var nickname = JsonConvert.DeserializeObject <string>(str);
                    return(new ApiResponse <NicknameRecord>(response, new NicknameRecord()
                    {
                        Nickname = nickname
                    }));
                }
            } // using
        }