Browse files

first checkin

  • Loading branch information...
0 parents commit fd0f6944fb1b29fe99a66f416c767d2daa0455e0 @arschles arschles committed Oct 11, 2011
Showing with 3,616 additions and 0 deletions.
  1. +11 −0 .gitignore
  2. +51 −0 Demo/.project
  3. +19 −0 Demo/AndroidManifest.xml
  4. +175 −0 Demo/LICENSE
  5. +12 −0 Demo/default.properties
  6. BIN Demo/libs/android-facebook-1.4.jar
  7. BIN Demo/libs/gson-1.7.1.jar
  8. BIN Demo/libs/signpost-commonshttp4-1.2.1.1.jar
  9. BIN Demo/libs/signpost-core-1.2.1.1.jar
  10. +116 −0 Demo/pom.xml
  11. +40 −0 Demo/proguard.cfg
  12. BIN Demo/res/drawable-hdpi/icon.png
  13. BIN Demo/res/drawable-ldpi/icon.png
  14. BIN Demo/res/drawable-mdpi/icon.png
  15. +12 −0 Demo/res/layout/main.xml
  16. +5 −0 Demo/res/values/strings.xml
  17. +48 −0 Demo/src/com/stackmob/android/demo/StackMobDemoActivity.java
  18. +175 −0 LICENSE
  19. +235 −0 README.md
  20. +45 −0 SDK/.project
  21. +35 −0 SDK/AndroidManifest.xml
  22. +175 −0 SDK/LICENSE
  23. +12 −0 SDK/default.properties
  24. +106 −0 SDK/pom.xml
  25. +40 −0 SDK/proguard.cfg
  26. BIN SDK/res/drawable-hdpi/icon.png
  27. BIN SDK/res/drawable-ldpi/icon.png
  28. BIN SDK/res/drawable-mdpi/icon.png
  29. +66 −0 SDK/src/com/stackmob/android/sdk/activity/FacebookActivity.java
  30. +142 −0 SDK/src/com/stackmob/android/sdk/activity/TwitterActivity.java
  31. +356 −0 SDK/src/com/stackmob/android/sdk/api/StackMob.java
  32. +243 −0 SDK/src/com/stackmob/android/sdk/api/StackMobRequest.java
  33. +128 −0 SDK/src/com/stackmob/android/sdk/api/StackMobSession.java
  34. +27 −0 SDK/src/com/stackmob/android/sdk/callback/StackMobCallback.java
  35. +27 −0 SDK/src/com/stackmob/android/sdk/callback/StackMobFacebookCallback.java
  36. +26 −0 SDK/src/com/stackmob/android/sdk/callback/StackMobTwitterCallback.java
  37. +55 −0 SDK/src/com/stackmob/android/sdk/demo/activity/FacebookDemoActivity.java
  38. +55 −0 SDK/src/com/stackmob/android/sdk/demo/activity/TwitterDemoActivity.java
  39. +27 −0 SDK/src/com/stackmob/android/sdk/exception/StackMobException.java
  40. +51 −0 SDK/src/com/stackmob/android/sdk/net/AcceptInvalidX509TrustManager.java
  41. +61 −0 SDK/src/com/stackmob/android/sdk/net/FollowPostRedirectHandler.java
  42. +233 −0 SDK/src/com/stackmob/android/sdk/net/HttpHelper.java
  43. +5 −0 SDK/src/com/stackmob/android/sdk/net/HttpVerb.java
  44. +97 −0 SDK/src/com/stackmob/android/sdk/net/SimpleSSLSocketFactory.java
  45. +72 −0 SDK/src/com/stackmob/android/sdk/net/SimpleX509TrustManager.java
  46. +71 −0 SDK/src/com/stackmob/android/sdk/util/EnvironmentInfoUtil.java
  47. +158 −0 SDK/tests/com/stackmob/android/sdk/api/StackMobRequestTest.java
  48. +48 −0 SDK/tests/com/stackmob/android/sdk/api/StackMobSessionTest.java
  49. +305 −0 SDK/tests/com/stackmob/android/sdk/api/StackMobTest.java
  50. +27 −0 SDK/tests/com/stackmob/android/sdk/api/StackMobTestCommon.java
  51. +24 −0 pom.xml
