Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ntoll/restprovider

REST Provider for Android
https://github.com/ntoll/restprovider

Last synced: about 1 month ago
JSON representation

REST Provider for Android

Awesome Lists containing this project

README

        

h1. Android RESTProvider: A web services cursor interface

RESTProvider handles all the HTTP querying and caching. Users can seamlessly interface with any Web Service API which provides JSON or XML as a response. To query a RESTProvider in an activity a user need only specify an endpoint and then query an APIs RESTful functions.

* Supports JSON & XML Web services
* Handles HTTP querying & caching

RESTProvider is an implementation of functionality commonly used when dealing with web services in Android.

h2. Example: Twitter stream as ListActivity



public class TwitterFeedExample extends ListActivity {
@Override public void onCreate(Bundle b) {
super.onCreate(b);
CPAsyncHandler g = new CPAsyncHandler(getContentResolver());
g.startQuery(1, null, Uri.parse("content://novoda.rest.test.twitter"),
null, "q=?", new String[] { "droidcon" }, null);
}

private class CPAsyncHandler extends AsyncQueryHandler {
@Override
protected void onQueryComplete(int token, Object cookie, Cursor c) {
super.onQueryComplete(token, cookie, c);
setListAdapter(new SimpleCursorAdapter(TwitterFeedExample.this,
android.R.layout.simple_list_item_2, c, new String[] {
"from_user", "text" }, new int[] {
android.R.id.text1, android.R.id.text2 }));
}

public CPAsyncHandler(ContentResolver cr) {
super(cr);
}
}
}



h2. Setup

* GIT: _git clone git://github.com/novoda/RESTProvider.git_
* Archive: "http://github.com/novoda/RESTProvider/archives/master":http://github.com/novoda/RESTProvider/archives/master
* JAR: "http://github.com/novoda/RESTProvider/downloads":http://github.com/novoda/RESTProvider/downloads
* Home: "http://github.com/novoda/RESTProvider":http://github.com/novoda/RESTProvider

The RESTProvider's most recent version is only available in source but regular versions are available as jar files.
We recommend working from source as significant changes are still frequent at these early stages.
Download the latest source as an archive or checkout via git. The advantage of checking out via git is that updates can be quickly applied within your working environment using $git pull origin master. To checkout the latest source via git, within the directory you wish to download the project: _git clone git://github.com/novoda/RESTProvider.git_

In Eclipse:
_File > New Android Project_
Select _Create project from existing source_
For the location select: RESTProvider/RESTProvider
Dependant files needed on build path, add the following to RESTProvider/RESTProvider/lib

* "Signpost-core-1.1.jar":http://oss.sonatype.org/content/repositories/signpost-releases/oauth/signpost/signpost-core/1.1/signpost-core-1.1.jar
* "Signpost-commonsHTTP-1.1.jar":http://oss.sonatype.org/content/repositories/signpost-releases/oauth/signpost/signpost-commonshttp4/1.1/signpost-commonshttp4-1.1.jar
* "Droidfu v1":http://cloud.github.com/downloads/kaeppler/droid-fu/droid-fu-1.0-SNAPSHOT.jar
* "DOM4J":http://sourceforge.net/projects/dom4j/files/dom4j/1.6.1/dom4j-1.6.1.jar/download
* "Jackson-core-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.4.1/jackson-core-asl-1.4.1.jar
* "Jackson-mapper-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-mapper-asl/1.4.1/
* "Google Collections 1.0":http://code.google.com/p/google-collections/

Refresh the directories in eclipse (F5 with the project selected)
All jars under 'libs' need to be added to the build path.
You can add each dependancy by right clicking the jar files under this directory and selecting _Build Path > Add to Build Path_.
You can now depend on this project as a build dependancy to use the RESTProvider in your project.

h2. Demos

Follow these steps in Eclipse:
_File > New Android Project_
Select _Create project from existing source_
For the location select: RESTProvider/RESTProviderTest
All of the libraries under the RESTprovider 'libs' directory need to be added to the build path.
You can add each library by right clicking the jar files under this directory and selecting _Build Path > Add to Build Path_.

Dependant files needed on build path as Android cannot src the dependencies from the other project, add the followingto RESTProvider/RESTProviderTest/lib

* "Signpost-core-1.1.jar":http://oss.sonatype.org/content/repositories/signpost-releases/oauth/signpost/signpost-core/1.1/signpost-core-1.1.jar
* "Signpost-commonsHTTP-1.1.jar":http://oss.sonatype.org/content/repositories/signpost-releases/oauth/signpost/signpost-commonshttp4/1.1/signpost-commonshttp4-1.1.jar
* "Droidfu v1":http://cloud.github.com/downloads/kaeppler/droid-fu/droid-fu-1.0-SNAPSHOT.jar
* "DOM4J":http://sourceforge.net/projects/dom4j/files/dom4j/1.6.1/dom4j-1.6.1.jar/download
* "Jackson-core-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.4.1/jackson-core-asl-1.4.1.jar
* "Jackson-mapper-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-mapper-asl/1.4.1/

You then need to add the RESTProvider's src as a dependency of this project by right clicking _Build Path > Link Src_ then selecting the directory of the RESTProvider's src on your disk.
Note: Intrumentations cannot be run if the RESTProvider is included as src in the Demo project

h3. Unit Tests are currently broken!

This is an experimental way of testing an android locally without deploying to the against an android emulated image using a n android.jar customly extended for testing. In order to provide a test framework, we use PowerMock as describe in the following page which I strongly recommend to follow and understand:
https://sites.google.com/site/androiddevtesting/

In Eclipse:
_File > New Java Project_
Select _Create new project from existing source_
For the location select: RESTProvider/RESTProviderLocalTest
Right click on Project dir
_Build path > Configure Build Path_
Add the RestProvider project as a dependency.
Dependant files needed on build path in the lib dir:

* "Jackson-core-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.4.1/jackson-core-asl-1.4.1.jar
* "Jackson-mapper-asl-1.4.1.jar":http://repository.codehaus.org/org/codehaus/jackson/jackson-mapper-asl/1.4.1/

h3. Exporting jar for use in project

In order for your dependant project to deploy correctly you will need to export the RESTProvider into your dependant project
as a jar. To do this:

h2. Help improve the RESTProvider!

The RESTProvider project is for everyone to take advantage and will improve only with your feedback.
If you are using the RESTProvider or have issues then please let the community know.
This project is unsupported but contributors will try their best to reply to problems on mailing list.
"http://groups.google.com/group/android-restprovider":http://groups.google.com/group/android-restprovider
Or you can raise issues on github.