#General Information
The base urls for all API request are:

- Development: http://stream.dev.audionow.com/digital/api/
- Production: http://stream.audionow.com/digital/api/

Every request should contain one of the following parameters.

Header params:

- Accept-App (e.g. RFI)
- Accept-User (e.g. 441cab1a-5191-47aa-ad47-cda74a4167a8)
- Accept-Lang (e.g. en)

GET params:

- app (e.g. RFI)
- user (e.g. 441cab1a-5191-47aa-ad47-cda74a4167a8)
- lang (e.g. en)

If both are specified the GET param wins.

##Cache

The caching is done on [redis][redis].

To inspect or remove caching endris use the redis-cli command in either interactive (shell) or direct way:

```shell
redis-cli get [key]
redis-cli del [key]
redis-cli flushall
```

##Return status
The success or fail status and message is returned in both HTTP return code and JSON fields.
Generic return format folowing format:
HTTP: 200 OK
JSON:
```json
{"status":"ok"}
```

or

HTTP: 404 Not found
JSON:
```json
{
"status":"fail",
"errorInfo":"User does not exist"
}
```
#localization
<http://stream.dev.audionow.com/digital/api/v1/localization>

###Method
GET

###Description
Gets the the available localization for the current app

###Parameters
None

###Output
Returns an array named languages with objects containing `code`, `name` and `font` attributes. 

##Example
```json
{
    "languages": [
        {
            "code": "en",
            "name": "English",
            "font": ""
        }
    ],
    "status": "ok"
}
```


#strings
<http://stream.dev.audionow.com/dev/digital/api/v1/strings>

###Method
GET

###Description
Gets the available strings for the current app and language.
The priority of the extracted strings is the following:
* take LANG strings for the current app
* add LANG strings from the app 0 if there are extra
* add english strings from the current app that are extra
* add english strings from the app 0 if there are extra

###Parameters
None

###Output
Returns an object named strings with key-value pairs of string identifier and corresponding translation.

##Example
```json
{

    "strings": {
        "dialUnable": "Impossible d'appeller le numéro de cette station",
        "Login": "Connexion",
        "titleSearchResults": "Résultats de la Recherche",
        "ValidatePasswordError": "Mot de passe doit comporter au moins 4 caractères",
        "ErrorTitle": "Oh non!",
        "TweetsNotLoggedIn": "Vous n'êtes pas connecté",
        "streamDownDial": "Flux indisponible pour le moment.\nVeuillez vous appeller pour écouter la station via téléphone.",
        "shareListening": "Ecoute de %@ sur %@",
        "sipConnectError": "Erreur de connexion de l'appel",
        "TweetsNoMore": "Plus de tweets disponibles",
        "Notifications": "Notifications",
    },
    "status": "ok"

}
```


#station
[http://stream.dev.audionow.com/dev/digital/api/v1/station/[station_id]][stationlink]

[stationlink]: http://stream.dev.audionow.com/dev/digital/api/v1/station

###Method
GET

###Description
Gets the profile of the requested station if station_id is specified.
If station_id is not specified then it will get all the stations that are
available for the current user within the current app.

###Parameters
Optional parameters:
>**station_id** - The uid of the station

###Output
1) If station_id is specified:
* Returns a list of key-value pairs of station property identifier and corresponding station property value.

2) If station_id is not specified:
* Returns an object named stations containing an array of stations. Each station is described as a list of 
key-value pairs of station property identifier and corresponding station property value.

##Example
```json
{
    "name": "Français",
    "plain_name": "RFI Français",
    "imgurl": "http://stream.audionow.com/digital/assets/stationimg/RFI_421__.jpg",
    "backgroundurl": "http://stream.audionow.com/digital/assets/stationbackground/french.jpg",
    "id": "421",
    "description": "Actualités, info, news en direct - Radio France Internationale - RFI",
    "uid": "421",
    "analyticscode": "UA-43454393-1",
    "webcolor": "e20000",
    "logo_html": "",
    "displaybanner": "1",
    "textToShare": "Check out this app on Google Play and Apple Store for Français. It allows you to listen to the radio by both voice and data plans. Thought you would enjoy!",
    "adnetworkcode": "a15231d3b80c8ed",
    "twitterhandle": null,
    "channels": [
        {
            "id": "925"
            "name": "Direct Monde"
            "entries": [
                {
                    "id": "84"
                    "name": "Direct Monde"
                    "live": "1"
                    "duration": "-1"
                    "creation_time": ""
                    "streams": [
                        {
                            "id": "1659"
                            "quality": "66"
                            "name": "med"
                            "url": "http:\/\/stream.rfi.fr\/rfimonde\/all\/rfimonde-64k.mp3"
                            "type": "mp3"
                        }
                        {
                            ...
                        }
                    ]
                }
                {
                    ...
                }
            ]
        }
        {
           ...
        },
    ],
    "social": [
        {
            "name": "Website",
            "url": "http://www.rfi.fr",
            "img": "http://stream.audionow.com/digital/assets/stationimg/social/socialIcons_site-0133.png"
        },
        {
            ...
        }
    ],
    "languages": [
        {
            "name": "English"
            "code": "en"
        }
        {
            ...
        }
    ]
    "adkeywords": [
        "gicatest2"
    ],
    "phone": null,
    "status": "ok"
}
```

