Skip to content

Commit a3220cd

Browse files
committed
Clean up.
1 parent b1fb232 commit a3220cd

File tree

6 files changed

+86
-49
lines changed

6 files changed

+86
-49
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 Phantom App Development
3+
Copyright (c) 2017 Phantom App Development
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Firebase is a back end platform that offers several services to aid in the development of apps and games, specially the ones that rely on server side infrastructure.
44

5-
Some of its services can be accessed by using RESTful techniques. This repository contains detailed guides and [examples](./examples) explaining how to use those services in your `Adobe AIR ` projects.
5+
Some of its services can be accessed by using a RESTful approach. This repository contains detailed guides and [examples](./examples) explaining how to use those services in your `Adobe AIR ` projects.
66

77
You won't need an `ANE` for these guides, all of them work only using `StageWebView`, `URLRequest` and `URLLoader`.
88

auth/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ Once you have the profile information you might want to save it on an Object tha
206206
## Obtaining and Refreshing an Access Token
207207

208208
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
209-
To obtain or refresh an `access_token` you only need to provide a `refreshToken` from a Sign In request and specify the `grant_type` as `"refresh_token"`.
209+
To obtain or refresh an `access_token` you only need to provide the following parameters:
210+
211+
Name | Description
212+
---|---
213+
`refreshToken` | A long encoded String that contains user information. You can obtain it from a Sign In request.
214+
`grant_type` | Set to: `refresh_token`
210215

211216
```actionscript
212217
private function refreshToken(refreshToken:String):void

auth/email/README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ private function errorHandler(event:flash.events.IOErrorEvent):void
3535

3636
## Registering a New User (Sign Up)
3737

38-
To register a new user you only require to provide a valid formatted Email Address and a non weak Password.
38+
To register a new user you only require to provide the following parameters:
39+
40+
Name | Description
41+
---|---
42+
`email` | A valid formatted Email Address.
43+
`password` | A non weak Password.
44+
`returnSecureToken` | Set to: `true`
3945

4046
```actionscript
4147
private function register(email:String, password:String):void
@@ -84,7 +90,13 @@ The `refreshToken` is used to get an `access_token` for Auth requests. For more
8490

8591
## Verifying Credentials (Sign In)
8692

87-
To sign in an user you only require to provide their valid Email Address and Password and the `returnSecureToken` parameter.
93+
To sign in an user you only require to provide the following parameters:
94+
95+
Name | Description
96+
---|---
97+
`email` | The user's Email Address.
98+
`password` | The user's Password.
99+
`returnSecureToken` | Set to: `true`
88100

89101
```actionscript
90102
private function login(email:String, password:String):void
@@ -135,10 +147,12 @@ The `refreshToken` is used to get an `access_token` for Auth requests. For more
135147

136148
## Password Reset
137149

138-
To reset a password you only require to provide 2 parameters:
150+
To reset a password you only require to provide the following parameters:
139151

140-
* `email` is the Email Address you want to send the Password recovery email.
141-
* `requestType` with the value: `PASSWORD_RESET`
152+
Name | Description
153+
---|---
154+
`email` | The Email Address you want to send the Password recovery email.
155+
`requestType` | Set to: `PASSWORD_RESET`
142156

143157
```actionscript
144158
private function resetPassword(emai:String):void
@@ -185,9 +199,11 @@ This is commonly used in message boards and ecommerce solutions.
185199

186200
This method is similar to the Reset Password one, you need to provide the following parameters:
187201

188-
* `email` is the email address you want to verify.
189-
* `requestType` with the value: `EMAIL_VERIFY`
190-
* `idToken` is a long encoded String that contains user information. You can obtain this String from the response Object in the Sign Up and Sign In methods.
202+
Name | Description
203+
---|---
204+
`email` | The Email Address you want to verify.
205+
`requestType` | Set to: `EMAIL_VERIFY`
206+
`idToken` | A long encoded String that contains user information. You can obtain this String from the response in the Sign Up and Sign In methods.
191207

192208
```actionscript
193209
private function verifyEmail(idToken:String, email:String):void
@@ -395,7 +411,12 @@ A successful response will look like the following JSON structure:
395411
## Obtaining and Refreshing an Access Token
396412

397413
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
398-
To obtain or refresh an `access_token` you only need to provide a `refreshToken` from a Sign In request and specify the `grant_type` as `"refresh_token"`.
414+
To obtain or refresh an `access_token` you only need to provide the following parameters:
415+
416+
Name | Description
417+
---|---
418+
`refreshToken` | A long encoded String that contains user information. You can obtain it from a Sign In request.
419+
`grant_type` | Set to: `refresh_token`
399420

400421
```actionscript
401422
private function refreshToken(refreshToken:String):void