11 .gitignore
@@ -0,0 +1,11 @@
+bin
+.directory
+.DS_Store
+*.class
+*~
+gen
+.settings
+.classpath
+target
+
+tmp
51 Demo/.project
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>StackMobDemoActivity</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>stackmob-sdk_src</name>
+ <type>2</type>
+ <locationURI>_android_stackmob_sdk_86c32c65/src</locationURI>
+ </link>
+ <link>
+ <name>stackmob-sdk_tests</name>
+ <type>2</type>
+ <locationURI>_android_stackmob_sdk_86c32c65/tests</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
19 Demo/AndroidManifest.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.stackmob.android.demo"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
+
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".StackMobDemoActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <uses-permission android:name="android.permission.INTERNET" />
+</manifest>
175 Demo/LICENSE
@@ -0,0 +1,175 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
12 Demo/default.properties
@@ -0,0 +1,12 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
+android.library.reference.1=../SDK
BIN Demo/libs/android-facebook-1.4.jar
Binary file not shown.
BIN Demo/libs/gson-1.7.1.jar
Binary file not shown.
BIN Demo/libs/signpost-commonshttp4-1.2.1.1.jar
Binary file not shown.
BIN Demo/libs/signpost-core-1.2.1.1.jar
Binary file not shown.
116 Demo/pom.xml
@@ -0,0 +1,116 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>stackmob-sdk-demo</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>apk</packaging>
+
+ <name>Stackmob Android SDK Demo</name>
+ <description>Stackmob Android SDK Demo App</description>
+ <inceptionYear>2011</inceptionYear>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>1.7.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.pivotallabs</groupId>
+ <artifactId>robolectric</artifactId>
+ <!--<version>1.0-apache</version>-->
+ <version>1.0-RC1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>oauth.signpost</groupId>
+ <artifactId>signpost-core</artifactId>
+ <version>1.2.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>oauth.signpost</groupId>
+ <artifactId>signpost-commonshttp4</artifactId>
+ <version>1.2.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android</artifactId>
+ <version>2.2.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.egoclean</groupId>
+ <artifactId>android-facebook</artifactId>
+ <version>1.4</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>stackmob-sdk</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <type>apklib</type>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>Egoclean</id>
+ <url>http://mvn.egoclean.com/</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
+ <artifactId>maven-android-plugin</artifactId>
+ <version>2.9.0-beta-5</version>
+ <configuration>
+ <sdk>
+ <platform>8</platform>
+ </sdk>
+ <deleteConflictingFiles>true</deleteConflictingFiles>
+ <undeployBeforeDeploy>true</undeployBeforeDeploy>
+ </configuration>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
40 Demo/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
BIN Demo/res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN Demo/res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN Demo/res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 Demo/res/layout/main.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <Button android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:text="Login call"
+ android:onClick="buttonClick"/>
+</LinearLayout>
5 Demo/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, StackMobDemoActivity!</string>
+ <string name="app_name">StackMobDemo</string>
+</resources>
48 Demo/src/com/stackmob/android/demo/StackMobDemoActivity.java
@@ -0,0 +1,48 @@
+package com.stackmob.android.demo;
+
+import java.util.HashMap;
+
+import com.stackmob.android.sdk.api.StackMob;
+import com.stackmob.android.sdk.callback.StackMobCallback;
+import com.stackmob.android.sdk.exception.StackMobException;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Toast;
+
+public class StackMobDemoActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ StackMob.getInstance().setApplication(
+ "7f1aebc7-0fb8-4265-bfea-2c42c08a3bf0",
+ "81573b21-b948-4339-baa3-dbffe0ca4503", "androidtest",
+ "stackmob", "stackmob.com", "user", 0);
+ }
+
+ public void buttonClick(View v) {
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("username", "admin");
+ params.put("password", "1234");
+
+ StackMob.getInstance().login(params, new StackMobCallback() {
+
+ @Override
+ public void success(String responseBody) {
+ Toast.makeText(StackMobDemoActivity.this,
+ "login response: " + responseBody, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failure(StackMobException e) {
+ Toast.makeText(StackMobDemoActivity.this,
+ "error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+}
175 LICENSE
@@ -0,0 +1,175 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
235 README.md
@@ -0,0 +1,235 @@
+# Stackmob Android SDK
+This is the Official Stackmob Android SDK
+
+# Getting Started
+
+### With Maven
+Maven is the best way to get set up with the SDK. Here's how:
+
+```bash
+git clone git@github.com:stackmob/StackMob_Android.git
+cd StackMob_Android/SDK
+mvn clean install -DskipTests #see below in "A note about testing the SDK" for why we need to skip tests
+```
+
+Then, add this to your pom.xml file:
+
+```xml
+<dependency>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>stackmob-sdk</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <type>apklib</type>
+ <scope>compile</scope>
+</dependency>
+```
+
+### Without Maven
+If you don't use Maven, we have you covered as well:
+
+1. download [this ZIP file](http://stackmob.github.com/StackMob_Android/downloads/0.0.1/StackMobDemo.zip)
+2. unzip StackMobDemo.zip
+3. in Eclipse, File -> Import -> General -> Existing Projects into Workspace
+4. select the StackMobDemo/SDK folder
+
+# Coding
+
+The SDK aims to be simple to setup and use. API docs are [here](http://stackmob.github.com/StackMob_Android/javadoc/0.0.1/apidocs/), and below are some code samples that show its use. All assume that you have a StackMob server set up with a Game object model that looks like this in Java:
+
+```java
+
+import java.util.List;
+
+class Game {
+ public List<String> players;
+ public String game_id;
+ public long createddate;
+ public long lastmoddate;
+ public String name;
+
+ public Game(List<String> players, String game_id, long createddate, long lastmoddate, String name) {
+ this.players = players;
+ this.game_id = game_id;
+ this.createddate = createddate;
+ this.lastmoddate = lastmoddate;
+ this.name = name;
+ }
+}
+```
+
+### Setup
+
+```java
+import com.stackmob.android.sdk.api.StackMob;
+import com.stackmob.android.sdk.api.StackMob;
+import com.stackmob.android.sdk.callback.StackMobCallback;
+import com.stackmob.android.sdk.exception.StackMobException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+StackMob stackmob = StackMob.getInstance();
+final String API_KEY = ...
+final String API_SECRET = ...
+final String APP_SUBDOMAIN = ...
+final String APP_NAME = ...
+final String DOMAIN = "stackmob.com";
+final String USER_OBJECT_NAME = "users"; //change this if you have a user object in your object model of a different name
+final Integer API_VERSION_NUM = 0; //0 for Sandbox, >0 for deployed
+stackmob.setApplication(API_KEY, API_SECRET, APP_NAME, APP_SUBDOMAIN, DOMAIN, USER_OBJECT_NAME, API_VERSION_NUM);
+```
+
+### GET
+
+```java
+//get the game object for tic tac toe
+
+Map<String, Object> arguments = new HashMap<String, Object>();
+arguments.put("game_id", "tic-tac-toe");
+
+StackMob.getInstance().get("Game", arguments, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {
+ System.out.println("got object with response: " + responseBody);
+ }
+ @Override
+ public void failure(StackMobException e) {
+ System.out.println("failed to get object with exception: " + e.toString());
+ }
+});
+```
+
+### POST
+
+```java
+//create a new game object for charades
+
+List<String> players = new ArrayList<String>();
+players.add("John Doe");
+players.add("Jane Doe");
+Game g = new Game(players, "charades", System.currentTimeMillis(), System.currentTimeMillis(), "Charades - kinda boring with only 2 people!");
+StackMob.getInstance().post("game", game, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException) {}
+});
+```
+
+### PUT
+
+```java
+//add a player to the charades game
+
+List<String> players = new ArrayList<String>();
+players.add("John Doe");
+players.add("Jane Doe");
+players.add("Bob Generic")
+
+Game newGame = new Game(players, "charades", System.currentTimeMillis(), System.currentTimeMillis(), "Charades - now less boring with 3 people!");
+StackMob.getInstance().put("game", "charades", newGame, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+### DELETE
+
+```java
+//cancel the charades game
+
+StackMob.getInstance().delete("game", "charades", new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+### Facebook Registration
+Register a new user with a Facebook token:
+
+```java
+StackMob.getInstance().registerWithFacebookToken(fbToken, "John Doe", new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+Link an existing user to their FB account:
+
+```java
+StackMob.getInstance().linkUserWithFacebookToken(fbToken, fbTokenSecret, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+### Twitter Registration
+Register a new user with a Twitter token, secret, and username:
+
+```java
+StackMob.getInstance().registerWithTwitterToken(twitterToken, twitterSecret, twitterUsername, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+Link an existing user to their Twitter account:
+
+```java
+StackMob.getInstance().linkUserWithTwitterToken(twitterToken, twitterSecret, new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+});
+```
+
+### Push Notifications
+StackMob works with Google's C2DM service [http://code.google.com/android/c2dm](http://code.google.com/android/c2dm/). To get a C2DM registration ID, follow the instructions at [http://code.google.com/android/c2dm/#registering](http://code.google.com/android/c2dm/#registering). Then, in your handleRegistration method, include this line to register the new registrationID with your servers on StackMob:
+
+```java
+StackMob.getInstance().registerForPushWithUser(stackmobUsername, intent.getStringExtra("registration_id"), new StackMobCallback() {
+ @Override
+ public void success(String responseBody) {}
+ @Override
+ public void failure(StackMobException e) {}
+})
+```
+
+Note that you only should register a push notification token if you have a valid StackMob username. In the end, your C2DM registration code should look similar to the code in [this tutorial](http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html).
+
+# Contributing
+We encourage contributions to the StackMob SDK. To do so, fork this repository, make your changes and submit a pull request.
+
+## A note about testing the SDK
+The SDK test suite depends on a forked version of the Robolectric Android mocking library. If you want to run the test suite, you have to set up this Robolectric fork. Here's how:
+
+1. in the Android SDK and AVD manager, go to "Available Packages" and select all under "Android Repository" and all under "Third Party Add-ons" -> "Google, Inc."
+2. then, run this script:
+
+```bash
+git clone https://github.com/mosabua/maven-android-sdk-deployer.git #installs Android JARs into the local maven repository
+cd maven-android-sdk-deployer && mvn clean install && cd ..
+git clone https://github.com/Macarse/robolectric.git
+cd robolectric && git checkout apacheVersion && mvn clean install -DskipTests && cd ..
+```
+
+Note that if you do not want to run tests on the SDK, make sure that you execute ```mvn clean install -DskipTests``` for your Maven builds.
+
+Also note that if you want to run tests, you must open StackMobTestCommon.java and replace the placeholder values with your app's values.
+
+## Forked Robolectric? What's up with that?
+The stock [Robolectric library](http://pivotal.github.com/robolectric/) completely mocks all HTTP requests, so with that library, the SDK cannot be tested against real StackMob servers while running inside the JVM. We want to do both, so we rely on [https://github.com/Macarse/robolectric](this version of Robolectric) which mocks everything except HTTP requests.
+
+We know this whole setup is far from ideal, and we're working on building a better way to test our SDK without mocking our HTTP requests. While we're working on a better solution, you should run normal (non-test) maven builds with ```-DskipTest``` so that you don't need to install custom Robolectric.
45 SDK/.project
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>TwitterActivity</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
35 SDK/AndroidManifest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright 2011 StackMob Licensed under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with the
+ License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software distributed
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the License. -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.stackmob.android.sdk" android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="4" />
+
+ <application android:icon="@drawable/icon" android:label="stackmob-sdk">
+
+ <activity android:name=".activity.TwitterActivity"
+ android:launchMode="singleTask"
+ android:configChanges="keyboardHidden|orientation">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="x-oauthflow-twitter" android:host="callback" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".activity.FacebookActivity"
+ android:configChanges="keyboardHidden|orientation"/>
+
+ </application>
+
+ <uses-permission android:name="android.permission.INTERNET" />
+</manifest>
175 SDK/LICENSE
@@ -0,0 +1,175 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
12 SDK/default.properties
@@ -0,0 +1,12 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-4
+android.library=true
106 SDK/pom.xml
@@ -0,0 +1,106 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.stackmob.android</groupId>
+ <artifactId>stackmob-sdk</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>apklib</packaging>
+
+ <name>Stackmob Android SDK</name>
+ <description>Stackmob Android SDK</description>
+ <inceptionYear>2011</inceptionYear>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>1.7.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>oauth.signpost</groupId>
+ <artifactId>signpost-core</artifactId>
+ <version>1.2.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>oauth.signpost</groupId>
+ <artifactId>signpost-commonshttp4</artifactId>
+ <version>1.2.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.pivotallabs</groupId>
+ <artifactId>robolectric</artifactId>
+ <version>1.0-apache</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android</artifactId>
+ <version>2.2.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.egoclean</groupId>
+ <artifactId>android-facebook</artifactId>
+ <version>1.4</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>Egoclean</id>
+ <url>http://mvn.egoclean.com/</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>tests</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
+ <artifactId>maven-android-plugin</artifactId>
+ <version>2.9.0-beta-5</version>
+ <configuration>
+ <sdk>
+ <platform>8</platform>
+ </sdk>
+ <deleteConflictingFiles>true</deleteConflictingFiles>
+ <undeployBeforeDeploy>true</undeployBeforeDeploy>
+ </configuration>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
40 SDK/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
BIN SDK/res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SDK/res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SDK/res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 SDK/src/com/stackmob/android/sdk/activity/FacebookActivity.java
@@ -0,0 +1,66 @@
+package com.stackmob.android.sdk.activity;
+
+import oauth.signpost.OAuth;
+
+import com.facebook.android.DialogError;
+import com.facebook.android.Facebook;
+import com.facebook.android.Facebook.DialogListener;
+import com.facebook.android.FacebookError;
+import com.stackmob.android.sdk.api.StackMob;
+import com.stackmob.android.sdk.api.StackMobSession;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+public class FacebookActivity extends Activity {
+
+ private static final String TAG = FacebookActivity.class.getCanonicalName();
+
+ public static final int RESULT_ERROR = 0;
+ public static final int RESULT_OK = 1;
+
+ private Facebook facebook;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ StackMobSession session = StackMob.getInstance().getSession();
+
+ facebook = new Facebook(session.getFacebookAppId());
+ facebook.authorize(this, new DialogListener() {
+
+ public void onComplete(Bundle values) {
+
+ StackMob.getInstance().setFacebookToken(facebook.getAccessToken(),
+ facebook.getAccessExpires(), null);
+ finish();
+ }
+
+ public void onFacebookError(FacebookError error) {
+ StackMob.getInstance().setFacebookToken(null, 0, error);
+ finish();
+ }
+
+ public void onError(DialogError e) {
+ StackMob.getInstance().setFacebookToken(null, 0, e);
+ finish();
+ }
+
+ public void onCancel() {
+ StackMob.getInstance().setFacebookToken(null, 0, new Exception("Cancelled"));
+ finish();
+ }
+
+ });
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode,
+ Intent data) {
+
+ super.onActivityResult(requestCode, resultCode, data);
+ facebook.authorizeCallback(requestCode, resultCode, data);
+ }
+}
142 SDK/src/com/stackmob/android/sdk/activity/TwitterActivity.java
@@ -0,0 +1,142 @@
+/**
+ * Copyright 2011 StackMob
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.stackmob.android.sdk.activity;
+
+import com.stackmob.android.sdk.api.StackMob;
+import com.stackmob.android.sdk.api.StackMobSession;
+import com.stackmob.android.sdk.callback.StackMobCallback;
+import com.stackmob.android.sdk.exception.StackMobException;
+
+import oauth.signpost.OAuth;
+import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
+import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+
+public class TwitterActivity extends Activity {
+ private static final String TAG = TwitterActivity.class
+ .getCanonicalName();
+
+ private static final String REQUEST_URL = "https://api.twitter.com/oauth/request_token";
+ private static final String ACCESS_URL = "https://api.twitter.com/oauth/access_token";
+ private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";
+
+ private static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-twitter";
+ private static final String OAUTH_CALLBACK_HOST = "callback";
+ private static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME
+ + "://" + OAUTH_CALLBACK_HOST;
+
+ public static final int RESULT_ERROR = 0;
+ public static final int RESULT_OK = 1;
+
+ private CommonsHttpOAuthConsumer consumer;
+ private CommonsHttpOAuthProvider provider;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ StackMobSession session = StackMob.getInstance().getSession();
+ try {
+ consumer = new CommonsHttpOAuthConsumer(
+ session.getTwitterConsumerKey(),
+ session.getTwitterConsumerSecret());
+ provider = new CommonsHttpOAuthProvider(REQUEST_URL, ACCESS_URL,
+ AUTHORIZE_URL);
+
+ } catch (Exception e) {
+ Log.e(TAG, "Error creating consumer / provider", e);
+ StackMob.getInstance().setTwitterTokens(null, null, e);
+ finish();
+ return;
+ }
+
+ Log.i(TAG, "Starting task to retrieve request token.");
+ new OAuthRequestTokenTask().execute();
+ }
+
+ private class OAuthRequestTokenTask extends
+ AsyncTask<Void, Void, Void> {
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Log.i(TAG, "Retrieving request token from Google servers");
+ final String url = provider.retrieveRequestToken(consumer,
+ OAUTH_CALLBACK_URL);
+ Log.i(TAG, "Popping a browser with the authorize URL : " + url);
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url))
+ .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
+ | Intent.FLAG_ACTIVITY_NO_HISTORY
+ | Intent.FLAG_FROM_BACKGROUND);
+ startActivity(intent);
+ } catch (Exception e) {
+ StackMob.getInstance().setTwitterTokens(null, null, e);
+ finish();
+ }
+
+ return null;
+ }
+ }
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ final Uri uri = intent.getData();
+ Log.d(TAG, "Calling onNewIntent with scheme: " + uri.getScheme());
+
+ if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
+ Log.i(TAG, "Callback received : " + uri);
+ Log.i(TAG, "Retrieving Access Token");
+ new RetrieveAccessTokenTask().execute(uri);
+ }
+ }
+
+ private class RetrieveAccessTokenTask extends
+ AsyncTask<Uri, Void, Void> {
+
+ @Override
+ protected Void doInBackground(Uri... params) {
+ final Uri uri = params[0];
+ final String oauth_verifier = uri
+ .getQueryParameter(OAuth.OAUTH_VERIFIER);
+
+ try {
+ provider.retrieveAccessToken(consumer, oauth_verifier);
+
+ } catch (Exception e) {
+ Log.e(TAG, "OAuth - Access Token Retrieval Error", e);
+ StackMob.getInstance().setTwitterTokens(null, null, e);
+ finish();
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ super.onPostExecute(result);
+ StackMob.getInstance().setTwitterTokens(consumer.getToken(), consumer.getTokenSecret(), null);
+ finish();
+ }
+ }
+}
356 SDK/src/com/stackmob/android/sdk/api/StackMob.java
@@ -0,0 +1,356 @@
+/**
+ * Copyright 2011 StackMob
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.stackmob.android.sdk.api;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import android.content.Context;
+import android.content.Intent;
+
+import com.stackmob.android.sdk.activity.FacebookActivity;
+import com.stackmob.android.sdk.activity.TwitterActivity;
+import com.stackmob.android.sdk.callback.StackMobCallback;
+import com.stackmob.android.sdk.callback.StackMobFacebookCallback;
+import com.stackmob.android.sdk.callback.StackMobTwitterCallback;
+import com.stackmob.android.sdk.exception.StackMobException;
+import com.stackmob.android.sdk.net.HttpHelper;
+import com.stackmob.android.sdk.net.HttpVerb;
+import com.stackmob.android.sdk.util.EnvironmentInfoUtil;
+
+public class StackMob {
+
+ private static StackMob instance = new StackMob();
+ private StackMobSession session;
+ private StackMobTwitterCallback mTwitterCallback;
+ private StackMobFacebookCallback mFacebookCallback;
+
+ protected static class RegistrationIDAndUser {
+ public String userId;
+ public Map<String, String> token = new HashMap<String, String>();
+ public RegistrationIDAndUser(String registrationID, String user) {
+ this.userId = user;
+ token.put("token", registrationID);
+ token.put("type", "android");
+ }
+ }
+
+ public static StackMob getInstance() {
+ return instance;
+ }
+
+ private StackMob() {
+ }
+
+ public void setApplication(String apiKey, String apiSecret,
+ String appName, String subDomain, String domain,
+ String userObjectName, Integer apiVersionNumber) {
+
+ setSession(new StackMobSession(apiKey, apiSecret, appName,
+ subDomain, domain, userObjectName, apiVersionNumber));
+ }
+
+ public void getTwitterUserToken(Context ctx, StackMobTwitterCallback callback) {
+ mTwitterCallback = callback;
+ ctx.startActivity(new Intent(ctx, TwitterActivity.class));
+ }
+
+ public void setTwitterTokens(String token, String tokenSecret, Throwable e) {
+ if ( null == e ) {
+ mTwitterCallback.success(token, tokenSecret);
+ } else {
+ mTwitterCallback.failure(new StackMobException(e.getMessage()));
+ }
+ }
+
+ public void setTwitterConsumer(String consumerKey, String consumerSecret) {
+ session.setTwitterConsumerKey(consumerKey);
+ session.setTwitterConsumerSecret(consumerSecret);
+ }
+
+ public void getFacebookUserToken(Context ctx, StackMobFacebookCallback callback) {
+ mFacebookCallback = callback;
+ ctx.startActivity(new Intent(ctx, FacebookActivity.class));
+ }
+
+ public void setFacebookToken(String token, long accessExpires, Throwable e) {
+ if (null == e) {
+ mFacebookCallback.success(token, accessExpires);
+ } else {
+ mFacebookCallback.failure(new StackMobException(e.getMessage()));
+ }
+ }
+
+ public void setFacebookAppId(String appId) {
+ session.setFacebookAppId(appId);
+ }
+
+ public void login(HashMap<String, Object> params,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "login";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void logout(StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "logout";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ request.sendRequest();
+ }
+
+ public void startSession(Context ctx, StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "startsession";
+ request.httpMethod = HttpVerb.POST;
+ request.isSecure = true;
+ request.callback = callback;
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("cd", EnvironmentInfoUtil.getApplicationInfo(ctx));
+ request.requestObject = params;
+
+ request.sendRequest();
+ }
+
+ public void endSession(StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "endsession";
+ request.httpMethod = HttpVerb.POST;
+ request.isSecure = true;
+ request.callback = callback;
+
+ request.sendRequest();
+ }
+
+ public void twitterLogin(String token, String secret,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "twitterLogin";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("tw_tk", token);
+ params.put("tw_ts", secret);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void twitterStatusUpdate(String message,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "twitterStatusUpdate";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("tw_st", message);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void registerWithTwitterToken(String token, String secret,
+ String username, StackMobCallback callback) {
+
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "createUserWithTwitter";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("tw_tk", token);
+ params.put("tw_ts", secret);
+ params.put("username", username);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void linkUserWithTwitterToken(String token, String secret,
+ StackMobCallback callback) {
+
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "linkUserWithTwitter";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("tw_tk", token);
+ params.put("tw_ts", secret);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void facebookLogin(String token, StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "facebookLogin";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("fb_at", token);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void registerWithFacebookToken(String token, String username, StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "createUserWithFacebook";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("fb_at", token);
+ params.put("username", username);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void linkUserWithFacebookToken(String token, String secret,
+ StackMobCallback callback) {
+
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "linkUserWithFacebook";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("fb_at", token);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void facebookPostMessage(String msg, StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = "postFacebookMessage";
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = true;
+ request.isSecure = true;
+ request.callback = callback;
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put("message", msg);
+ request.params = params;
+
+ request.sendRequest();
+ }
+
+ public void getFacebookUserInfo(StackMobCallback callback) {
+ get("getFacebookUserInfo", callback);
+ }
+
+ public void registerForPushWithUser(String username, String registrationID, StackMobCallback callback) {
+ RegistrationIDAndUser tokenAndUser = new RegistrationIDAndUser(registrationID, username);
+ post("/push/register_device_token_universal", tokenAndUser, callback);
+ }
+
+ public void get(String path, StackMobCallback callback) {
+ get(path, null, callback);
+ }
+
+ public void get(String path, HashMap<String, Object> arguments,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = path;
+ request.httpMethod = HttpVerb.GET;
+ request.isUserBased = false;
+ request.isSecure = true;
+ request.callback = callback;
+ request.params = arguments;
+
+ request.sendRequest();
+ }
+
+ public void post(String path, Object requestObject,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = path;
+ request.httpMethod = HttpVerb.POST;
+ request.isUserBased = false;
+ request.isSecure = true;
+ request.callback = callback;
+ request.requestObject = requestObject;
+
+ request.sendRequest();
+
+ }
+
+ public void put(String path, String id, Object requestObject,
+ StackMobCallback callback) {
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = path + "/" + id;
+ request.httpMethod = HttpVerb.PUT;
+ request.isUserBased = false;
+ request.isSecure = true;
+ request.callback = callback;
+ request.requestObject = requestObject;
+
+ request.sendRequest();
+
+ }
+
+ public void delete(String path, String id, StackMobCallback callback) {
+
+ StackMobRequest request = new StackMobRequest(this.session);
+ request.methodName = path + "/" + id;
+ request.httpMethod = HttpVerb.DELETE;
+ request.isUserBased = false;
+ request.isSecure = true;
+ request.callback = callback;
+
+ request.sendRequest();
+ }
+
+ public void setSession(StackMobSession session) {
+ this.session = session;
+ HttpHelper.setVersion(this.session.getApiVersionNumber());
+ }
+
+ public StackMobSession getSession() {
+ return session;
+ }
+}
243 SDK/src/com/stackmob/android/sdk/api/StackMobRequest.java
@@ -0,0 +1,243 @@
+/**
+ * Copyright 2011 StackMob
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.stackmob.android.sdk.api;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+
+import com.google.gson.Gson;
+import com.stackmob.android.sdk.callback.StackMobCallback;
+import com.stackmob.android.sdk.exception.StackMobException;
+import com.stackmob.android.sdk.net.HttpHelper;
+import com.stackmob.android.sdk.net.HttpVerb;
+
+public class StackMobRequest {
+ private static final String URL_FMT = "api.mob1.stackmob.com";
+ private static final String SECURE_SCHEME = "https";
+ private static final String REGULAR_SCHEME = "http";
+
+ private StackMobSession session;
+ public String methodName;
+ public boolean isUserBased = false;
+ public Boolean isSecure = true;
+ public HttpVerb httpMethod = HttpVerb.GET;
+ public String method;
+ //default to doing nothing
+ public StackMobCallback callback = new StackMobCallback() {
+ @Override
+ public void success(String s) {}
+ @Override
+ public void failure(StackMobException e) {}
+ };
+ public HashMap<String, Object> params;
+ public Object requestObject;
+
+ public StackMobRequest(StackMobSession session) {
+ this.session = session;
+ }
+
+ public void sendRequest() {
+
+ try {
+ String response = null;
+
+ switch(this.httpMethod) {
+
+ case GET:
+ response = sendGetRequest();
+ break;
+
+ case POST:
+ response = sendPostRequest();
+ break;
+
+ case PUT:
+ response = sendPutRequest();
+ break;
+
+ case DELETE:
+ response = sendDeleteRequest();
+ break;
+
+ }
+
+ callback.success(response);
+
+ } catch (StackMobException e) {
+ callback.failure(e);
+ }
+
+ }
+
+ private String sendGetRequest() throws StackMobException {
+
+ URI uri = null;
+ String ret = null;
+
+ try {
+ String query = null;
+ if (null != this.params) {
+ query = URLEncodedUtils.format(getParamsForRequest(),
+ HTTP.UTF_8);
+ }
+
+ uri = URIUtils.createURI(getScheme(), getHost(), -1, getPath(),
+ query, null);
+ ret = HttpHelper.doGet(uri);
+
+ } catch (URISyntaxException e) {
+ throw new StackMobException(e.getMessage());
+ }
+
+ return ret;
+
+ }
+
+ private String sendPostRequest() throws StackMobException {
+ URI uri = null;
+ String ret = null;
+
+ try {
+
+ uri = URIUtils.createURI(getScheme(), getHost(), -1, getPath(),
+ null, null);
+
+ HttpEntity entity = null;
+ if (null != this.params) {
+ entity = new UrlEncodedFormEntity(getParamsForRequest(),
+ HTTP.UTF_8);
+ } else if (null != this.requestObject) {
+ Gson gson = new Gson();
+ entity = new StringEntity(gson.toJson(this.requestObject),
+ HTTP.UTF_8);
+ }
+
+ ret = HttpHelper.doPost(uri, entity);
+
+ } catch (URISyntaxException e) {
+ throw new StackMobException(e.getMessage());
+ } catch (UnsupportedEncodingException e) {
+ throw new StackMobException(e.getMessage());
+ }
+
+ return ret;
+ }
+
+ private String sendPutRequest() throws StackMobException {
+ URI uri = null;
+ String ret = null;
+
+ try {
+
+ uri = URIUtils.createURI(getScheme(), getHost(), -1, getPath(),
+ null, null);
+
+ HttpEntity entity = null;
+ if (null != this.params) {
+ entity = new UrlEncodedFormEntity(getParamsForRequest(),
+ HTTP.UTF_8);
+ } else if (null != this.requestObject) {
+ Gson gson = new Gson();
+ entity = new StringEntity(gson.toJson(this.requestObject),
+ HTTP.UTF_8);
+ }
+
+ ret = HttpHelper.doPut(uri, entity);
+
+ } catch (URISyntaxException e) {
+ throw new StackMobException(e.getMessage());
+ } catch (UnsupportedEncodingException e) {
+ throw new StackMobException(e.getMessage());
+ }
+
+ return ret;
+ }
+
+ private String sendDeleteRequest() throws StackMobException {
+ URI uri = null;
+ String ret = null;
+
+ try {
+ String query = null;
+ if (null != this.params) {
+ query = URLEncodedUtils.format(getParamsForRequest(),
+ HTTP.UTF_8);
+ }
+
+ uri = URIUtils.createURI(getScheme(), getHost(), -1, getPath(),
+ query, null);
+ ret = HttpHelper.doDelete(uri);
+
+ } catch (URISyntaxException e) {
+ throw new StackMobException(e.getMessage());
+ }
+
+ return ret;
+ }
+
+ private String getPath() {
+ if (this.isUserBased) {
+ return "/" + this.session.getUserObjectName() + "/"
+ + this.methodName;
+ } else {
+ return "/" + this.methodName;
+ }
+
+ }
+
+ private String getScheme() {
+ if (this.isSecure) {
+ return SECURE_SCHEME;
+ } else {
+ return REGULAR_SCHEME;
+ }
+ }
+
+ private String getHost() {
+ return URL_FMT;
+ }
+
+ private List<NameValuePair> getParamsForRequest() {
+
+ if (null == this.params) {
+ return null;
+ }
+
+ List<NameValuePair> ret = new ArrayList<NameValuePair>(
+ this.params.size());
+ for (String key : this.params.keySet()) {
+ ret.add(new BasicNameValuePair(key, this.params.get(key)
+ .toString()));
+ }
+
+ return ret;
+ }
+
+}
128 SDK/src/com/stackmob/android/sdk/api/StackMobSession.java
@@ -0,0 +1,128 @@
+/**
+ * Copyright 2011 StackMob
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.stackmob.android.sdk.api;
+
+public class StackMobSession {
+
+ private String key;
+ private String secret;
+ private String appName;
+ private String subDomain;
+ private String domain;
+ private String userObjectName;
+ private int apiVersionNumber;
+
+ private String twitterConsumerKey;
+ private String twitterConsumerSecret;
+
+ private String facebookAppId;
+
+ public StackMobSession(String key, String secret, String appName,
+ String subDomain, String domain, String userObjectName,
+ int apiVersionNumber) {
+
+ this.key = key;
+ this.secret = secret;
+ this.appName = appName;
+ this.subDomain = subDomain;
+ this.domain = domain;
+ this.userObjectName = userObjectName;
+ this.apiVersionNumber = apiVersionNumber;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
+
+ public String getAppName() {
+ return appName;
+ }
+
+ public void setAppName(String appName) {
+ this.appName = appName;
+ }
+
+ public String getSubDomain() {
+ return subDomain;
+ }
+
+ public void setSubDomain(String subDomain) {
+ this.subDomain = subDomain;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public String getUserObjectName() {
+ return userObjectName;
+ }
+
+ public void setUserObjectName(String userObjectName) {
+ this.userObjectName = userObjectName;
+ }
+
+ public int getApiVersionNumber() {
+ return apiVersionNumber;
+ }
+
+ public void setApiVersionNumber(int apiVersionNumber) {
+ this.apiVersionNumber = apiVersionNumber;
+ }
+
+ public String getTwitterConsumerKey() {
+ return twitterConsumerKey;
+ }
+
+ public void setTwitterConsumerKey(String twitterConsumerKey) {
+ this.twitterConsumerKey = twitterConsumerKey;
+ }
+
+ public String getTwitterConsumerSecret() {
+ return twitterConsumerSecret;
+ }
+
+ public void setTwitterConsumerSecret(String twitterConsumerSecret) {
+ this.twitterConsumerSecret = twitterConsumerSecret;
+ }
+
+ public void setFacebookAppId(String facebookAppId) {
+ this.facebookAppId = facebookAppId;
+ }