#profile
[http://stream.dev.audionow.com/dev/digital/api/v1/profile/[action]/[parameter1]/[parameter2]/...][profilelink]

[profilelink]: http://stream.dev.audionow.com/dev/digital/api/v1/profile

###Method
GET

###Description
If action is not specified:
* Gets the profile of the current user within the current app. Performs an automatic register.
If action is specified:
* Perform the specified action for the current user using the specified parameters
(each action has different parameters)

###Parameters
Optional parameters:
* **action** - The action that should be performed for the current user
* Parameters for each action:
>**[notify]** 
>> **station_id** -> The uid of the station
**push** -> 1/0 (enable / disable pushnotifications)

>**[add]**
>> **station_id** -> The uid of the station

>**[remove]**
>> **station_id** -> The uid of the station

>**[register]**
>> **propertyName** -> The name of the property that should be used to push notifications - 'iOsPushId' or 'androidPushId'
 **propertyValue** -> The value of the property that should be used to push notifications
 These parameters are optional together (omit both or none)

>**[merge]**
>> **old_uid** -> The uid of the user whose profile will be merged with the profile of the current user

>**[reorder]**
>> **station_id** -> The uid of the station that will be repositioned within stations list of the current user
 **pos** -> The new position of the station specified by station_id 

###Output
1) If action is not specified:
* Returns an object named items containing an array of stations. Each station is described as a list of 
key-value pairs of station property identifier and corresponding station property value.

2) If action is specified:
* Returns an object named status containing the string "ok" if the operation was completed successfully.

##Example
```json
{
    "items": [
        {
            "adnetworkcode": "a15231d3b80c8ed",
            "station_id": "421",
            "name": "RFI Français",
            "logo_url": "http://stream.audionow.com/digital/assets/stationimg/RFI_421__.jpg",
            "backgroundurl": "http://stream.audionow.com/digital/assets/stationbackground/french.jpg",
            "pushnotification": "-1"
        },
        {
            ...
        }
    ],
    "splash_url": ""
    "default_station_id": "test-04"
    "status": "ok"
}
```

[redis]: http://redis.io

#stats
http://stream.dev.audionow.com/digital/api/v1/stats

###Method
POST

###Description
Sends usage statistics to the server and registers user agents.
- 3 types of events: 
- PLAYER - events generated by the media player
- VIEW - events generated when user changes active view
- ACTION - events generated for user actions (buttons, menu items, etc)
- “timestamp” value should be in UTC timezone
- param1, param2, param3 depend on the “type” and “name” values and they are not all mandatory:
	TYPE = PLAYER
	name = “play” ->
		param1 = station id
		param2 = channel id
		param3 = entry id
        param4 = stream id
        param5 = time

	name = “pause/stop/end/error” ->
		param1 = stationId
		param2 = streamId
		param3 = streamUrlId
		param4 = time_since_last_play (number of seconds since last play event)        
	
	TYPE = VIEW
	name = “station” -> param1 = stationId

	TYPE = ACTION
	name = “download” -> param1 = streamId
	name = “share” -> 	param1 = facebook, twitter, google+, other
				param2 = big_player, small_player
	name = “social” -> param1 = name of the social action (as it comes from the server)
	name = “quality” -> param1 = selected_low, selected_med, selected_high
			    -> param2 = stream, global
	name = “play” -> param1 = big_player, small_player, mini_player, micro_player
name = “pause” -> param1 = big_player, small_player, mini_player, micro_player
	
big_player 	- Player with big buttons in the lower part of the station view
small_player 	- Player with smaller buttons in the upper part of the station view
mini_player 	- Player in the bottom of the station view (in the advertising area)
micro_player 	- Player in the system notification area when application is in background

###Parameters
```json
{
"userId":"f7676e03-341c-4829-bae5-8433344980c7",

"events":[
     	{
		“type”:”PLAYER”,
       		"name":"play/pause/stop/end/error",
		"timestamp":"2014-04-15 11:46:00",
       		"param1":"806",    		// stationId
       		"param2":"455",		// streamId
       		"param3":"123"		// streamUrlId
		“param4”:”43”			// nr of seconds since last play
    	 },
    	 {
		“type”:”VIEW”,
		“name”:”station/settings/left_menu/right_menu/quality/language/splash”,
		"timestamp":"2014-04-15 11:46:00",
		“param1”:””,	    		// OPTIONAL: stationId for example
		“param2”:””			// OPTIONAL: undefined
		“param3”:””			// OPTIONAL: undefined
     	},
     	{
	“type”:”ACTION”,
	“name”:”download/share/social/play/pause/quality/mini_player”,
	"timestamp":"2014-04-15 11:46:00",
	“param1”:””,			// OPTIONAL: streamId, facebook, twitter,                sip, email, website, etc.
	“param2”:””,			// OPTIONAL: undefined
“param3”:””			// OPTIONAL: undefined
}
   ]
}
```

###Output
Success or fail of the stats registration.

##Example
```json
{
"status": "ok"
}
```

#picture upload



http://stream.dev.audionow.com/digital/api/v1/picture/[station_id]

###Method
POST

###Description
Will save the message and the picture received in a multipart form (message/file fields).

The multipart form data has to be similar to the one send by the following html code:

```html
<form action="." method="post" enctype="multipart/form-data">
<input type="text" name="message">
<input type="text" name="email">
<input type="text" name="phone">
<input type="file" name="file">
<input type="submit" name="submit" value="Submit">
</form>
```

###Parameters
>**station_id** - The uid of the station to receive the picture

###Output
This method will only show a status ok or fail response.

##Example
```json
{
"status": "ok"
}
```
