# Deywuro Sender ID API

A RESTful API for managing Sender ID requests in the Deywuro messaging platform.

## Overview

The Deywuro Sender ID API allows clients to programmatically submit, track, and manage Sender ID requests. It connects to both the main Deywuro database and a dedicated API database to process and track these requests.

## Features

- Authenticate users using Deywuro credentials
- Submit new Sender ID requests
- Check status of existing requests
- IP whitelisting for enhanced security
- Email and SMS notifications for status changes
- API key management

## Requirements

- PHP 7.4+ with the following extensions:
  - mysqli
  - curl
  - json
- MySQL 5.7+ or MariaDB 10.2+
- Web server with URL rewriting (Apache, Nginx)

## Installation

1. Clone the repository:
   ```bash
   git clone https://github.com/deywuro/sender-id-api.git
   cd sender-id-api
   ```

2. Copy the configuration example file and update with your settings:
   ```bash
   cp config/config.example.php config/config.php
   # Edit config.php with your database credentials and other settings
   ```

3. Create the database tables:
   ```bash
   mysql -u your_user -p your_database < schema.sql
   ```

4. Set up directory permissions:
   ```bash
   mkdir -p logs
   chmod 755 logs
   chmod +x crons/status_check.php
   ```

5. Configure web server:

   **Apache**:
   ```apache
   <VirtualHost *:80>
       ServerName api.yourdomain.com
       DocumentRoot /path/to/sender-id-api

       <Directory /path/to/sender-id-api>
           AllowOverride All
           Require all granted
           Options -Indexes +FollowSymLinks
       </Directory>

       ErrorLog ${APACHE_LOG_DIR}/api-error.log
       CustomLog ${APACHE_LOG_DIR}/api-access.log combined
   </VirtualHost>
   ```
   
   **Nginx**:
   ```nginx
   server {
       listen 80;
       server_name api.yourdomain.com;
       root /path/to/sender-id-api;

       location / {
           try_files $uri $uri/ /index.php?$query_string;
       }

       location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
       }

       location ~ /\.ht {
           deny all;
       }
   }
   ```

6. Set up the cron job for status notifications:
   ```bash
   ./setup_cron.sh
   ```
   
   Alternatively, add this line to your crontab:
   ```
   */5 * * * * php /path/to/sender-id-api/crons/status_check.php >> /path/to/sender-id-api/logs/cron.log 2>&1
   ```

## Configuration Options

Key configuration options in `config/config.php`:

```php
// API Configuration
define('API_VERSION', 'v1');
define('API_BASE_URL', 'https://api.yourdomain.com/' . API_VERSION);

// Database Configuration
define('PRIMARY_DB_HOST', 'your_primary_db_host');
define('PRIMARY_DB_PORT', 3306);
define('PRIMARY_DB_USER', 'your_primary_db_user');
define('PRIMARY_DB_PASS', 'your_primary_db_password');
define('PRIMARY_DB_NAME', 'your_primary_db_name');

// API Database Configuration
define('API_DB_HOST', 'your_api_db_host');
define('API_DB_PORT', 3306);
define('API_DB_USER', 'your_api_db_user');
define('API_DB_PASS', 'your_api_db_password');
define('API_DB_NAME', 'your_api_db_name');

// SMS API Configuration for Notifications
define('SMS_API_URL', 'https://api.example.com/sms/send');
define('SMS_API_KEY', 'your_sms_api_key');

// Rate Limiting Configuration
define('RATE_LIMIT_HOUR', 100);
define('RATE_LIMIT_DAY', 1000);
```

## Usage

See the full API documentation in the following files:
- [Client API Guide](docs/client_api_guide.md) - For API consumers
- [Admin Technical Guide](docs/admin_technical_guide.md) - For system administrators

## API Endpoints Summary

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST   | /sender-id | Create a new sender ID request |
| GET    | /sender-id | Get all sender ID requests |
| GET    | /sender-id/{sender_id} | Get a specific sender ID |
| GET    | /sender-id/request/{request_id} | Get a request by ID |
| GET    | /whitelist | Get all whitelisted IPs |
| POST   | /whitelist/add | Add an IP to the whitelist |
| DELETE | /whitelist/remove | Remove an IP from whitelist |
| GET    | /auth/verify | Verify API key |

## Postman Collection

Import the [Postman collection](docs/postman_collection.json) for testing and exploring the API endpoints.

## Extending the API

1. Add new endpoints in `controllers/` directory
2. Update the routing in `index.php`
3. Add any new models in `models/` directory

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is proprietary and owned by Deywuro. All rights reserved.

## Support

For support, email support@deywuro.com or create an issue in the repository. 