<commit_before>## rest2mobile Command-line Tool (r2m)
<img style="margin:10px" src="http://developer.magnet.com/tmp/img/logo_r2m_main.png"
 alt="rest2mobile logo" title="rest2mobile" align="right" />
<code>r2m</code> is a command-line tool that generates Android, iOS, and JavaScript code for your mobile app to interact with REST APIs. It takes REST request and JSON response information from a variety of sources you provide, and generates
platform-specific code for making the request and retrieving the response.

**Note:** If you are developing with Android Studio or IntelliJ, you can use the [rest2mobile plugin for Android][r2m-plugin-android] instead of the CLI. For iOS apps, you can use the [rest2mobile plugin for Xcode][r2m-plugin-ios].

### Get Started

### Prerequisites
<code>r2m</code> requires Java 6 or later and supports the following platforms:

* Windows® 7 or later
* Mac® OS X® 10.08 or later
* Linux® Ubuntu® 12

### Build and run
```
mvn clean install -am -pl cli-r2m-installer
./cli-r2m-installer/target/magnet-tools-cli-r2m-installer-<version>/r2m
r2m> gen --interactive
```

### Run it using installers

Find universal installers [here](https://github.com/magnetsystems/r2m-cli/releases) 

#### On Mac

Run:
```
brew install https://raw.githubusercontent.com/magnetsystems/r2m-cli/master/brew/r2m.rb
```

If you don't have _brew_, go to: http://brew.sh/


#### On all platforms

Unzip the rest2mobile zip file and add r2m to the path.

## How to use it

### Start in interactive mode:

```
r2m
Starting rest2mobile 1.0.0
Run 'gen --interactive' to generate Mobile APIs in interactive mode.
Type '?' for help. Use <TAB> for completion. <Ctrl-D> to abort commands.
r2m> gen 
```

### Get help
```
r2m> help -v gen
```
or check the [CLI usage](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-generate-code-gen).

### Build from existing examples

Here's a simple example generating the Google distance Mobile API for iOS, Android and Javascript

``` 
r2m> gen -d GoogleDistance 
```

You can get a list of examples with:

```
r2m> gen -l
```
All examples are available on [rest2mobile examples repo](https://github.com/magnetsystems/r2m-examples)
 
### Build with your own examples

You can also build your own Mobile API from existing REST examples or documentation. 
Find out how to create your own example [here](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-create-spec-file).

Examples are usually text files containing the copy-pasted URL request and response payloads from a REST documentation, curl invocation, or simply your browser.
Let's say you want to create a controller using the Google Time Zone API, simple type this in on your browser:


https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&sensor=true


Then you get this JSON response:
```json
{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}
```

Now copy-paste request and response in the file <code>example.txt</code>:
```
+Name getTimeZone
+Request
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&sensor=true

+Response
+Body
{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}

```
With this example file, you can now generate an async Mobile API with a strongly object model for Android, Javascript and iOS

### Generating Mobile API

Using the file created above, run <code>r2m</code> to generate the mobile code.

```
r2m> gen -e example.txt 
```

This generates the Mobile API for all platforms under the <code>mobile/</code> directory.

## Invoking the Mobile API


#### For Android

First, install the [rest2mobile Android SDK](https://github.com/magnetsystems/r2m-sdk-android) by modifying your app's build.gradle, as described [here](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-setup-studio#update-the-build-file)

Then call the method in <code>mobile/android/com/magnet/controller/api/RestController.java</code>:
```java
  Call<TimeZoneResult> getTimeZone(
     String location,
     String timestamp,
     String sensor,
     StateChangedListener listener
  );  
```

For example, with:
```java
  MagnetMobileClient client = MagnetMobileClient.getInstance(this.getApplicationContext());
  RestControllerFactory factory = new RestControllerFactory(client);
  RestController controller = factory.obtainInstance();
  Call resp = controller.getTimeZone("39.6034810,-119.6822510", "1331161200", "true");
  TimeZoneResult result = resp.get();
  
  // assert result.getStatus() == "OK";
  // assert result.getTimeZoneId == "America/Los_Angeles";
  // assert result.getTimeZoneName == "Pacific Standard Time";
  // assert result.getDstOffSet() == 0;
  // assert result.getRawOffset() == -28800;
```

#### For iOS:<commit_msg>Fixed typo in sample code<commit_after>## rest2mobile Command-line Tool (r2m)
<img style="margin:10px" src="http://developer.magnet.com/tmp/img/logo_r2m_main.png"
 alt="rest2mobile logo" title="rest2mobile" align="right" />
<code>r2m</code> is a command-line tool that generates Android, iOS, and JavaScript code for your mobile app to interact with REST APIs. It takes REST request and JSON response information from a variety of sources you provide, and generates
platform-specific code for making the request and retrieving the response.

**Note:** If you are developing with Android Studio or IntelliJ, you can use the [rest2mobile plugin for Android][r2m-plugin-android] instead of the CLI. For iOS apps, you can use the [rest2mobile plugin for Xcode][r2m-plugin-ios].

### Get Started

### Prerequisites
<code>r2m</code> requires Java 6 or later and supports the following platforms:

* Windows® 7 or later
* Mac® OS X® 10.08 or later
* Linux® Ubuntu® 12

### Build and run
```
mvn clean install -am -pl cli-r2m-installer
./cli-r2m-installer/target/magnet-tools-cli-r2m-installer-<version>/r2m
r2m> gen --interactive
```

### Run it using installers

Find universal installers [here](https://github.com/magnetsystems/r2m-cli/releases) 

#### On Mac

Run:
```
brew install https://raw.githubusercontent.com/magnetsystems/r2m-cli/master/brew/r2m.rb
```

If you don't have _brew_, go to: http://brew.sh/


#### On all platforms

Unzip the rest2mobile zip file and add r2m to the path.

## How to use it

### Start in interactive mode:

```
r2m
Starting rest2mobile 1.0.0
Run 'gen --interactive' to generate Mobile APIs in interactive mode.
Type '?' for help. Use <TAB> for completion. <Ctrl-D> to abort commands.
r2m> gen 
```

### Get help
```
r2m> help -v gen
```
or check the [CLI usage](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-generate-code-gen).

### Build from existing examples

Here's a simple example generating the Google distance Mobile API for iOS, Android and Javascript

``` 
r2m> gen -d GoogleDistance 
```

You can get a list of examples with:

```
r2m> gen -l
```
All examples are available on [rest2mobile examples repo](https://github.com/magnetsystems/r2m-examples)
 
### Build with your own examples

You can also build your own Mobile API from existing REST examples or documentation. 
Find out how to create your own example [here](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-create-spec-file).

Examples are usually text files containing the copy-pasted URL request and response payloads from a REST documentation, curl invocation, or simply your browser.
Let's say you want to create a controller using the Google Time Zone API, simple type this in on your browser:


https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&sensor=true


Then you get this JSON response:
```json
{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}
```

Now copy-paste request and response in the file <code>example.txt</code>:
```
+Name getTimeZone
+Request
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&sensor=true

+Response
+Body
{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}

```
With this example file, you can now generate an async Mobile API with a strongly object model for Android, Javascript and iOS

### Generating Mobile API

Using the file created above, run <code>r2m</code> to generate the mobile code.

```
r2m> gen -e example.txt 
```

This generates the Mobile API for all platforms under the <code>mobile/</code> directory.

## Invoking the Mobile API


#### For Android

First, install the [rest2mobile Android SDK](https://github.com/magnetsystems/r2m-sdk-android) by modifying your app's build.gradle, as described [here](https://github.com/magnetsystems/rest2mobile/wiki/rest2mobile-setup-studio#update-the-build-file)

Then call the method in <code>mobile/android/com/magnet/controller/api/RestController.java</code>:
```java
  Call<TimeZoneResult> getTimeZone(
     String location,
     String timestamp,
     String sensor,
     StateChangedListener listener
  );  
```

For example, with:
```java
  MagnetMobileClient client = MagnetMobileClient.getInstance(this.getApplicationContext());
  RestControllerFactory factory = new RestControllerFactory(client);
  RestController controller = factory.obtainInstance();
  Call resp = controller.getTimeZone("39.6034810,-119.6822510", "1331161200", "true", null);
  TimeZoneResult result = resp.get();
  
  // assert result.getStatus() == "OK";
  // assert result.getTimeZoneId == "America/Los_Angeles";
  // assert result.getTimeZoneName == "Pacific Standard Time";
  // assert result.getDstOffSet() == 0;
  // assert result.getRawOffset() == -28800;
```

#### For iOS:
{'fraction_non_alphanumeric': 0.12027594481103779, 'fraction_numerical': 0.03139372125574885, 'mean_word_length': 4.532632743362832, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 49, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6971083', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3049, 'n_words': 1018}