C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
ExtensionMethods.Rest.ICollection[T].cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using RestSharp;
4
5namespace AnalyzeRe
6{
8 public static partial class ExtensionMethods
9 {
17 public static T GetItem<T>(this APITypes.IResourceCollection<T> collection, string id,
18 IEnumerable<Parameter> parameters = null, int? timeout = null)
19 where T : IAPIType
20 {
21 API.ValidateResourceId(id);
22 return API.RequestAndParse<T>($"{collection.Path}/{id}",
23 Method.GET, parameters, timeout);
24 }
25
38 public static ICollectionResponse<T> GetItems<T>(this APITypes.IResourceCollection<T> collection,
39 IEnumerable<string> ids, IEnumerable<Parameter> parameters = null, int? timeout = null)
40 where T : IAPIType
41 {
42 List<string> idList = ids as List<string> ?? ids.ToList();
43 return API.RequestAndParse<CollectionResponse<T>>(collection.Path, Method.GET,
44 // Ensure the page size is enough to get all ids at once
45 API.Parameters.Page(0, idList.Count).AddParameters(parameters)
46 .AddParameters(API.Parameters.Ids(idList)),
48 }
49
58 public static ICollectionResponse<T> List<T>(this APITypes.IResourceCollection<T> collection,
59 long offset, long limit, IEnumerable<Parameter> parameters = null, int? timeout = null)
60 where T : IAPIType
61 {
62 return API.RequestAndParse<CollectionResponse<T>>(collection.Path,
63 Method.GET, API.Parameters.Page(offset, limit).AddParameters(parameters),
65 }
66
73 public static long Count<T>(this APITypes.IResourceCollection<T> collection,
74 IEnumerable<Parameter> parameters = null, int? timeout = null)
75 where T : IAPIType
76 => List(collection, 0, 0, parameters, timeout).meta.total_count;
77
85 public static T Post<T>(this APITypes.IResourceCollection<T> collection, T item,
86 IEnumerable<Parameter> parameters = null, int? timeout = null)
87 where T : IAPIType
88 {
89 return API.RequestAndParse<T>(collection.Path,
90 Method.POST, API.AddRequestBodyParameters(parameters, item), timeout);
91 }
92 }
93}
Parameters that can be added to your REST requests to access additional API features.
static RequestParameters Ids(IEnumerable< string > ids)
Can be added to your collection GET requests to return only the set of resources whose id matches one...
static RequestParameters Page(long offset, long limit)
When getting a collection of items, these parameters can be added to restrict the number of results y...
API methods / requests made available to the user.
static int DefaultRequestTimeoutCollections
The default timeout used when requesting a resource collection from the server, in milliseconds.
static object RequestAndParse(Type deserializeType, string resource, Method method, IEnumerable< Parameter > requestParameters=null, int? timeout=null)
Perform a REST request on the server and serializes the response to the desired run-time type.
Implements the reference entity interface, with support for resolving references using lazy loading.
static ICollectionResponse< T > List< T >(this APITypes.IResourceCollection< T > collection, long offset, long limit, IEnumerable< Parameter > parameters=null, int? timeout=null)
Performs a GET request to list the collection at this endpoint.
static object Post(this IAPIResource obj, Type deserializeType, IEnumerable< Parameter > requestParameters=null, int? timeout=null)
Perform a POST on the current resource, returning the server response deserialized to a new object of...
static ICollectionResponse< T > GetItems< T >(this APITypes.IResourceCollection< T > collection, IEnumerable< string > ids, IEnumerable< Parameter > parameters=null, int? timeout=null)
Searches this collection for a list of resource ids and returns a collection response containing all ...
static long Count< T >(this APITypes.IResourceCollection< T > collection, IEnumerable< Parameter > parameters=null, int? timeout=null)
Get the number of items in this collection.
static T GetItem< T >(this APITypes.IResourceCollection< T > collection, string id, IEnumerable< Parameter > parameters=null, int? timeout=null)
Performs a GET request for a specific resource in this collection.
Interface shared by all object types and resources returned by the Analyze Re server.
Definition IAPIType.cs:6
Covariant interface for the generic collection response type.