-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Binali Rustamov
committed
Dec 22, 2019
1 parent
70f94b7
commit 2a5c8cb
Showing
28 changed files
with
485 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using RestSharp; | ||
|
||
namespace PortainerClient.Api | ||
namespace PortainerClient.Api.Base | ||
{ | ||
/// <summary> | ||
/// Helpers for the Portainer API | ||
/// </summary> | ||
public static class BaseApiHelpers | ||
{ | ||
public static void AddParameters(this RestRequest request, | ||
/// <summary> | ||
/// Fill the request with provided parameters | ||
/// </summary> | ||
/// <param name="request">API request</param> | ||
/// <param name="parameters">List with request parameters</param> | ||
public static void AddParameters(this IRestRequest request, | ||
IEnumerable<(string paramName, object paramValue)> parameters) | ||
{ | ||
foreach (var (paramName, paramValue) in parameters) request.AddParameter(paramName, paramValue); | ||
} | ||
|
||
/// <summary> | ||
/// Fill the request with provided parameters | ||
/// </summary> | ||
/// <param name="request">API request</param> | ||
/// <param name="parameters">List with request parameters</param> | ||
/// <exception cref="InvalidOperationException">Occurs when parameter type is not implemented</exception> | ||
public static void AddParameters(this IRestRequest request, | ||
IEnumerable<(string paramName, object value, ParamType type)> parameters) | ||
{ | ||
foreach (var (paramName, value, type) in parameters) | ||
{ | ||
switch (type) | ||
{ | ||
case ParamType.File: | ||
request.AddFile(paramName, value.ToString()); | ||
break; | ||
case ParamType.QueryParam: | ||
request.AddQueryParameter(paramName, value.ToString()); | ||
break; | ||
case ParamType.BodyParam: | ||
request.AddParameter(paramName, value); | ||
break; | ||
case ParamType.JsonBody: | ||
request.RequestFormat = DataFormat.Json; | ||
request.AddJsonBody(value); | ||
break; | ||
default: | ||
throw new InvalidOperationException($"You should define parameter type for {paramName} "); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,28 @@ | ||
namespace PortainerClient.Api.Base | ||
{ | ||
/// <summary> | ||
/// Request parameter types | ||
/// </summary> | ||
public enum ParamType | ||
{ | ||
/// <summary> | ||
/// File parameter (send file to server) | ||
/// </summary> | ||
File, | ||
|
||
/// <summary> | ||
/// Query parameter (attach parameter to query string) | ||
/// </summary> | ||
QueryParam, | ||
|
||
/// <summary> | ||
/// Body parameter (attach parameter to body (form)) | ||
/// </summary> | ||
BodyParam, | ||
|
||
/// <summary> | ||
/// JSON Body parameter (attach parameter as JSON Body of request) | ||
/// </summary> | ||
JsonBody | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// General model for Portainer API error | ||
/// </summary> | ||
public class ApiError | ||
{ | ||
/// <summary> | ||
/// Message about occured error | ||
/// </summary> | ||
public string message { get; set; } | ||
/// <summary> | ||
/// Occured error details | ||
/// </summary> | ||
public string details { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// Model for authorization process | ||
/// </summary> | ||
public class AuthInfo | ||
{ | ||
/// <summary> | ||
/// User's login | ||
/// </summary> | ||
public string Username { get; set; } | ||
/// <summary> | ||
/// User's password | ||
/// </summary> | ||
public string Password { get; set; } | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// Model for stack's environment variable | ||
/// </summary> | ||
public class StackEnv | ||
{ | ||
/// <summary> | ||
/// Environment variable name | ||
/// </summary> | ||
public string Name { get; set; } | ||
/// <summary> | ||
/// Environment variable value | ||
/// </summary> | ||
public string Value { get; set; } | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// Stack file inspect model | ||
/// </summary> | ||
public class StackFileInspect | ||
{ | ||
/// <summary> | ||
/// Stack file content (as string) | ||
/// </summary> | ||
public string StackFileContent { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// Stack types | ||
/// </summary> | ||
public enum StackType | ||
{ | ||
/// <summary> | ||
/// Swarm stack | ||
/// </summary> | ||
Swarm = 1, | ||
/// <summary> | ||
/// Docker compose stack | ||
/// </summary> | ||
Compose = 2 | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
namespace PortainerClient.Api.Model | ||
{ | ||
/// <summary> | ||
/// Token information model | ||
/// </summary> | ||
public class TokenInfo | ||
{ | ||
/// <summary> | ||
/// JWT Token for authorized user | ||
/// </summary> | ||
public string Jwt { get; set; } | ||
} | ||
} | ||
} |
Oops, something went wrong.