Skip to content

Commit

Permalink
Account renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 committed Feb 28, 2020
1 parent 8a39abd commit be09252
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 7 deletions.
17 changes: 17 additions & 0 deletions Nexmo.Api/Applications/Application.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;
using Nexmo.Api.Applications.Capabilities;

namespace Nexmo.Api.Applications
{
public class Application
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("capabilities")]
public Capability[] Capabilities { get; set; }
}
}
63 changes: 63 additions & 0 deletions Nexmo.Api/Applications/ApplicationClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Nexmo.Api.Request;

namespace Nexmo.Api.Applications
{
public class ApplicationClient : IApplicationClient
{
public Credentials Credentials { get; set; }
public ApplicationClient(Credentials creds)
{
Credentials = creds;
}
public Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null)
{
return ApiRequest.DoRequestWithJsonContent<Application>(
"POST",
ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"),
request,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
}

public PaginatedResponse<ApplicationList> ListApplications(ListApplicationsRequest request, Credentials creds = null)
{
return ApiRequest.DoGetRequestWithUrlContent<PaginatedResponse<Api.Applications.ApplicationList>>(
ApiRequest.GetBaseUriFor(typeof(ApplicationV2), "/v2/applications"),
ApiRequest.AuthType.Basic,
request,
creds ?? Credentials
);
}

public Application GetApplication(string id, Credentials creds)
{
return ApiRequest.DoGetRequestWithUrlContent<Application>(
ApiRequest.GetBaseUriFor(typeof(ApplicationV2), $"/v2/applications{id}"),
ApiRequest.AuthType.Basic,
credentials: creds ?? Credentials
);
}

public Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null)
{
return ApiRequest.DoRequestWithJsonContent<Application>(
"PUT",
ApiRequest.GetBaseUriFor(typeof(ApplicationV2), $"/v2/applications{id}"),
request,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
}

public bool DeleteApplication(string id, Credentials creds)
{
ApiRequest.DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUriFor(typeof(ApplicationV2), $"/v2/applications{id}"),
null,
creds ?? Credentials
);
return true;
}
}
}
10 changes: 10 additions & 0 deletions Nexmo.Api/Applications/ApplicationList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Nexmo.Api.Applications
{
public class ApplicationList
{
[JsonProperty("applications")]
public IList<Application> Applications { get; set; }
}
}
28 changes: 28 additions & 0 deletions Nexmo.Api/Applications/Capabilities/Capability.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.ComponentModel;
using Nexmo.Api.Common;
using Newtonsoft.Json;

namespace Nexmo.Api.Applications.Capabilities
{
public abstract class Capability
{
[JsonProperty("webhooks")]
public IDictionary<Common.Webhook.Type,Common.Webhook> Webhooks { get; set; }

[JsonIgnore]
public CapabilityType Type { get; protected set; }

public enum CapabilityType
{
[Description("voice")]
Voice,
[Description("rtc")]
Rtc,
[Description("messages")]
Messages,
[Description("vbc")]
Vbc
}
}
}
14 changes: 14 additions & 0 deletions Nexmo.Api/Applications/Capabilities/Messages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;

namespace Nexmo.Api.Applications.Capabilities
{
public class Messages : Capability
{
public Messages(IDictionary<Common.Webhook.Type, Common.Webhook> webhooks)
{
this.Webhooks = webhooks;
this.Type = CapabilityType.Messages;
}

}
}
13 changes: 13 additions & 0 deletions Nexmo.Api/Applications/Capabilities/Rtc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Nexmo.Api.Applications.Capabilities
{
public class Rtc : Capability
{
public Rtc(IDictionary<Common.Webhook.Type, Common.Webhook> webhooks)
{
this.Webhooks = webhooks;
this.Type = CapabilityType.Rtc;
}
}
}
10 changes: 10 additions & 0 deletions Nexmo.Api/Applications/Capabilities/Vbc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Nexmo.Api.Applications.Capabilities
{
public class Vbc : Capability
{
public Vbc()
{
Type = CapabilityType.Vbc;
}
}
}
13 changes: 13 additions & 0 deletions Nexmo.Api/Applications/Capabilities/Voice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Nexmo.Api.Applications.Capabilities
{
public class Voice : Capability
{
public Voice(IDictionary<Common.Webhook.Type, Common.Webhook> webhooks)
{
this.Webhooks = Webhooks;
this.Type = Capability.CapabilityType.Voice;
}
}
}
18 changes: 18 additions & 0 deletions Nexmo.Api/Applications/CreateApplicationRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;
using Nexmo.Api.Applications.Capabilities;

namespace Nexmo.Api.Applications
{
public class CreateApplicationRequest
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("capabilities")]
public Capability[] Capabilities { get; set; }

[JsonProperty("keys")]
public Keys Keys { get; set; }

}
}
13 changes: 13 additions & 0 deletions Nexmo.Api/Applications/IApplicationClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Nexmo.Api.Request;

namespace Nexmo.Api.Applications
{
public interface IApplicationClient
{
Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null);
PaginatedResponse<ApplicationList> ListApplications(ListApplicationsRequest request, Credentials creds = null);
Application GetApplication(string id, Credentials creds);
Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null);
bool DeleteApplication(string id, Credentials creds);
}
}
10 changes: 10 additions & 0 deletions Nexmo.Api/Applications/Keys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Nexmo.Api.Applications
{
public class Keys
{
[JsonProperty("public_key")]
public string PublicKey { get; set; }
}
}
13 changes: 13 additions & 0 deletions Nexmo.Api/Applications/ListApplicationsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Nexmo.Api.Applications
{
public class ListApplicationsRequest
{
[JsonProperty("page_size")]
public int PageSize { get; set; }

[JsonProperty("page")]
public int Page { get; set; }
}
}
7 changes: 0 additions & 7 deletions Nexmo.Api/Client/AccountClient.cs

This file was deleted.

30 changes: 30 additions & 0 deletions Nexmo.Api/Common/Webhook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.ComponentModel;
using System.Net.Http;
using Newtonsoft.Json;

namespace Nexmo.Api.Common
{
public class Webhook
{
[JsonProperty("http_method")]
public HttpMethod Method { get; set; }

[JsonProperty("address")]
public string Address { get; set; }

public enum Type
{
[Description("answer_url")]
Answer=1,
[Description("event_url")]
Event=2,
[Description("inbound_url")]
Inbound=3,
[Description("status_url")]
Status=4,
[Description("unknown")]
Unknown=5
}

}
}

0 comments on commit be09252

Please sign in to comment.