Skip to content

Commit ee0e053

Browse files
committed
Added toJSONObject to new state classes
1 parent 58cbfce commit ee0e053

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSPermissionState.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import android.content.SharedPreferences;
3131

32+
import org.json.JSONObject;
33+
3234
import static com.onesignal.OneSignal.appContext;
3335
import static com.onesignal.OneSignal.getGcmPreferences;
3436

@@ -84,6 +86,24 @@ protected Object clone() {
8486
return null;
8587
}
8688

89+
public JSONObject toJSONObject() {
90+
JSONObject mainObj = new JSONObject();
91+
92+
try {
93+
mainObj.put("enabled", enabled);
94+
}
95+
catch(Throwable t) {
96+
t.printStackTrace();
97+
}
98+
99+
return mainObj;
100+
}
101+
102+
@Override
103+
public String toString() {
104+
return toJSONObject().toString();
105+
}
106+
87107

88108
// FUTURE: Can add a list of categories here for Android O.
89109
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSPermissionStateChanges.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
package com.onesignal;
2929

30+
import org.json.JSONObject;
31+
3032
public class OSPermissionStateChanges {
3133
OSPermissionState to, from;
3234

@@ -37,4 +39,23 @@ public OSPermissionState getTo() {
3739
public OSPermissionState getFrom() {
3840
return from;
3941
}
42+
43+
public JSONObject toJSONObject() {
44+
JSONObject mainObj = new JSONObject();
45+
46+
try {
47+
mainObj.put("from", from.toJSONObject());
48+
mainObj.put("to", to.toJSONObject());
49+
}
50+
catch(Throwable t) {
51+
t.printStackTrace();
52+
}
53+
54+
return mainObj;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return toJSONObject().toString();
60+
}
4061
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSPermissionSubscriptionState.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
128
package com.onesignal;
229

30+
import org.json.JSONObject;
31+
332
public class OSPermissionSubscriptionState {
433
OSSubscriptionState subscriptionStatus;
534
OSPermissionState permissionStatus;
@@ -11,4 +40,23 @@ public OSPermissionState getPermissionStatus() {
1140
public OSSubscriptionState getSubscriptionStatus() {
1241
return subscriptionStatus;
1342
}
43+
44+
public JSONObject toJSONObject() {
45+
JSONObject mainObj = new JSONObject();
46+
47+
try {
48+
mainObj.put("permissionStatus", permissionStatus.toJSONObject());
49+
mainObj.put("subscriptionStatus", subscriptionStatus.toJSONObject());
50+
}
51+
catch(Throwable t) {
52+
t.printStackTrace();
53+
}
54+
55+
return mainObj;
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return toJSONObject().toString();
61+
}
1462
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSSubscriptionState.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import android.content.SharedPreferences;
3232

33+
import org.json.JSONObject;
34+
3335
import static com.onesignal.OneSignal.appContext;
3436
import static com.onesignal.OneSignal.getGcmPreferences;
3537

@@ -136,4 +138,25 @@ protected Object clone() {
136138
} catch (Throwable t) {}
137139
return null;
138140
}
141+
142+
public JSONObject toJSONObject() {
143+
JSONObject mainObj = new JSONObject();
144+
145+
try {
146+
mainObj.put("userId", userId);
147+
mainObj.put("pushToken", pushToken);
148+
mainObj.put("userSubscriptionSetting", userSubscriptionSetting);
149+
mainObj.put("subscribed", getSubscribed());
150+
}
151+
catch(Throwable t) {
152+
t.printStackTrace();
153+
}
154+
155+
return mainObj;
156+
}
157+
158+
@Override
159+
public String toString() {
160+
return toJSONObject().toString();
161+
}
139162
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSSubscriptionStateChanges.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
package com.onesignal;
2929

30+
import org.json.JSONObject;
31+
3032
public class OSSubscriptionStateChanges {
3133
OSSubscriptionState to, from;
3234

@@ -37,4 +39,23 @@ public OSSubscriptionState getTo() {
3739
public OSSubscriptionState getFrom() {
3840
return from;
3941
}
42+
43+
public JSONObject toJSONObject() {
44+
JSONObject mainObj = new JSONObject();
45+
46+
try {
47+
mainObj.put("from", from.toJSONObject());
48+
mainObj.put("to", to.toJSONObject());
49+
}
50+
catch(Throwable t) {
51+
t.printStackTrace();
52+
}
53+
54+
return mainObj;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return toJSONObject().toString();
60+
}
4061
}

0 commit comments

Comments
 (0)