Skip to content

Commit

Permalink
Added toJSONObject to new state classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkasten2 committed Apr 27, 2017
1 parent 58cbfce commit ee0e053
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import android.content.SharedPreferences;

import org.json.JSONObject;

import static com.onesignal.OneSignal.appContext;
import static com.onesignal.OneSignal.getGcmPreferences;

Expand Down Expand Up @@ -84,6 +86,24 @@ protected Object clone() {
return null;
}

public JSONObject toJSONObject() {
JSONObject mainObj = new JSONObject();

try {
mainObj.put("enabled", enabled);
}
catch(Throwable t) {
t.printStackTrace();
}

return mainObj;
}

@Override
public String toString() {
return toJSONObject().toString();
}


// FUTURE: Can add a list of categories here for Android O.
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

package com.onesignal;

import org.json.JSONObject;

public class OSPermissionStateChanges {
OSPermissionState to, from;

Expand All @@ -37,4 +39,23 @@ public OSPermissionState getTo() {
public OSPermissionState getFrom() {
return from;
}

public JSONObject toJSONObject() {
JSONObject mainObj = new JSONObject();

try {
mainObj.put("from", from.toJSONObject());
mainObj.put("to", to.toJSONObject());
}
catch(Throwable t) {
t.printStackTrace();
}

return mainObj;
}

@Override
public String toString() {
return toJSONObject().toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
/**
* Modified MIT License
*
* Copyright 2017 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.onesignal;

import org.json.JSONObject;

public class OSPermissionSubscriptionState {
OSSubscriptionState subscriptionStatus;
OSPermissionState permissionStatus;
Expand All @@ -11,4 +40,23 @@ public OSPermissionState getPermissionStatus() {
public OSSubscriptionState getSubscriptionStatus() {
return subscriptionStatus;
}

public JSONObject toJSONObject() {
JSONObject mainObj = new JSONObject();

try {
mainObj.put("permissionStatus", permissionStatus.toJSONObject());
mainObj.put("subscriptionStatus", subscriptionStatus.toJSONObject());
}
catch(Throwable t) {
t.printStackTrace();
}

return mainObj;
}

@Override
public String toString() {
return toJSONObject().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import android.content.SharedPreferences;

import org.json.JSONObject;

import static com.onesignal.OneSignal.appContext;
import static com.onesignal.OneSignal.getGcmPreferences;

Expand Down Expand Up @@ -136,4 +138,25 @@ protected Object clone() {
} catch (Throwable t) {}
return null;
}

public JSONObject toJSONObject() {
JSONObject mainObj = new JSONObject();

try {
mainObj.put("userId", userId);
mainObj.put("pushToken", pushToken);
mainObj.put("userSubscriptionSetting", userSubscriptionSetting);
mainObj.put("subscribed", getSubscribed());
}
catch(Throwable t) {
t.printStackTrace();
}

return mainObj;
}

@Override
public String toString() {
return toJSONObject().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

package com.onesignal;

import org.json.JSONObject;

public class OSSubscriptionStateChanges {
OSSubscriptionState to, from;

Expand All @@ -37,4 +39,23 @@ public OSSubscriptionState getTo() {
public OSSubscriptionState getFrom() {
return from;
}

public JSONObject toJSONObject() {
JSONObject mainObj = new JSONObject();

try {
mainObj.put("from", from.toJSONObject());
mainObj.put("to", to.toJSONObject());
}
catch(Throwable t) {
t.printStackTrace();
}

return mainObj;
}

@Override
public String toString() {
return toJSONObject().toString();
}
}

0 comments on commit ee0e053

Please sign in to comment.