generated from FromDoppler/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from FromDoppler/refactor-get-api-client
Add RestClientExtensions
- Loading branch information
Showing
2 changed files
with
46 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using RestSharp; | ||
|
||
namespace DopplerBeplic.Services.Classes | ||
{ | ||
public static class RestClientExtensions | ||
{ | ||
public static async Task<RestResponse> ExecuteResource(this IRestClient client, string accessToken, string resource, object body, Method method) | ||
{ | ||
var request = new RestRequest(resource, method); | ||
request.AddJsonBody(body); | ||
request.AddHeader("Content-Type", "application/json"); | ||
request.AddHeader("Authorization", "Bearer " + accessToken); | ||
|
||
return await client.ExecuteAsync(request); | ||
} | ||
|
||
public static async Task<RestResponse> ExecuteResource(this IRestClient client, string accessToken, string resource, Parameter[] parameters, Method method) | ||
{ | ||
var request = new RestRequest(resource, method); | ||
request.AddHeader("Content-Type", "application/json"); | ||
request.AddHeader("Authorization", "Bearer " + accessToken); | ||
request.Parameters.AddParameters(parameters); | ||
|
||
return await client.ExecuteAsync(request); | ||
} | ||
|
||
public static async Task<RestResponse> ExecuteResource(this IRestClient client, string accessToken, string resource, Method method) | ||
{ | ||
var request = new RestRequest(resource, method); | ||
request.AddHeader("Content-Type", "application/json"); | ||
request.AddHeader("Authorization", "Bearer " + accessToken); | ||
|
||
return await client.ExecuteAsync(request); | ||
} | ||
} | ||
} |