Skip to content

Commit

Permalink
Fix for review
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouault committed May 23, 2016
1 parent bddc612 commit 101319a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 21 deletions.
63 changes: 43 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Description

PhoneGap plugin for managing application assets with javascript asset maps. Includes (iOS background threaded) downloadFile, getFileURI, getFileURIs, deleteFile, deleteFiles.
PhoneGap plugin for managing application assets with javascript asset maps. Includes downloadFile, getFileURI, getFileURIs, deleteFile, deleteFiles.


## Install (with Plugman)
Expand All @@ -22,52 +22,57 @@ PhoneGap plugin for managing application assets with javascript asset maps. Incl

## APIs

### downloadFile()

**wizAssets.downloadFile(String remoteURL, String assetId, Function success, Function fail);**
### wizAssets.downloadFile(remoteURL, assetId, success, fail)

- downloads a file to native App directory @ ./ + gameDir+ / +filePathToBeStoredWithFilename <br />
- A success returns a local URL string like; file://documents/settings/img/cards/card001.jpg <br />
- example;
- An error returns an error object such as:
```
{
"code": WizAssetsError value,
"status": if code is a HTTP_REQUEST_ERROR, the status of the HTPP request, optional
"message": description of the error if any
}
```

**Example**
```
wizAssets.downloadFile("http://google.com/logo.jpg", "img/ui/logo.jpg", successCallback, failCallback);
```

### deleteFile()

**wizAssets.deleteFile(string assetId, Function success, Function fail);**
### wizAssets.deleteFile(assetId, success, fail)

- deletes the file specified by the asset id <br />
- if the asset id does not exist fail will be called with error NotFoundError <br />
- if the asset id cannot be deleted (i.e. file resides in read-only memory) fail will be called with error NotModificationAllowedError


**Example**
```
wizAssets.deleteFile("file://documents/settings/img/cards/card001.jpg", successCallback, failCallback);
wizAssets.deleteFile("img/cards/card001.jpg", successCallback, failCallback);
```

### deleteFiles()

**wizAssets.deleteFiles(Array assetIds, Function success, Function fail );**
### wizAssets.deleteFiles(assetIds, success, fail)

- delete files specified by their asset id in Array like; [ "img/cards/card001.jpg", "img/cards/card002.jpg " .. ] <br />
- delete files specified by their asset id in Array <br />
- if an asset id uses a path format and matches a folder, then the folder content will be deleted; img/cards <br />
- the array CAN contain one asset id

### getFileURI()
**Example**
```
wizAssets.deleteFiles(["img/cards/card001.jpg", "img/cards/card002.jpg"], successCallback, failCallback);
```

**wizAssets.getFileURI(String assetId, Function success, Function fail);**
### wizAssets.getFileURI(assetId, success, fail)

- A success returns a local URL string like file://documents/settings/img/cards/card001.jpg <br />
- example;

**Example**
```
wizAssets.getFileURI("img/ui/logo.jpg", successCallback, failCallback);
```

### getFileURIs()

**wizAssets.getFileURIs(Function success, Function fail);**
### wizAssets.getFileURIs(success, fail)

- A success returns a hashmap of asset id matching its local URL such as

Expand All @@ -77,5 +82,23 @@ wizAssets.getFileURI("img/ui/logo.jpg", successCallback, failCallback);
"img/ui/loader.gif" : "/sdcard/<appname>/img/ui/loading.gif",
"img/cards/card001.jpg" : "file://documents/settings/img/cards/card001.jpg"
}
}
```

**Example**
```
wizAssets.getFileURIs(successCallback, failCallback);
```

### Error handling

| Code | Constant | Description |
|-----:|:-----------------------------|:-------------------------------------------------------------------------------------------------------|
| 1 | `ARGS_MISSING_ERROR` | Arguments are missing in your call to WizAssets' method |
| 2 | `INVALID_URL_ERROR` | Specified URL to download is invald |
| 3 | `CONNECTIVITY_ERROR` | Download could not be processed because network could not be accessed |
| 4 | `HTTP_REQUEST_ERROR` | HTTP status of the request is not successful (not 2XX) |
| 5 | `HTTP_REQUEST_CONTENT_ERROR` | Content received in HTTP request could not be read |
| 6 | `DIRECTORY_CREATION_ERROR` | Creation of the directory to save the asset failed |
| 7 | `FILE_CREATION_ERROR` | Saving the asset failed |
| 8 | `JSON_CREATION_ERROR` | Your call to WizAssets' method failed and its error could not be processed internally |
3 changes: 3 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<js-module src="www/phonegap/plugin/wizAssets/wizAssets.js" name="wizAssetsPlugin" target="phonegap/plugin/wizAssets/wizAssets.js">
<clobbers target="window.wizAssets" />
</js-module>
<js-module src="www/phonegap/plugin/wizAssets/WizAssetsError.js" name="WizAssetsError" target="phonegap/plugin/wizAssets/WizAssetsError.js">
<clobbers target="window.WizAssetsError" />
</js-module>

<!-- ios -->
<platform name="ios">
Expand Down
41 changes: 41 additions & 0 deletions www/phonegap/plugin/wizAssets/WizAssetsError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Wizcorp Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* WizAssetsError
*/
function WizAssetsError(error) {
this.code = error || null;
}

// WizPurchase error codes
WizAssetsError.ARGS_MISSING_ERROR = 1;
WizAssetsError.INVALID_URL_ERROR = 2;
WizAssetsError.CONNECTIVITY_ERROR = 3;
WizAssetsError.HTTP_REQUEST_ERROR = 4;
WizAssetsError.HTTP_REQUEST_CONTENT_ERROR = 5;
WizAssetsError.DIRECTORY_CREATION_ERROR = 6;
WizAssetsError.FILE_CREATION_ERROR = 7;
WizAssetsError.JSON_CREATION_ERROR = 8;

module.exports = WizAssetsError;
8 changes: 7 additions & 1 deletion www/phonegap/plugin/wizAssets/wizAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ var wizAssets = {
downloadFile: function (url, filePath, s, f) {
window.setTimeout(
function () {
exec(s, f, "WizAssetsPlugin", "downloadFile", [url, filePath]);
function failure(error) {
if (error === WizAssetsError.JSON_CREATION_ERROR) {
error = new WizAssetsError(error);
}
return f(error);
}
exec(s, failure, "WizAssetsPlugin", "downloadFile", [url, filePath]);
}, 0);
},
deleteFile: function (uri, s, f) {
Expand Down

0 comments on commit 101319a

Please sign in to comment.