Skip to content

Commit

Permalink
adding some summary documentation, changing names of the tons of DoRe…
Browse files Browse the repository at this point in the history
…quest calls
  • Loading branch information
slorello89 committed Feb 5, 2020
1 parent 40a6481 commit 8084e8b
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 92 deletions.
12 changes: 6 additions & 6 deletions Nexmo.Api/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class Number
/// <returns>Balance data</returns>
public static Balance GetBalance(Credentials credentials = null)
{
return ApiRequest.DoRequest<Balance>(ApiRequest.GetBaseUriFor(typeof(Account),
return ApiRequest.DoGetRequest<Balance>(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-balance"),
// TODO: using this method sig allows us to have the api auth injected at the expense of opaque code here
new Dictionary<string, string>(),
Expand All @@ -131,7 +131,7 @@ public static Pricing GetPricing(string country, string type = null, Credentials
parameters.Add("type", type);
}

return ApiRequest.DoRequest<Pricing>(ApiRequest.GetBaseUriFor(typeof(Account),
return ApiRequest.DoGetRequest<Pricing>(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-pricing/outbound/"),
parameters,
credentials);
Expand All @@ -145,7 +145,7 @@ public static Pricing GetPrefixPricing(string prefix, string type, Credentials c
{ "type", type }
};

return ApiRequest.DoRequest<Pricing>(ApiRequest.GetBaseUriFor(typeof(Account),
return ApiRequest.DoGetRequest<Pricing>(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-prefix-pricing/outbound/"),
parameters,
credentials);
Expand All @@ -169,7 +169,7 @@ public static Settings SetSettings(string newsecret = null, string httpMoCallbac
if (null != httpDrCallbackurlCom)
parameters.Add("drCallBackUrl", httpDrCallbackurlCom);

return ApiRequest.DoPostRequest<Settings>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/settings"), parameters, credentials);
return ApiRequest.DoPostRequestWithUrlContent<Settings>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/settings"), parameters, credentials);
}

/// <summary>
Expand All @@ -179,7 +179,7 @@ public static Settings SetSettings(string newsecret = null, string httpMoCallbac
/// <param name="credentials">(Optional) Overridden credentials for only this request</param>
public static void TopUp(string transaction, Credentials credentials = null)
{
ApiRequest.DoRequest<Topup>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/top-up"), new Dictionary<string, string>
ApiRequest.DoGetRequest<Topup>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/top-up"), new Dictionary<string, string>
{
{"trx", transaction}
},
Expand All @@ -206,7 +206,7 @@ public static NumbersResponse GetNumbers(Credentials credentials = null)
/// <returns></returns>
public static NumbersResponse GetNumbers(NumbersRequest request, Credentials credentials = null)
{
return ApiRequest.DoRequest<NumbersResponse>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers"), request, credentials);
return ApiRequest.DoGetRequest<NumbersResponse>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers"), request, ApiRequest.AuthType.Query, credentials);
}
}
}
8 changes: 4 additions & 4 deletions Nexmo.Api/ApiSecret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SecretRequest
/// <returns>List of secrets</returns>
public static List<Secret> ListSecrets(string apiKey, Credentials creds = null)
{
return ApiRequest.DoRequest<Response<SecretList>>(ApiRequest.GetBaseUriFor(typeof(ApiSecret),
return ApiRequest.DoGetRequest<Response<SecretList>>(ApiRequest.GetBaseUriFor(typeof(ApiSecret),
$"/accounts/{apiKey}/secrets"),
// TODO: using this method sig allows us to have the api auth injected at the expense of opaque code here
new Dictionary<string, string>(),
Expand All @@ -51,7 +51,7 @@ public static List<Secret> ListSecrets(string apiKey, Credentials creds = null)
/// <returns>The secret</returns>
public static Secret GetSecret(string apiKey, string secretId, Credentials creds = null)
{
return ApiRequest.DoRequest<Secret>(ApiRequest.GetBaseUriFor(typeof(ApiSecret),
return ApiRequest.DoGetRequest<Secret>(ApiRequest.GetBaseUriFor(typeof(ApiSecret),
$"/accounts/{apiKey}/secrets/{secretId}"),
// TODO: using this method sig allows us to have the api auth injected at the expense of opaque code here
new Dictionary<string, string>(),
Expand All @@ -72,7 +72,7 @@ public static Secret GetSecret(string apiKey, string secretId, Credentials creds
/// <returns>The created secret</returns>
public static Secret CreateSecret(string apiKey, string newSecret, Credentials creds = null)
{
var response = ApiRequest.DoRequest("POST", ApiRequest.GetBaseUriFor(typeof(ApiSecret), $"/accounts/{apiKey}/secrets"), new SecretRequest { Secret = newSecret }, ApiRequest.AuthType.Basic, creds);
var response = ApiRequest.DoRequestWithJsonContent("POST", ApiRequest.GetBaseUriFor(typeof(ApiSecret), $"/accounts/{apiKey}/secrets"), new SecretRequest { Secret = newSecret }, ApiRequest.AuthType.Basic, creds);

return JsonConvert.DeserializeObject<Secret>(response.JsonResponse);
}
Expand All @@ -84,7 +84,7 @@ public static Secret CreateSecret(string apiKey, string newSecret, Credentials c
/// <param name="secretId">ID of the API Secret</param>
public static bool DeleteSecret(string apiKey, string secretId, Credentials creds = null)
{
var response = ApiRequest.DoRequest("DELETE", ApiRequest.GetBaseUriFor(typeof(ApiSecret),
var response = ApiRequest.DoRequestWithJsonContent("DELETE", ApiRequest.GetBaseUriFor(typeof(ApiSecret),
$"/accounts/{apiKey}/secrets/{secretId}"), null, ApiRequest.AuthType.Basic, creds);

return response.Status == HttpStatusCode.NoContent;
Expand Down
8 changes: 4 additions & 4 deletions Nexmo.Api/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public static List<ApplicationResponse> List(int PageSize = 10, int PageIndex =
{
return new List<ApplicationResponse>
{
ApiRequest.DoRequest<ApplicationResponse>(ApiRequest.GetBaseUriFor(typeof(Application),
ApiRequest.DoGetRequest<ApplicationResponse>(ApiRequest.GetBaseUriFor(typeof(Application),
$"/v1/applications/{AppId}"),
// TODO: using this method sig allows us to have the api auth injected at the expense of opaque code here
new Dictionary<string, string>(),
creds)
};
}

return ApiRequest.DoRequest<ApplicationListResponse>(ApiRequest.GetBaseUriFor(typeof(Application), "/v1/applications"),
return ApiRequest.DoGetRequest<ApplicationListResponse>(ApiRequest.GetBaseUriFor(typeof(Application), "/v1/applications"),
new Dictionary<string, string>
{
{ "page_size", PageSize.ToString()},
Expand All @@ -154,7 +154,7 @@ public static List<ApplicationResponse> List(int PageSize = 10, int PageIndex =
public static ApplicationResponse Update(ApplicationRequest request, Credentials creds = null)
{
var sb = ApiRequest.GetQueryStringBuilderFor(request, ApiRequest.AuthType.Query);
return ApiRequest.DoPutRequest<ApplicationResponse>(ApiRequest.GetBaseUriFor(typeof(Application),
return ApiRequest.DoPutRequestWithUrlContent<ApplicationResponse>(ApiRequest.GetBaseUriFor(typeof(Application),
$"/v1/applications/{request.id}?{sb}"), null, creds);
}

Expand All @@ -167,7 +167,7 @@ public static ApplicationResponse Update(ApplicationRequest request, Credentials
public static bool Delete(string appId, Credentials creds = null)
{
var sb = ApiRequest.GetQueryStringBuilderFor(new object(), ApiRequest.AuthType.Query);
var response = ApiRequest.DoDeleteRequest(ApiRequest.GetBaseUriFor(typeof(Application),
var response = ApiRequest.DoDeleteRequestWithUrlContent(ApiRequest.GetBaseUriFor(typeof(Application),
$"/v1/applications/{appId}?{sb}"), null, creds);

return response.Status == HttpStatusCode.NoContent;
Expand Down
10 changes: 5 additions & 5 deletions Nexmo.Api/ApplicationV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class ApplicationV2
/// <returns></returns>
public static AppResponse Create(AppRequest request, Credentials credentials = null)
{
var response = ApiRequest.DoRequest("POST",ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"), request, ApiRequest.AuthType.Basic, credentials);
var response = ApiRequest.DoRequestWithJsonContent("POST",ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"), request, ApiRequest.AuthType.Basic, credentials);

return JsonConvert.DeserializeObject<AppResponse>(response.JsonResponse);
}
Expand All @@ -194,7 +194,7 @@ public static AppResponse Create(AppRequest request, Credentials credentials = n
/// <returns></returns>
public static AppResponse Get(string appId, Credentials credentials = null)
{
return ApiRequest.DoRequest<AppResponse>(ApiRequest.GetBaseUriFor(typeof(ApplicationV2), $"/v2/applications/{appId}"), ApiRequest.AuthType.Query, credentials);
return ApiRequest.DoGetRequest<AppResponse>(ApiRequest.GetBaseUriFor(typeof(ApplicationV2), $"/v2/applications/{appId}"), ApiRequest.AuthType.Query, credentials);
}

/// <summary>
Expand All @@ -208,7 +208,7 @@ public static AppResponse Get(string appId, Credentials credentials = null)
public static List<AppResponse> List(int pageSize = 10, int page = 0, Credentials credentials = null)
{
var filter = new AppListFilter() { page = page, page_size = pageSize };
return ApiRequest.DoRequest<AppListResponse>(ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"), filter, ApiRequest.AuthType.Basic, credentials)._embedded.Applications;
return ApiRequest.DoGetRequest<AppListResponse>(ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"), filter, ApiRequest.AuthType.Basic, credentials)._embedded.Applications;

}

Expand All @@ -226,7 +226,7 @@ public static List<AppResponse> List()
/// <returns></returns>
public static AppResponse Update(AppRequest request, Credentials credentials = null)
{
var response = ApiRequest.DoRequest("PUT",ApiRequest.GetBaseUriFor(typeof(ApplicationV2),
var response = ApiRequest.DoRequestWithJsonContent("PUT",ApiRequest.GetBaseUriFor(typeof(ApplicationV2),
$"/v2/applications/{request.Id}"), request, ApiRequest.AuthType.Basic, credentials);

return JsonConvert.DeserializeObject<AppResponse>(response.JsonResponse);
Expand All @@ -240,7 +240,7 @@ public static AppResponse Update(AppRequest request, Credentials credentials = n
/// <returns></returns>
public static bool Delete(string appId, Credentials credentials = null)
{
var response = ApiRequest.DoRequest("DELETE",ApiRequest.GetBaseUriFor(typeof(ApplicationV2),
var response = ApiRequest.DoRequestWithJsonContent("DELETE",ApiRequest.GetBaseUriFor(typeof(ApplicationV2),
$"/v2/applications/{appId}"), null, ApiRequest.AuthType.Basic, credentials);

return response.Status == HttpStatusCode.NoContent;
Expand Down
2 changes: 1 addition & 1 deletion Nexmo.Api/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static Configuration()

private Configuration()
{
var logger = Api.Logger.LogProvider.GetLogger(LOGGER_CATEGORY);
var logger = Logger.LogProvider.GetLogger(LOGGER_CATEGORY);
var builder = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
Expand Down
8 changes: 4 additions & 4 deletions Nexmo.Api/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class SearchResults

public static SearchResults ListOwnNumbers(SearchRequest request, Credentials creds = null)
{
return ApiRequest.DoRequest<SearchResults>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers/"), request, creds);
return ApiRequest.DoGetRequest<SearchResults>(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers/"), request, ApiRequest.AuthType.Query, creds);
}
/// <summary>
/// Retrieve the list of virtual numbers available for a specific country.
Expand All @@ -109,7 +109,7 @@ public static SearchResults ListOwnNumbers(SearchRequest request, Credentials cr
/// <returns></returns>
public static SearchResults Search(SearchRequest request, Credentials creds = null)
{
return ApiRequest.DoRequest<SearchResults>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/search/"), request, creds);
return ApiRequest.DoGetRequest<SearchResults>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/search/"), request, ApiRequest.AuthType.Query, creds);
}

/// <summary>
Expand All @@ -121,7 +121,7 @@ public static SearchResults Search(SearchRequest request, Credentials creds = nu
/// <returns></returns>
public static ResponseBase Buy(string country, string number, Credentials creds = null)
{
return ApiRequest.DoPostRequest<ResponseBase>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/buy"), new Dictionary<string, string>
return ApiRequest.DoPostRequestWithUrlContent<ResponseBase>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/buy"), new Dictionary<string, string>
{
{"country", country},
{"msisdn", number}
Expand Down Expand Up @@ -149,7 +149,7 @@ public static ResponseBase Update(NumberUpdateCommand cmd, Credentials creds = n
/// <returns></returns>
public static ResponseBase Cancel(string country, string number, Credentials creds = null)
{
return ApiRequest.DoPostRequest<ResponseBase>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/cancel"), new Dictionary<string, string>
return ApiRequest.DoPostRequestWithUrlContent<ResponseBase>(ApiRequest.GetBaseUriFor(typeof(Number), "/number/cancel"), new Dictionary<string, string>
{
{"country", country},
{"msisdn", number}
Expand Down
2 changes: 1 addition & 1 deletion Nexmo.Api/NumberInsight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static NumberInsightAsyncRequestResponse RequestAsync(NumberInsightAsyncR
parameters.Add("ip", request.IPAddress);
}

return ApiRequest.DoPostRequest<NumberInsightAsyncRequestResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/ni/advanced/async/json"), parameters, creds);
return ApiRequest.DoPostRequestWithUrlContent<NumberInsightAsyncRequestResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/ni/advanced/async/json"), parameters, creds);
}

public class NumberInsightResponseException : Exception
Expand Down
8 changes: 4 additions & 4 deletions Nexmo.Api/NumberVerify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class VerifyResponse : VerifyResponseBase
/// <returns></returns>
public static VerifyResponse Verify(VerifyRequest request, Credentials creds = null)
{
var response = ApiRequest.DoRequest<VerifyResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/json"), request, creds);
var response = ApiRequest.DoGetRequest<VerifyResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/json"), request, ApiRequest.AuthType.Query, creds);
ValidateVerifyResponse(response);
return response;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public class CheckResponse : VerifyResponseBase
/// <returns></returns>
public static CheckResponse Check(CheckRequest request, Credentials creds = null)
{
var response = ApiRequest.DoRequest<CheckResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/check/json"),
var response = ApiRequest.DoGetRequest<CheckResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/check/json"),
new Dictionary<string, string>
{
{"request_id", request.request_id},
Expand Down Expand Up @@ -224,7 +224,7 @@ public class CheckObj
/// <returns></returns>
public static SearchResponse Search(SearchRequest request, Credentials creds = null)
{
return ApiRequest.DoRequest<SearchResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/search/json"), new Dictionary<string, string>()
return ApiRequest.DoGetRequest<SearchResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/search/json"), new Dictionary<string, string>()
{
{"request_id", request.request_id},
{"request_ids", request.request_ids}
Expand Down Expand Up @@ -262,7 +262,7 @@ public class ControlResponse : VerifyResponseBase
/// <returns></returns>
public static ControlResponse Control(ControlRequest request, Credentials creds = null)
{
var response = ApiRequest.DoRequest<ControlResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/control/json"), request, creds);
var response = ApiRequest.DoGetRequest<ControlResponse>(ApiRequest.GetBaseUriFor(typeof(NumberVerify), "/verify/control/json"), request, ApiRequest.AuthType.Query, creds);
ValidateVerifyResponse(response);
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion Nexmo.Api/Redact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public RedactRequest(string id, string product, string type)
/// <returns></returns>
public static NexmoResponse RedactTransaction(RedactRequest redactRequest, Credentials creds = null)
{
return ApiRequest.DoRequest("POST",ApiRequest.GetBaseUriFor(typeof(Redact), "/v1/redact/transaction"), redactRequest, ApiRequest.AuthType.Basic, creds);
return ApiRequest.DoRequestWithJsonContent("POST",ApiRequest.GetBaseUriFor(typeof(Redact), "/v1/redact/transaction"), redactRequest, ApiRequest.AuthType.Basic, creds);
}
}
}
Loading

0 comments on commit 8084e8b

Please sign in to comment.