database/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ private function loadNews():void
155155
private function newsLoaded(event:flash.events.Event):void
156156
{
157157
trace(event.currentTarget.data);
158-
var rawData:Object = JSON.parse(event.currentTarget.data);
159158
}
160159
```
161160

162-
A simple GET request (the default for `URLRequest`) is enough. Remember to always add `.json` after the name of the node you want to read.
161+
A simple `GET` request (the default for `URLRequest`) is enough. Remember to always add `.json` after the name of the node you want to read.
163162

164163
To load a Private resource use the following code:
165164

@@ -176,7 +175,6 @@ private function loadSpecialOffers(authToken:String):void
176175
private function offersLoaded(event:flash.events.Event):void
177176
{
178177
trace(event.currentTarget.data);
179-
var rawData:Object = JSON.parse(event.currentTarget.data);
180178
}
181179
```
182180

@@ -359,7 +357,7 @@ For example, we want that each user has their independent journal that they can
359357
}
360358
```
361359

362-
When you want to modify or read their journal you need to specify the users's `localId` (known as `uid` inside the rules) and `authToken` as part of the URL.
360+
When you want to modify or read their journal you need to specify the users `localId` (known as `uid` inside the rules) and `authToken` as part of the URL.
363361

364362
```actionscript
365363
private function loadPrivateJournal(localId:String, authToken:String):void
@@ -374,7 +372,6 @@ private function loadPrivateJournal(localId:String, authToken:String):void
374372
private function journalLoaded(event:flash.events.Event):void
375373
{
376374
trace(event.currentTarget.data);
377-
var rawData:Object = JSON.parse(event.currentTarget.data);
378375
}
379376
```
380377

storage/README.md

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Files are stored the same way as in your personal computer, using a tree hierarc
66

77
It is strongly recommended to avoid the use of special characters when naming files and folders.
88

9-
You need special care for the slash character `(/)`. I recommend using this helper function to URL encode them:
9+
You will need special care for the slash character `(/)`. I recommend using this helper function to URL encode them:
1010

1111
```actionscript
1212
private function formatUrl(url:String):String
@@ -84,11 +84,10 @@ service firebase.storage {
8484
}
8585
```
8686

87-
## Uploading a File
87+
## Prerequisites
8888

89-
To upload a file you require to send it as a `ByteArray`. The following snippets show the most common scenarios.
9089

91-
All of the examples use the following `Event.COMPLETE` and `IOErrorEvent.IOERROR` listeners.
90+
Since Firebase returns useful error information we will use the following `Event.COMPLETE` and `IOErrorEvent.IOERROR` listeners in all of our requests.
9291

9392
```actionscript
9493
private function uploadComplete(event:flash.events.Event):void
@@ -102,9 +101,11 @@ private function errorHandler(event:flash.events.Event):void
102101
}
103102
```
104103

105-
If you upload the same file to the same location, it will be replaced with new metadata.
104+
## Uploading from a fixed location
106105

107-
### Uploading from a fixed location
106+
To upload a file you require to send it as a `ByteArray`. The following snippets show the most common scenarios.
107+
108+
If you upload the same file to the same location, it will be replaced with new metadata.
108109

109110
In this example we are uploading a file from a predefined location. A common example is syncing a save game after a game session:
110111

@@ -119,7 +120,7 @@ private function uploadFile():void
119120
fileStream.readBytes(bytes);
120121
fileStream.close();
121122
122-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
123+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
123124
request.method = URLRequestMethod.POST;
124125
request.data = bytes;
125126
request.contentType = "text/plain";
@@ -156,9 +157,9 @@ Your new file and a `savegames` folder will instantly appear in the Storage sect
156157

157158
The `contentType` doesn't need to be accurate, but it is recommended to set it properly.
158159

159-
### Uploading with Auth
160+
## Uploading with Auth
160161

161-
Authorizing requests for Firebase Storage is a bit different than in Firebase Database. Instead of adding an `auth` parameter in the URL with the `authToken`, we add it into an `URLRequestHeader`.
162+
Authorizing requests for Firebase Storage is a bit different than in Firebase Database. Instead of adding an `auth` parameter in the URL with the `authToken`, we add it into a header.
162163

163164
```actionscript
164165
private function uploadFile(authToken:String):void
@@ -173,7 +174,7 @@ private function uploadFile(authToken:String):void
173174
174175
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
175176
176-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
177+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
177178
request.method = URLRequestMethod.POST;
178179
request.data = bytes;
179180
request.contentType = "text/plain";
@@ -220,7 +221,7 @@ private function deleteFile():void
220221
{
221222
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
222223
223-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
224+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
224225
request.method = URLRequestMethod.POST;
225226
request.requestHeaders.push(header);
226227
@@ -233,15 +234,17 @@ private function deleteFile():void
233234

234235
A successful response will return an [empty String](https://cloud.google.com/storage/docs/json_api/v1/objects/delete).
235236

236-
Use the following snippet if you want to delete the same file using authentication:
237+
## Deleting a File with Auth
238+
239+
To delete a file with authentication you only need to provide an `authToken` in the `Authorization` header and the file path in a `DELETE` request.
237240

238241
```actionscript
239242
private function deleteFile(authToken:String):void
240243
{
241244
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
242245
var header2:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
243246
244-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
247+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
245248
request.method = URLRequestMethod.POST;
246249
request.requestHeaders.push(header);
247250
request.requestHeaders.push(header2);
@@ -255,7 +258,7 @@ private function deleteFile(authToken:String):void
255258

256259
## Updating Metadata
257260

258-
To modify the metadata generated after your upload a file you will only require to indicate which fields do you need to update. This is very similar as updating the Firebase Database data.
261+
To modify the metadata generated after your upload a file you will only require to `JSON` encode which fields do you need to update and send them in a `PATCH` request. This is very similar as updating the Firebase Database data.
259262

260263
Click [here](https://firebase.google.com/docs/storage/web/file-metadata) for a list of all the fields that can be modified. In the following example we are going to change the `contentType`.
261264

@@ -302,19 +305,23 @@ A successful response will look like the following JSON structure:
302305
}
303306
```
304307

305-
Use the following snippet if you want to update the same file using authentication:
308+
## Updating Metadata with Auth
309+
310+
To update metadata with authentication you need to provide an `authToken` in the `Authorization` header.
311+
312+
You will also require to `JSON` encode which fields do you need to update and send them in a `PATCH` request.
306313

307314
```actionscript
308-
private function updateMetadata():void
315+
private function updateMetadata(authToken:String):void
309316
{
310317
var myObject:Object = new Object();
311318
myObject.contentType = "application/binary";
312319
313320
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "PATCH");
314321
var header2:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
315-
var header3:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+profile.authToken);
322+
var header3:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
316323
317-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
324+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
318325
request.method = URLRequestMethod.POST;
319326
request.data = JSON.stringify(myObject);
320327
request.requestHeaders.push(header);
@@ -328,11 +335,16 @@ private function updateMetadata():void
328335
}
329336
```
330337

331-
## Downloading Files
338+
## Downloading a File
332339

333340
To download files from your Firebase Storage bucket you only require to send a `GET` request with the full path of the file and the parameter `alt=media`.
341+
You will also require the followinv values from the `JSON` structure.
334342

335-
We are going to use the following JSON structure as our example:
343+
Name | Description
344+
---|---
345+
`name` | The path of the file including its name.
346+
`bucket` | Your Firebase Project ID plus the `appspot.com` domain.
347+
`downloadTokens` | A String used for downloading private files.
336348

337349
```json
338350
{
@@ -355,30 +367,30 @@ We are going to use the following JSON structure as our example:
355367

356368
There are several ways to download files using the AIR runtime, we are going to use the easiest one: `navigateToURL()`.
357369

358-
Use the following code to download a `public` file:
370+
The following example downloads a `public` file:
359371

360372
```actionscript
361373
private function downloadFile():void
362374
{
363-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data?alt=media");
375+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data"+"?alt=media");
364376
navigateToURL(request);
365377
}
366378
```
367379

368-
Use the following code to download a `private` file:
380+
## Downloading a Private File
381+
382+
Downloading `private` files doesn't require the `Authorization` header. You only require to provide the `token` parameter and the file path.
383+
384+
The `token` parameter is the `downloadTokens` value from the `JSON` response when you upload a file.
369385

370386
```actionscript
371387
private function downloadFile(downloadTokens:String):void
372388
{
373-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data?alt=media&token="+downloadTokens);
389+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data"+"?alt=media&token="+downloadTokens);
374390
navigateToURL(request);
375391
}
376392
```
377393

378-
Don't forget to encode the slash character from `(/)` to `%2F`.
379-
380-
The `token` parameter refers to the `downloadTokens` value from the JSON response when you upload a file.
381-
382394
## Downloading Metadata
383395

384396
You can download the information of any file in JSON format without downloading the file itself.
@@ -388,7 +400,7 @@ To download the metadata of a `public` file you only require to send a `GET` req
388400
```actionscript
389401
private function downloadMetadata():void
390402
{
391-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
403+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
392404
393405
var loader:URLLoader = new URLLoader();
394406
loader.addEventListener(flash.events.event.COMPLETE, metadataLoaded);
@@ -401,14 +413,16 @@ private function metadataLoaded(event:flash.events.Event):void
401413
}
402414
```
403415

404-
Use the following snippet to download the metadata of a `private` file:
416+
## Downloading Private Metadata
417+
418+
To download metadata from `private` files you require to provide an `authToken` in the `Authorization` header.
405419

406420
```actionscript
407421
private function downloadMetadata(authToken:String):void
408422
{
409423
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
410424
411-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
425+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
412426
request.method = URLRequestMethod.POST;
413427
request.requestHeaders.push(header);
414428
@@ -473,7 +487,7 @@ private function uploadPersonalFile(authToken:String, localId:String):void
473487
474488
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
475489
476-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+localId+"%2Fsavegame.data");
490+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+localId+"%2F"+"savegame.data");
477491
request.method = URLRequestMethod.POST;
478492
request.data = bytes;
479493
request.contentType = "text/plain";

0 commit comments

Comments
 (0)