Tested with Ruby 2 and Rails 3.2.x
Add this line to your application's Gemfile:
gem 'reaper', :git => 'https://github.com/dwa012/reaper.git'
And then execute:
$ bundle install
Reaper is a set of tasks that help connect your Rails server to iOS and Android devices. These task read the models in your rails applicaiton and create all the code need to connect to the server. Follow the simple guide for the platform you wish to target.
The tasks are scoped to the reaper namespace.
rake reaper:TARGET_PLATFORM [MODEL[,MODEL]]
Each target can take a list of models if you wish to target a subset of the server models.
When you create the Rails API controller, a routes file is generated. You can either copy the routes into your regular routes file or add the following to your application.rb
.
config.paths['config/routes'] << Rails.root.join('config/routes/api.rb')
This will make sure that if you regenerate the API controllr, you can get the updated routes file without any additional work.
The contoller will be placed in {APP_ROOT}/app/controllers/api/v1/
.
Run rake reaper:go
in the root of the Rails applicaiton.
Navigate to the {APP_ROOT}/generated_files/golang
directory.
- Open
{APP_ROOT}/generated_files/golang/src/reaper/db/db.go
and update the database information to correspond to the database you are using and the relavant connection information. - Open
{APP_ROOT}/generated_files/golang/src/reaper/server/server.go
and change the listening port if required.
To run the server:
- Navigate to
{APP_ROOT}/generated_files/golang
- Run
go get reaper/server
- Run
go install reaper/server
- Run
{APP_ROOT}/generated_files/golang/bin/server
You can then go to the server address in the browser http://**host**/api/v1/**Model**
.
Run rake reaper:android
in the root of the Rails applicaiton.
- Copy
{APP_ROOT}/generated_files/mobile_app/android/com
into the source fodler of your Android project. - Open
com/github/dwa012/reaper/api/Api.java
and change theBASE_API_URL
constnt to point to the server.
There is an example Android project provided that uses the Rails API server. To get the Albums from the example Rails server do something like the following:
AlbumAsync async = new AlbumAsync(this);
async.fetchItems(new AsyncListener<Album>() {
@Override
public void retrievalFinished(List<Album> items) {
// add items to the adapter list
// refresh the adapter
}
});
You will need to add some dependencies to your app to support the Reaper code.
Gradle
compile 'com.google.guava:guava:14.0.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.1.3'
Maven
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.3</version>
</dependency>
Run rake reaper:ios
in the root of the Rails applicaiton.
- Copy
{APP_ROOT}/generated_files/mobile_app/ios/*
into the source directory of your iOS project. - Open
api/APIController.m
and change theAPI_URL
macro to point to the server.
You will need to add some dependencies to your app to support the Reaper code.
Add
pod 'RestKit'
To your Podfile
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request