<commit_before><?php

namespace Linkstreet\LaravelSms\Adapters\Kap;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use Illuminate\Support\Facades\Config;
use Linkstreet\LaravelSms\Adapters\BaseAdapter;
use Linkstreet\LaravelSms\Contracts\AdapterInterface;
use Linkstreet\LaravelSms\Exceptions\AdapterException;

/**
 * KapAdapter
 */
class KapAdapter extends BaseAdapter implements AdapterInterface
{
    /**
     * Create a instance of Kap Adapter
     *
     * @param array|null configuration for KAP adapter
     */
    public function __construct($config = null)
    {
        $this->config = $this->requiredConfig($config);
        $this->setClient(new Client());
    }

    /**
     * {@inheritdoc}
     */
    public function send($devices, $message)
    {
        $this->response = $this->client->send($this->buildRequest(), $this->buildOptions($devices, $message));
        return new KapResponse($devices, $this->response);
    }

    /**
     * Build Guzzle request object
     *
     * @return Request
     */
    private function buildRequest()
    {
        return new Request('POST', 'http://api.kapsystem.com/api/v3/sendsms/json');
    }

    /**
     * Build Guzzle query options with json payload
     *
     * @param DeviceCollection $devices
     * @param Message $message
     * @return array
     */
    private function buildOptions($devices, $message)
    {
        $recipients = [];

        foreach ($devices as $device) {
            $recipients[]['gsm'] = $device->getNumber();
        }

        return [
            'debug' => false,
            'timeout' => 10,
            'json' => [
                'authentication' => [
                    'username' => $this->config['username'],
                    'password' => $this->config['password']
                ],
                'messages' => [
                    [
                        'sender' => $this->config['sender'],
                        'text' => $message->getMessage(),
                        'recipients' => $recipients
                    ]
                ]
            ]<commit_msg>TASK: Configure header to aid sending UTF-8 messages<commit_after><?php

namespace Linkstreet\LaravelSms\Adapters\Kap;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use Illuminate\Support\Facades\Config;
use Linkstreet\LaravelSms\Adapters\BaseAdapter;
use Linkstreet\LaravelSms\Contracts\AdapterInterface;
use Linkstreet\LaravelSms\Exceptions\AdapterException;

/**
 * KapAdapter
 */
class KapAdapter extends BaseAdapter implements AdapterInterface
{
    /**
     * Create a instance of Kap Adapter
     *
     * @param array|null configuration for KAP adapter
     */
    public function __construct($config = null)
    {
        $this->config = $this->requiredConfig($config);
        $this->setClient(new Client());
    }

    /**
     * {@inheritdoc}
     */
    public function send($devices, $message)
    {
        $this->response = $this->client->send($this->buildRequest(), $this->buildOptions($devices, $message));
        return new KapResponse($devices, $this->response);
    }

    /**
     * Build Guzzle request object
     *
     * @return Request
     */
    private function buildRequest()
    {
        return new Request('POST', 'http://api.kapsystem.com/api/v3/sendsms/json');
    }

    /**
     * Build Guzzle query options with json payload
     *
     * @param DeviceCollection $devices
     * @param Message $message
     * @return array
     */
    private function buildOptions($devices, $message)
    {
        $recipients = [];

        foreach ($devices as $device) {
            $recipients[]['gsm'] = $device->getNumber();
        }

        return [
            'debug' => false,
            'timeout' => 10,
            'headers' => [
                'Content-Encoding' => 'UTF-8'
            ],
            'json' => [
                'authentication' => [
                    'username' => $this->config['username'],
                    'password' => $this->config['password']
                ],
                'messages' => [
                    [
                        'sender' => $this->config['sender'],
                        'text' => $message->getMessage(),
                        'datacoding' => 8,
                        'recipients' => $recipients
                    ]
                ]
            ]
{'fraction_non_alphanumeric': 0.13373161764705882, 'fraction_numerical': 0.002527573529411765, 'mean_word_length': 1.8657011191573403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3807290', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1166, 'n_words': 236}