diff --git a/PushSharp.Google/Exceptions.cs b/PushSharp.Google/Exceptions.cs index b27da6ec..a68ab188 100644 --- a/PushSharp.Google/Exceptions.cs +++ b/PushSharp.Google/Exceptions.cs @@ -4,34 +4,34 @@ namespace PushSharp.Google { - public class GcmNotificationException : NotificationException + public class FcmNotificationException : NotificationException { - public GcmNotificationException (GcmNotification notification, string msg) : base (msg, notification) + public FcmNotificationException (FcmNotification notification, string msg) : base (msg, notification) { Notification = notification; } - public GcmNotificationException (GcmNotification notification, string msg, string description) : base (msg, notification) + public FcmNotificationException (FcmNotification notification, string msg, string description) : base (msg, notification) { Notification = notification; Description = description; } - public new GcmNotification Notification { get; private set; } + public new FcmNotification Notification { get; private set; } public string Description { get; private set; } } - public class GcmMulticastResultException : Exception + public class FcmMulticastResultException : Exception { - public GcmMulticastResultException () : base ("One or more Registration Id's failed in the multicast notification") + public FcmMulticastResultException () : base ("One or more Registration Id's failed in the multicast notification") { - Succeeded = new List (); - Failed = new Dictionary (); + Succeeded = new List (); + Failed = new Dictionary (); } - public List Succeeded { get;set; } + public List Succeeded { get;set; } - public Dictionary Failed { get;set; } + public Dictionary Failed { get;set; } } } diff --git a/PushSharp.Google/GcmConfiguration.cs b/PushSharp.Google/FcmConfiguration.cs similarity index 67% rename from PushSharp.Google/GcmConfiguration.cs rename to PushSharp.Google/FcmConfiguration.cs index 91f320ff..caba060a 100644 --- a/PushSharp.Google/GcmConfiguration.cs +++ b/PushSharp.Google/FcmConfiguration.cs @@ -2,24 +2,24 @@ namespace PushSharp.Google { - public class GcmConfiguration + public class FcmConfiguration { - private const string GCM_SEND_URL = "https://gcm-http.googleapis.com/gcm/send"; + private const string FCM_SEND_URL = "https://fcm.googleapis.com/fcm/send"; - public GcmConfiguration (string senderAuthToken) + public FcmConfiguration (string senderAuthToken) { this.SenderAuthToken = senderAuthToken; - this.GcmUrl = GCM_SEND_URL; + this.FcmUrl = FCM_SEND_URL; this.ValidateServerCertificate = false; } - public GcmConfiguration (string optionalSenderID, string senderAuthToken, string optionalApplicationIdPackageName) + public FcmConfiguration (string optionalSenderID, string senderAuthToken, string optionalApplicationIdPackageName) { this.SenderID = optionalSenderID; this.SenderAuthToken = senderAuthToken; this.ApplicationIdPackageName = optionalApplicationIdPackageName; - this.GcmUrl = GCM_SEND_URL; + this.FcmUrl = FCM_SEND_URL; this.ValidateServerCertificate = false; } @@ -32,11 +32,11 @@ public GcmConfiguration (string optionalSenderID, string senderAuthToken, string public bool ValidateServerCertificate { get; set; } - public string GcmUrl { get; set; } + public string FcmUrl { get; set; } public void OverrideUrl (string url) { - GcmUrl = url; + FcmUrl = url; } } } diff --git a/PushSharp.Google/GcmMessageResult.cs b/PushSharp.Google/FcmMessageResult.cs similarity index 59% rename from PushSharp.Google/GcmMessageResult.cs rename to PushSharp.Google/FcmMessageResult.cs index e467505c..03a1863d 100644 --- a/PushSharp.Google/GcmMessageResult.cs +++ b/PushSharp.Google/FcmMessageResult.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using System.Net.Http; using System.Net.Http.Headers; @@ -6,7 +6,7 @@ namespace PushSharp.Google { - public class GcmMessageResult + public class FcmMessageResult { [JsonProperty("message_id", NullValueHandling = NullValueHandling.Ignore)] public string MessageId { get; set; } @@ -15,7 +15,7 @@ public class GcmMessageResult public string CanonicalRegistrationId { get; set; } [JsonIgnore] - public GcmResponseStatus ResponseStatus { get; set; } + public FcmResponseStatus ResponseStatus { get; set; } [JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)] public string Error @@ -24,35 +24,35 @@ public string Error { switch (ResponseStatus) { - case GcmResponseStatus.Ok: + case FcmResponseStatus.Ok: return null; - case GcmResponseStatus.Unavailable: + case FcmResponseStatus.Unavailable: return "Unavailable"; - case GcmResponseStatus.QuotaExceeded: + case FcmResponseStatus.QuotaExceeded: return "QuotaExceeded"; - case GcmResponseStatus.NotRegistered: + case FcmResponseStatus.NotRegistered: return "NotRegistered"; - case GcmResponseStatus.MissingRegistrationId: + case FcmResponseStatus.MissingRegistrationId: return "MissingRegistration"; - case GcmResponseStatus.MissingCollapseKey: + case FcmResponseStatus.MissingCollapseKey: return "MissingCollapseKey"; - case GcmResponseStatus.MismatchSenderId: + case FcmResponseStatus.MismatchSenderId: return "MismatchSenderId"; - case GcmResponseStatus.MessageTooBig: + case FcmResponseStatus.MessageTooBig: return "MessageTooBig"; - case GcmResponseStatus.InvalidTtl: + case FcmResponseStatus.InvalidTtl: return "InvalidTtl"; - case GcmResponseStatus.InvalidRegistration: + case FcmResponseStatus.InvalidRegistration: return "InvalidRegistration"; - case GcmResponseStatus.InvalidDataKey: + case FcmResponseStatus.InvalidDataKey: return "InvalidDataKey"; - case GcmResponseStatus.InternalServerError: + case FcmResponseStatus.InternalServerError: return "InternalServerError"; - case GcmResponseStatus.DeviceQuotaExceeded: + case FcmResponseStatus.DeviceQuotaExceeded: return null; - case GcmResponseStatus.CanonicalRegistrationId: + case FcmResponseStatus.CanonicalRegistrationId: return null; - case GcmResponseStatus.Error: + case FcmResponseStatus.Error: return "Error"; default: return null; diff --git a/PushSharp.Google/GcmNotification.cs b/PushSharp.Google/FcmNotification.cs similarity index 92% rename from PushSharp.Google/GcmNotification.cs rename to PushSharp.Google/FcmNotification.cs index 28ba0599..efdc60e7 100644 --- a/PushSharp.Google/GcmNotification.cs +++ b/PushSharp.Google/FcmNotification.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.Serialization; using Newtonsoft.Json.Linq; using System.Collections.Generic; @@ -8,11 +8,11 @@ namespace PushSharp.Google { - public class GcmNotification : INotification + public class FcmNotification : INotification { - public static GcmNotification ForSingleResult (GcmResponse response, int resultIndex) + public static FcmNotification ForSingleResult (FcmResponse response, int resultIndex) { - var result = new GcmNotification (); + var result = new FcmNotification (); result.Tag = response.OriginalNotification.Tag; result.MessageId = response.OriginalNotification.MessageId; @@ -31,9 +31,9 @@ public static GcmNotification ForSingleResult (GcmResponse response, int resultI return result; } - public static GcmNotification ForSingleRegistrationId (GcmNotification msg, string registrationId) + public static FcmNotification ForSingleRegistrationId (FcmNotification msg, string registrationId) { - var result = new GcmNotification (); + var result = new FcmNotification (); result.Tag = msg.Tag; result.MessageId = msg.MessageId; result.RegistrationIds.Add (registrationId); @@ -49,7 +49,7 @@ public static GcmNotification ForSingleRegistrationId (GcmNotification msg, stri return result; } - public GcmNotification () + public FcmNotification () { RegistrationIds = new List (); CollapseKey = string.Empty; @@ -101,7 +101,7 @@ public bool IsDeviceRegistrationIdValid () public JObject Notification { get; set; } /// - /// If true, GCM will only be delivered once the device's screen is on + /// If true, FCM will only be delivered once the device's screen is on /// [JsonProperty ("delay_while_idle")] public bool? DelayWhileIdle { get; set; } @@ -121,7 +121,7 @@ public bool IsDeviceRegistrationIdValid () /// /// A string that maps a single user to multiple registration IDs associated with that user. This allows a 3rd-party server to send a single message to multiple app instances (typically on multiple devices) owned by a single user. /// - [Obsolete ("Deprecated on GCM Server API. Use Device Group Messaging to send to multiple devices.")] + [Obsolete ("Deprecated on FCM Server API. Use Device Group Messaging to send to multiple devices.")] public string NotificationKey { get; set; } /// @@ -142,7 +142,7 @@ public bool IsDeviceRegistrationIdValid () /// /// The priority. [JsonProperty ("priority"), JsonConverter (typeof (Newtonsoft.Json.Converters.StringEnumConverter))] - public GcmNotificationPriority? Priority { get; set; } + public FcmNotificationPriority? Priority { get; set; } internal string GetJson () { @@ -163,7 +163,7 @@ public override string ToString () } } - public enum GcmNotificationPriority + public enum FcmNotificationPriority { [EnumMember (Value="normal")] Normal = 5, diff --git a/PushSharp.Google/GcmResponse.cs b/PushSharp.Google/FcmResponse.cs similarity index 83% rename from PushSharp.Google/GcmResponse.cs rename to PushSharp.Google/FcmResponse.cs index f580d014..53975019 100644 --- a/PushSharp.Google/GcmResponse.cs +++ b/PushSharp.Google/FcmResponse.cs @@ -5,17 +5,17 @@ namespace PushSharp.Google { - public class GcmResponse + public class FcmResponse { - public GcmResponse() + public FcmResponse() { MulticastId = -1; NumberOfSuccesses = 0; NumberOfFailures = 0; NumberOfCanonicalIds = 0; OriginalNotification = null; - Results = new List(); - ResponseCode = GcmResponseCode.Ok; + Results = new List(); + ResponseCode = FcmResponseCode.Ok; } [JsonProperty("multicast_id")] @@ -31,16 +31,16 @@ public GcmResponse() public long NumberOfCanonicalIds { get; set; } [JsonIgnore] - public GcmNotification OriginalNotification { get; set; } + public FcmNotification OriginalNotification { get; set; } [JsonProperty("results")] - public List Results { get; set; } + public List Results { get; set; } [JsonIgnore] - public GcmResponseCode ResponseCode { get; set; } + public FcmResponseCode ResponseCode { get; set; } } - public enum GcmResponseCode + public enum FcmResponseCode { Ok, Error, @@ -50,7 +50,7 @@ public enum GcmResponseCode InternalServiceError } - public enum GcmResponseStatus + public enum FcmResponseStatus { [EnumMember (Value="Ok")] Ok, diff --git a/PushSharp.Google/GcmServiceConnection.cs b/PushSharp.Google/FcmServiceConnection.cs similarity index 76% rename from PushSharp.Google/GcmServiceConnection.cs rename to PushSharp.Google/FcmServiceConnection.cs index b3b539c5..5921ebb1 100644 --- a/PushSharp.Google/GcmServiceConnection.cs +++ b/PushSharp.Google/FcmServiceConnection.cs @@ -11,31 +11,31 @@ namespace PushSharp.Google { - public class GcmServiceConnectionFactory : IServiceConnectionFactory + public class FcmServiceConnectionFactory : IServiceConnectionFactory { - public GcmServiceConnectionFactory (GcmConfiguration configuration) + public FcmServiceConnectionFactory (FcmConfiguration configuration) { Configuration = configuration; } - public GcmConfiguration Configuration { get; private set; } + public FcmConfiguration Configuration { get; private set; } - public IServiceConnection Create() + public IServiceConnection Create() { - return new GcmServiceConnection (Configuration); + return new FcmServiceConnection (Configuration); } } - public class GcmServiceBroker : ServiceBroker + public class FcmServiceBroker : ServiceBroker { - public GcmServiceBroker (GcmConfiguration configuration) : base (new GcmServiceConnectionFactory (configuration)) + public FcmServiceBroker (FcmConfiguration configuration) : base (new FcmServiceConnectionFactory (configuration)) { } } - public class GcmServiceConnection : IServiceConnection + public class FcmServiceConnection : IServiceConnection { - public GcmServiceConnection (GcmConfiguration configuration) + public FcmServiceConnection (FcmConfiguration configuration) { Configuration = configuration; http = new HttpClient (); @@ -45,17 +45,17 @@ public GcmServiceConnection (GcmConfiguration configuration) http.DefaultRequestHeaders.TryAddWithoutValidation ("Authorization", "key=" + Configuration.SenderAuthToken); } - public GcmConfiguration Configuration { get; private set; } + public FcmConfiguration Configuration { get; private set; } readonly HttpClient http; - public async Task Send (GcmNotification notification) + public async Task Send (FcmNotification notification) { var json = notification.GetJson (); var content = new StringContent (json, System.Text.Encoding.UTF8, "application/json"); - var response = await http.PostAsync (Configuration.GcmUrl, content); + var response = await http.PostAsync (Configuration.FcmUrl, content); if (response.IsSuccessStatusCode) { await processResponseOk (response, notification).ConfigureAwait (false); @@ -64,12 +64,12 @@ public async Task Send (GcmNotification notification) } } - async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification notification) + async Task processResponseOk (HttpResponseMessage httpResponse, FcmNotification notification) { - var multicastResult = new GcmMulticastResultException (); + var multicastResult = new FcmMulticastResultException (); - var result = new GcmResponse () { - ResponseCode = GcmResponseCode.Ok, + var result = new FcmResponse () { + ResponseCode = FcmResponseCode.Ok, OriginalNotification = notification }; @@ -83,18 +83,18 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification var jsonResults = json ["results"] as JArray ?? new JArray (); foreach (var r in jsonResults) { - var msgResult = new GcmMessageResult (); + var msgResult = new FcmMessageResult (); msgResult.MessageId = r.Value ("message_id"); msgResult.CanonicalRegistrationId = r.Value ("registration_id"); - msgResult.ResponseStatus = GcmResponseStatus.Ok; + msgResult.ResponseStatus = FcmResponseStatus.Ok; if (!string.IsNullOrEmpty (msgResult.CanonicalRegistrationId)) - msgResult.ResponseStatus = GcmResponseStatus.CanonicalRegistrationId; + msgResult.ResponseStatus = FcmResponseStatus.CanonicalRegistrationId; else if (r ["error"] != null) { var err = r.Value ("error") ?? ""; - msgResult.ResponseStatus = GetGcmResponseStatus (err); + msgResult.ResponseStatus = GetFcmResponseStatus (err); } result.Results.Add (msgResult); @@ -106,13 +106,13 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification // We will raise events for each individual result so that the consumer of the library // can deal with individual registrationid's for the notification foreach (var r in result.Results) { - var singleResultNotification = GcmNotification.ForSingleResult (result, index); + var singleResultNotification = FcmNotification.ForSingleResult (result, index); singleResultNotification.MessageId = r.MessageId; - if (r.ResponseStatus == GcmResponseStatus.Ok) { // Success + if (r.ResponseStatus == FcmResponseStatus.Ok) { // Success multicastResult.Succeeded.Add (singleResultNotification); - } else if (r.ResponseStatus == GcmResponseStatus.CanonicalRegistrationId) { //Need to swap reg id's + } else if (r.ResponseStatus == FcmResponseStatus.CanonicalRegistrationId) { //Need to swap reg id's //Swap Registrations Id's var newRegistrationId = r.CanonicalRegistrationId; var oldRegistrationId = string.Empty; @@ -131,9 +131,9 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification OldSubscriptionId = oldRegistrationId, NewSubscriptionId = newRegistrationId }); - } else if (r.ResponseStatus == GcmResponseStatus.Unavailable) { // Unavailable - multicastResult.Failed.Add (singleResultNotification, new GcmNotificationException (singleResultNotification, "Unavailable Response Status")); - } else if (r.ResponseStatus == GcmResponseStatus.NotRegistered) { //Bad registration Id + } else if (r.ResponseStatus == FcmResponseStatus.Unavailable) { // Unavailable + multicastResult.Failed.Add (singleResultNotification, new FcmNotificationException (singleResultNotification, "Unavailable Response Status")); + } else if (r.ResponseStatus == FcmResponseStatus.NotRegistered) { //Bad registration Id var oldRegistrationId = string.Empty; if (singleResultNotification.RegistrationIds != null && singleResultNotification.RegistrationIds.Count > 0) @@ -149,7 +149,7 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification new DeviceSubscriptionExpiredException (singleResultNotification) { OldSubscriptionId = oldRegistrationId }); } else { - multicastResult.Failed.Add (singleResultNotification, new GcmNotificationException (singleResultNotification, "Unknown Failure: " + r.ResponseStatus)); + multicastResult.Failed.Add (singleResultNotification, new FcmNotificationException (singleResultNotification, "Unknown Failure: " + r.ResponseStatus)); } index++; @@ -170,7 +170,7 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification throw multicastResult; } - async Task processResponseError (HttpResponseMessage httpResponse, GcmNotification notification) + async Task processResponseError (HttpResponseMessage httpResponse, FcmNotification notification) { string responseBody = null; @@ -180,10 +180,10 @@ async Task processResponseError (HttpResponseMessage httpResponse, GcmNotificati //401 bad auth token if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - throw new UnauthorizedAccessException ("GCM Authorization Failed"); + throw new UnauthorizedAccessException ("FCM Authorization Failed"); if (httpResponse.StatusCode == HttpStatusCode.BadRequest) - throw new GcmNotificationException (notification, "HTTP 400 Bad Request", responseBody); + throw new FcmNotificationException (notification, "HTTP 400 Bad Request", responseBody); if ((int)httpResponse.StatusCode >= 500 && (int)httpResponse.StatusCode < 600) { //First try grabbing the retry-after header and parsing it. @@ -191,26 +191,26 @@ async Task processResponseError (HttpResponseMessage httpResponse, GcmNotificati if (retryAfterHeader != null && retryAfterHeader.Delta.HasValue) { var retryAfter = retryAfterHeader.Delta.Value; - throw new RetryAfterException (notification, "GCM Requested Backoff", DateTime.UtcNow + retryAfter); + throw new RetryAfterException (notification, "FCM Requested Backoff", DateTime.UtcNow + retryAfter); } } - throw new GcmNotificationException (notification, "GCM HTTP Error: " + httpResponse.StatusCode, responseBody); + throw new FcmNotificationException (notification, "FCM HTTP Error: " + httpResponse.StatusCode, responseBody); } - static GcmResponseStatus GetGcmResponseStatus (string str) + static FcmResponseStatus GetFcmResponseStatus (string str) { - var enumType = typeof(GcmResponseStatus); + var enumType = typeof(FcmResponseStatus); foreach (var name in Enum.GetNames (enumType)) { var enumMemberAttribute = ((EnumMemberAttribute[])enumType.GetField (name).GetCustomAttributes (typeof(EnumMemberAttribute), true)).Single (); if (enumMemberAttribute.Value.Equals (str, StringComparison.InvariantCultureIgnoreCase)) - return (GcmResponseStatus)Enum.Parse (enumType, name); + return (FcmResponseStatus)Enum.Parse (enumType, name); } //Default - return GcmResponseStatus.Error; + return FcmResponseStatus.Error; } } } diff --git a/PushSharp.Google/PushSharp.Google.csproj b/PushSharp.Google/PushSharp.Google.csproj index 92d72f31..126d903d 100644 --- a/PushSharp.Google/PushSharp.Google.csproj +++ b/PushSharp.Google/PushSharp.Google.csproj @@ -41,12 +41,12 @@ - - - - + + + + - + diff --git a/PushSharp.Tests/GcmRealTests.cs b/PushSharp.Tests/FcmRealTests.cs similarity index 72% rename from PushSharp.Tests/GcmRealTests.cs rename to PushSharp.Tests/FcmRealTests.cs index 4e915644..c3571d15 100644 --- a/PushSharp.Tests/GcmRealTests.cs +++ b/PushSharp.Tests/FcmRealTests.cs @@ -8,17 +8,17 @@ namespace PushSharp.Tests { [TestFixture] [Category ("Real")] - public class GcmRealTests + public class FcmRealTests { [Test] - public void Gcm_Send_Single () + public void Fcm_Send_Single () { var succeeded = 0; var failed = 0; var attempted = 0; - var config = new GcmConfiguration (Settings.Instance.GcmSenderId, Settings.Instance.GcmAuthToken, null); - var broker = new GcmServiceBroker (config); + var config = new FcmConfiguration (Settings.Instance.FcmSenderId, Settings.Instance.FcmAuthToken, null); + var broker = new FcmServiceBroker (config); broker.OnNotificationFailed += (notification, exception) => { failed++; }; @@ -28,10 +28,10 @@ public void Gcm_Send_Single () broker.Start (); - foreach (var regId in Settings.Instance.GcmRegistrationIds) { + foreach (var regId in Settings.Instance.FcmRegistrationIds) { attempted++; - broker.QueueNotification (new GcmNotification { + broker.QueueNotification (new FcmNotification { RegistrationIds = new List { regId }, diff --git a/PushSharp.Tests/GcmTests.cs b/PushSharp.Tests/FcmTests.cs similarity index 55% rename from PushSharp.Tests/GcmTests.cs rename to PushSharp.Tests/FcmTests.cs index 2590a207..adc60756 100644 --- a/PushSharp.Tests/GcmTests.cs +++ b/PushSharp.Tests/FcmTests.cs @@ -6,15 +6,15 @@ namespace PushSharp.Tests { - [Category ("GCM")] + [Category ("FCM")] [TestFixture] - public class GcmTests + public class FcmTests { [Test] - public void GcmNotification_Priority_Should_Serialize_As_String_High () + public void FcmNotification_Priority_Should_Serialize_As_String_High () { - var n = new GcmNotification (); - n.Priority = GcmNotificationPriority.High; + var n = new FcmNotification (); + n.Priority = FcmNotificationPriority.High; var str = n.ToString (); @@ -22,10 +22,10 @@ public void GcmNotification_Priority_Should_Serialize_As_String_High () } [Test] - public void GcmNotification_Priority_Should_Serialize_As_String_Normal () + public void FcmNotification_Priority_Should_Serialize_As_String_Normal () { - var n = new GcmNotification (); - n.Priority = GcmNotificationPriority.Normal; + var n = new FcmNotification (); + n.Priority = FcmNotificationPriority.Normal; var str = n.ToString (); diff --git a/PushSharp.Tests/PushSharp.Tests.csproj b/PushSharp.Tests/PushSharp.Tests.csproj index 6cdef5f4..56e56072 100644 --- a/PushSharp.Tests/PushSharp.Tests.csproj +++ b/PushSharp.Tests/PushSharp.Tests.csproj @@ -44,11 +44,11 @@ - + - + diff --git a/PushSharp.Tests/Settings.cs b/PushSharp.Tests/Settings.cs index 108b7b2f..f5caf6b7 100644 --- a/PushSharp.Tests/Settings.cs +++ b/PushSharp.Tests/Settings.cs @@ -50,12 +50,12 @@ public Settings () [JsonProperty ("apns_device_tokens")] public List ApnsDeviceTokens { get;set; } - [JsonProperty ("gcm_auth_token")] - public string GcmAuthToken { get;set; } - [JsonProperty ("gcm_sender_id")] - public string GcmSenderId { get;set; } - [JsonProperty ("gcm_registration_ids")] - public List GcmRegistrationIds { get;set; } + [JsonProperty ("fcm_auth_token")] + public string FcmAuthToken { get;set; } + [JsonProperty ("fcm_sender_id")] + public string FcmSenderId { get;set; } + [JsonProperty ("fcm_registration_ids")] + public List FcmRegistrationIds { get;set; } [JsonProperty ("adm_client_id")] public string AdmClientId { get;set; }