Parent: [15a914] (diff)

Child: [456085] (diff)

Download this file

readme.md    648 lines (497 with data), 15.4 kB

ERROR! The markdown supplied could not be parsed correctly. Did you forget to surround a code snippet with "~~~~"?

## Notification Enabler
### Read me

#### 1. Prerequisite

In order to run this enabler code on your local machine you should have installed Docker.

#### 2. Instalation

Make sure the docker is installed on the system environment. 

##### 2.1. Clone the code repository:

`git clone https://<username>@opensourceprojects.eu/git/p/vfos/assets/enablers/nen/code vfos-assets-enablers-nen-code`

##### 2.2. Run multi-container Docker application
`This multi-container Docker application is composed by two services: `enabler` and `MySQL`.`

`Navigate to the clone directory and execute `docker-compose up --build` to startup the multi-container enabler on background.`

#### 2.3. Usage

`Whenever it's needed to have this enabler runnig, please execute `docker-compose up`.`

`On the browser please navigate to `localhost:5000` to reach the frontend module.`

Notification enabler will need the following Environment Variables:
`PORT 
USEREMAIL 
USERPWD
DBUSER
DBPASSWORD
DATABASE
DBCONLIMIT`

`This Environment Variables will be in data.env file, locate on the clone directory.`

#### 3. API

## vf-OS Enablers

### Enabler 2 - Get Rules

