# 1. Configuring shared modules for API and Cache Manager
Copy the below to a shell script file and execute it.

 ```sh
git clone git@github.com:theorchard/ows-film-transparency.git
cd ows-film-transparency

# Copy shared requirements into api requirements
while read line; do 
    if grep -q $line services/api/requirements-dev.txt
        then echo 'dev requirement already present'
    else 
        echo $line >> requirements.txt
    fi
done < services/shared/requirements-dev.txt

while read line; do 
    if grep -q $line services/api/requirements.txt
        then echo 'requirement already present'
    else 
        echo $line >> requirements.txt
    fi
done < services/shared/requirements.txt

# Copy shared code into the project root
cp -a  services/shared/shared  services/api/
 ```

# 2. Installing The API Microservice
The API is built with Flask and gets all the data from AWS Aurora that is populated by the ETLs.

```sh
$ cd ows-film-transparency/services/api
```

#### Environment Variables (no changes required)
```sh
api> cp .env.shadow .env
```

#### Installing Requirements
```sh
api> pyvenv ./env
api> pip install -r requirements.txt
api> pip install -r requirements-dev.txt
```

#### Running The API Microservice
You can access the api by visiting [http://localhost:8080/hello](http://localhost:8080/hello).

```sh
api> source .env
api> python application.py
```

#### API Documentation
We use [Sphinx](http://www.sphinx-doc.org/en/master/) to generate documentation from our docstrings.

To generate `.rst` files from docstrings:
``` sh
$ cd ows-film-transparency/services/api
$ cd docs
$ sphinx-apidoc -f -o source ../api/
```

To render the API docs locally:
```sh
$ cd docs
$ make html
```

# 3. Installing Cache Manager
The Cache Manager is a process that listens to SQS for messages on what cache to clear or create on Redis.

```sh
$ git clone git@github.com:theorchard/ows-film-transparency.git 
$ cd ows-film-transparency/services/cache_manager
```

#### Installing Requirements
```sh
cache_manager> pyvenv ./env
cache_manager> pip install -r requirements.txt
cache_manager> pip install -r requirements-dev.txt
```

#### Running The Cache Manager
```sh
cache_manager> source ../../etls/.env
cache_manager> python application.py
```
