Skip to content

Instantly share code, notes, and snippets.

@MarkArts
Created March 7, 2018 08:19
Show Gist options
  • Save MarkArts/84684319a650c3148e69b3e34bb7d06b to your computer and use it in GitHub Desktop.
Save MarkArts/84684319a650c3148e69b3e34bb7d06b to your computer and use it in GitHub Desktop.
generics.cs
public class ApiCall<POSTDATATYPE, POSTRESPONSETYPE, GETRESPONSETYPE>
where POSTDATATYPE:class
where POSTRESPONSETYPE:class
where GETRESPONSETYPE:class
{
public string endpoint;
public EntrailsApi api;
public ApiCall(string endpoint, EntrailsApi api)
{
this.endpoint = endpoint;
this.api = api;
}
public Task<GETRESPONSETYPE> get(string token){
return api.get<GETRESPONSETYPE>(endpoint, token);
}
public Task<POSTRESPONSETYPE> post(POSTDATATYPE postdata, string token){
return api.post<POSTRESPONSETYPE, POSTDATATYPE>(endpoint, postdata, token);
}
}
public ApiCall<userInvite, InviteResponse, UsersResponse> Users;
public ApiCall<Coupon, CouponResponse, EmptyResponse> Coupons;
public ApiCall<EmptyResponse, EmptyResponse, ConfigResponse> Config;
public EntrailsApi(System.Uri url, string adminToken){
this.url = url;
this.adminToken = adminToken;
this.Users = new ApiCall<userInvite, InviteResponse, UsersResponse>("/users/", this);
this.Coupons = new ApiCall<Coupon, CouponResponse, EmptyResponse>("/coupons/", this);
this.Config = new ApiCall<EmptyResponse, EmptyResponse, ConfigResponse>("/config/", this);
this.Config = new ApiCall<EmptyResponse, EmptyResponse, ConfigResponse>("/config/", this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment