-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
280 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file modified
BIN
+1013 Bytes
(100%)
Playtomic/out/production/Playtomic/Playtomic.unaligned.apk
Binary file not shown.
Binary file modified
BIN
+170 Bytes
(110%)
Playtomic/out/production/Playtomic/com/playtomic/android/PResponse.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.playtomic.android; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class Newsletter { | ||
|
||
private static String SECTION = "newsletter"; | ||
private static String SUBSCRIBE = "subscribe"; | ||
|
||
/** | ||
* Subscribes a person to your newsletter | ||
* @param options JSONObject with email and other fields you configure | ||
* @param callback NewsletterSubscribeHandler for receiving the response | ||
*/ | ||
public static void subscribe(JSONObject options, final NewsletterSubscribeHandler callback) { | ||
PRequest.load(SECTION, SUBSCRIBE, options, new PResponseHandler() { | ||
|
||
@Override | ||
public void onResponse(PResponse response, JSONObject data) { | ||
if(response.getSuccess()) { | ||
callback.onSuccess(response); | ||
} else { | ||
callback.onFailure(response); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Playtomic/src/com/playtomic/android/NewsletterSubscribeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.playtomic.android; | ||
|
||
public interface NewsletterSubscribeHandler { | ||
void onSuccess(PResponse response); | ||
void onFailure(PResponse response); | ||
} |
38 changes: 38 additions & 0 deletions
38
Playtomic/src/com/playtomic/android/NewsletterSubscription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.playtomic.android; | ||
import org.json.JSONObject; | ||
import org.json.JSONException; | ||
|
||
public class NewsletterSubscription extends JSONObject { | ||
|
||
public void set(String name, Object value) { | ||
try { | ||
put(name, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
|
||
public void setEmail(String email) { | ||
set("email", email); | ||
} | ||
|
||
public void setFirstName(String firstname) { | ||
set("firstname", firstname); | ||
} | ||
|
||
public void setLastName(String lastname) { | ||
set("lastname", lastname); | ||
} | ||
|
||
public void setField(String name, Object value) { | ||
if(!has("fields")) { | ||
set("fields", new JSONObject()); | ||
} | ||
|
||
try { | ||
optJSONObject("fields").put(name, value); | ||
} catch(JSONException err) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.playtomic.tests; | ||
|
||
import com.playtomic.android.Newsletter; | ||
import com.playtomic.android.NewsletterSubscribeHandler; | ||
import com.playtomic.android.NewsletterSubscription; | ||
import com.playtomic.android.PResponse; | ||
|
||
public class PTestNewsletter extends PTest { | ||
|
||
public static void subscribe(final TestHandler callback) { | ||
|
||
final String section = "TestNewsletter.subscribe"; | ||
|
||
final NewsletterSubscription options = new NewsletterSubscription(); | ||
options.setEmail("invalid @email.com"); | ||
|
||
Newsletter.subscribe(options, new NewsletterSubscribeHandler() { | ||
|
||
@Override | ||
public void onFailure(PResponse r) { | ||
assertFalse(section, "Request failed", r.getSuccess()); | ||
assertEquals(section, "No errorcode", r.getErrorCode(), 602); | ||
|
||
options.setEmail("valid@testuri.com"); | ||
options.setField("STRINGFIELD", "a value"); | ||
|
||
Newsletter.subscribe(options, new NewsletterSubscribeHandler() { | ||
|
||
@Override | ||
public void onSuccess(PResponse r2) { | ||
assertTrue(section + "#2", "Request succeeded", r2.getSuccess()); | ||
assertEquals(section + "#2", "No errorcode", r2.getErrorCode(), 0); | ||
callback.done(); | ||
} | ||
@Override | ||
public void onFailure(PResponse response) { | ||
fail(section, "Request failed with errorcode " + response.getErrorCode()); | ||
callback.done(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onSuccess(PResponse response) { | ||
fail(section, "Request failed with errorcode " + response.getErrorCode()); | ||
callback.done(); | ||
} | ||
}); | ||
} | ||
} |