```http
GET /api/vf-os-enabler/v0/getRules/myawesomeappid
Accept: */*
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 11:04:31 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true,
    "data": [
        {
            "rulesID": 11,
            "description": "New Rule",
            "parameter": "slumptest",
            "conditionValue": ">",
            "controlValue": "5",
            "notificationType": 5,
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

Use this API call whenever is needed to retrieve all rules related to vApp.  

#### Request
`GET /api/vf-os-enabler/<api_version>/getRules/<app_id>`

#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.
app_id             | Identifies the APP.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the rules of app (if found).

In the following Example it's queried all rules related to specific appID:


```json
{
    "success": true,
    "data": [
        {
            "rulesID": 11,
            "description": "New Rule",
            "parameter": "slumptest",
            "conditionValue": ">",
            "controlValue": "5",
            "notificationType": 5,
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

#### Return Codes
Code | Description
---- | -----------
200  | Data Found.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Get Notifications

```http
GET /api/vf-os-enabler/v0/getNotifications/myawesomeappid
Accept: */*
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 11:04:31 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true,
    "data": [
        {
            "emailTo": "raquel.melo@knowledgebiz.pt",
            "subject": "slumptest>10",
            "date": "2018-04-27 12:06:02",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```
Use this API call whenever is needed to retrieve all notifications of vApp.

#### Request
`GET /api/vf-os-enabler/<api_version>/getNotifications/<app_id>`


#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.
app_id             | Identifies the APP to show the notifications.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the notifications of app (if found).

In the following Example it's queried the all notifications of specific appID:

```json
{
    "success": true,
    "data": [
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 15:39:51",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:06:00",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:06:09",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:08:30",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:09:51",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

#### Return Codes
Code | Description
---- | -----------
200  | Data Found.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Get Apps

```http
GET /api/vf-os-enabler/v0/getApps/david.aleixo@knowledgebiz.pt
Accept: */*
```


```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 13:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true,
    "data": [
        {
            "token": "Es5zfsco57fieoQcDJZuIZxFZWv4HQbBYgUXRgqodQp",
            "appID": "myawesomeappid",
            "developerID": "david.aleixo@knowledgebiz.pt"
        }
    ]
}
```
Use this API call whenever is needed to retrieve all apps of developerid.

#### Request
`GET /api/vf-os-enabler/<api_version>/getApps/<developer_id>`


#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.
developer_id       | Identifies the Developer.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the notifications of app (if found).

In the following Example it's queried the all Apps of specific developerID:

```json
{
    "success": true,
    "data": [
        {
            "token": "Es5zfsco57fieoQcDJZuIZxFZWv4HQbBYgUXRgqodQp",
            "appID": "MiguelID",
            "developerID": "painatal_vodka@hotmail.com"
        }
    ]
}
```

#### Return Codes
Code | Description
---- | -----------
200  | Data Found.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Delete vApp

```http
DELETE /api/vf-os-enabler/v0/app/myawesomeappid
Accept: */*
```


```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 13:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true
}
```
Use this API call whenever is needed to delete vApp.

#### Request
`GET /api/vf-os-enabler/<api_version>/app/<app_id>`


#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.
app_id             | Identifies the APP.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false**.

In the following Example it's delete the vApp:

```json
{
    "success": true
}
```

#### Return Codes

Code | Description
---- | ---
200  | vApp deleted successfully.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.



### Enabler 2 - Delete Rules

```http
DELETE /api/vf-os-enabler/v0/rule/1
Accept: */*
```


```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 13:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true
}
```
Use this API call whenever is needed to delete rule of vApp.

#### Request
`GET /api/vf-os-enabler/<api_version>/rule/<rule_id>`


#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.
rule_id            | Identifies the Rule.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false**.

In the following Example it's delete the rule:

```json
{
    "success": true
}
```

#### Return Codes
Code | Description
---- | -----------
200  | Rule deleted successfully.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Create Notifications

```http
POST http://localhost:8000/api/vf-os-enabler/v0/notifications
Accept: */*
Content-Type: application/json; charset=utf-8

{
	"emailTo":[
		"my_email1",
		"my_email2"
	],
	"token":"my_token",
	"body":[
		{"subject":"my_Subject_1",
		 "subjectValue": "my_SubjectValue_1"
		},
		{"subject":"my_Subject_2",
		 "subjectValue": "my_SubjectValue_2"
		},
		{"subject":"my_Subject_3",
		 "subjectValue": "my_SubjectValue_3"
		}
	]
}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{"success": true}
```

Use this API call whenever is needed to create a new notification.

#### Request
`POST /api/vf-os-enabler/<api_version>/notifications`

#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.

#### JSON Body Payload

Name    | Required    | Type   | Description
------- | ----------- | ------ | -----------
emailTo |    Yes      | STRING | String where is the emails.  
token   |    Yes      | STRING | String where is the token. 
body    |    Yes      | JSON   | JSON document where is the subject and subjectValue. 

Example of JSON body payload structure: 
`	{
		"emailTo": [
			"string",
			"string"
		 ],
		"token": "string",
		"body": [
			{
				"subject" : "stirng",
				"subjectValue" : "string"
			},{
				"subject" : "string",
				"subjectValue" : "string"
			},{
				"subject" : "stirng",
				"subjectValue" : "string"
			}
		]
	}`

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `reason` if the `success` became **false**.

Example:

```json
{
     "success": true
}
```

#### Return Codes
Code | Description
---- | ----
200  | Notification created successfully.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Register vApp

```http
POST http://localhost:8000/api/vf-os-enabler/v0/register
Accept: */*
Content-Type: application/json; charset=utf-8

{
	"appID":[
		"my_appID1",
		"my_appID2"
	],
	"developerID":[
		"my_developerID",
		"my_developerID"
	]
}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

    "success": true,
    "data": {
        "token": "Z58oqMmXJJzC1KHAaPurgohg00xgklomu5DVXgcZwj4"
    }
```

Use this API call whenever is needed to create vApp.

#### Request
`POST /api/vf-os-enabler/<api_version>/register`

#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.

#### JSON Body Payload

Name          | Required    | Type   | Description
------------- | ----------- | ------ | -----------
appID         |    Yes      | STRING | String where is the appID.  
developerID   |    Yes      | STRING | String where is the developerID.  

Example of JSON body payload structure: 
`   {
        "appID": [
            "string",
            "string"
         ],
        "developerID": [
            "string",
            "string"
         ],
    }`

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` if the `success` became **false**.

Example:

```json
{
    "success": true,
    "data": {
        "token": "Z58oqMmXJJzC1KHAaPurgohg00xgklomu5DVXgcZwj4"
    }
}
```

#### Return Codes
Code | Description
---- | ----
200  | vApp created successfully.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.

### Enabler 2 - Create Rules

```http
POST http://localhost:8000/api/vf-os-enabler/v0/notification/rules
Accept: */*
Content-Type: application/json; charset=utf-8

{
	"appID":"my_appID",
	"description":"my_description",
	"parameter":"my_parameter",
	"conditionValue":"my_conditionValue",
	"controlValue":"my_controlValue",
	"notificationType":"my_notificationType"
}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true
}
```

Use this API call whenever is needed to create a rule of vApp.

#### Request
`POST /api/vf-os-enabler/<api_version>/notification/rules/`

#### URL Parameters

Resource Parameter | Description
------------------ | -----------
api_version        | Identifies the API version that will be used for the request.

#### JSON Body Payload

Name             | Required | Type   | Description
---------------- | -------- | ------ | -----------
appID            | Yes      | STRING | String where is the vAppID. 
description      | Yes      | STRING | String where is the description.
parameter        | Yes      | STRING | String where is the parameter for the rule.
conditionValue   | Yes      | STRING | String where is the conditionValue (>, <, >=, <=).
controlValue     | Yes      | STRING | String where is the controlValue (Threshold).
notificationType | Yes      | STRING | String where is the Notification Type (1 - Notify End of Month, 2 - Notify End of Two Weeks, 3 - Notify End of Week, 4 - Notify End of Three Days, 5 - Notify Immediately).

Example of JSON body payload structure: 
`   {
        "appID": "string",
        "description": "string",
        "parameter": "string",
        "conditionValue": "string",
        "controlValue": "string",
        "notificationType": "string"
    }`

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `reason` if the `success` became **false**.

Example:

```json
{
     "success": true
}
```

#### Return Codes
Code | Description
---- | ----
200  | Rule created successfully.
500  | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Powered by:

![alt text](https://static.wixstatic.com/media/d65bd8_d460ab5a6ff54207a8ac3e7497af18c4~mv2_d_4201_2594_s_4_2.png "Notification Enabler")