Giter Club home page Giter Club logo

karix-php's Introduction

karix-php

Build Status Coverage Status

Karix API lets you interact with the Karix platform using an omnichannel messaging API. It also allows you to query your account, set up webhooks and buy phone numbers.

This PHP package is automatically generated by the Swagger Codegen project:

  • API version: 2.0
  • Package version: 2.0.0
  • Build package: io.swagger.codegen.languages.PhpClientCodegen

Requirements

PHP 5.6 and later

Installation & Usage

Composer

To install the bindings via Composer, add the following to composer.json:

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/karixtech/karix-php.git"
    }
  ],
  "require": {
    "karixtech/karix-php": "2.0.0"
  }
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

    require_once('/path/to/karix-php/vendor/autoload.php');

Tests

To run the unit tests:

composer install
./vendor/bin/phpunit

Getting Started

Please follow the installation procedure and then run the following:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure HTTP basic authorization: basicAuth
$config = Karix\Configuration::getDefaultConfiguration()
    ->setUsername('ACCOUNT_ID')
    ->setPassword('ACCOUNT_TOKEN');

$apiInstance = new Karix\Api\MessageApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
date_default_timezone_set('UTC');
// Create Message object
$message = (new \Karix\Model\CreateMessage())
    ->setChannel("sms") //Or use "whatsapp"
    ->setSource("+1XXX2321XXX")
    ->setDestination(["+1XXX8323XXX", "+1XXX3234XXX"])
    ->setContent(["text" => "Sent from Karix PHP SDK"]);

try {
    $result = $apiInstance->sendMessage($message);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling MessageApi->sendMessage: ', $e->getMessage(), PHP_EOL;
}
?>

Documentation for API Endpoints

All URIs are relative to https://api.karix.io

Class Method HTTP request Description
AccountsApi createSubaccount POST /account/ Create a new subaccount
AccountsApi getSubaccount GET /account/ Get a list of accounts
AccountsApi getSubaccountById GET /account/{uid}/ Get details of an account
AccountsApi patchSubaccount PATCH /account/{uid}/ Edit an account
MessageApi getMessage GET /message/ Get list of messages sent or received
MessageApi getMessageById GET /message/{uid}/ Get message details by id.
MessageApi sendMessage POST /message/ Send a message to a list of destinations
NumberApi deleteNumber DELETE /number/{num}/ Unrent number from your account
NumberApi getNumber GET /number/ Get details of all phone numbers linked to your account.
NumberApi getNumberDetails GET /number/{num}/ Get details of a number
NumberApi patchNumberDetails PATCH /number/{num}/ Edit phone number belonging to your account
NumberApi rentNumber POST /number/ Rent a phone number
NumberSearchApi searchNumber GET /numbersearch/ Query for phone numbers in our inventory.
WebhookApi createWebhook POST /webhook/ Create webhooks to receive Message
WebhookApi deleteWebhookById DELETE /webhook/{uid}/ Delete a webhook by ID
WebhookApi getWebhook GET /webhook/ Get a list of your webhooks
WebhookApi getWebhookById GET /webhook/{uid}/ Get a webhook by ID
WebhookApi patchWebhook PATCH /webhook/{uid}/ Edit a webhook

Documentation For Models

Documentation For Authorization

basicAuth

  • Type: HTTP basic authentication

Author

[email protected]

karix-php's People

Contributors

tsudot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

karix-php's Issues

Class 'Brick\Math\BigDecimal' not found

I am using laravel and when I send sms I got this error
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'Brick\Math\BigDecimal' not found

The SMS message sent but with internal server error 500 so this make problems with my API client

I tried to fix it by myself but I did not find the class Brick\Math\BigDecimal in this class ObjectSerializer here is the link to the line which I mean https://github.com/karixtech/karix-php/blob/v2/lib/ObjectSerializer.php#L32

and the problem occurs at this line of code https://github.com/karixtech/karix-php/blob/v2/lib/ObjectSerializer.php#L268

I hope I get solution of my problem!

Method sendMessage() throws a 500 error

Hi, I'm using karix-php with cakephp framework 3.4.10 version and when try to send an sms the method throws an error, even though sms is arrived.

Error: [Exception] DateTime::__construct(): Failed to parse time string (2018-09-03T09:28:07.140475154Z) at position 0 (2): The timezone could not be found in the database

Here is a logs:

2018-09-03 09:27:54 Error: [Exception] DateTime::__construct(): Failed to parse time string (2018-09-03T09:28:07.140475154Z) at position 0 (2): The timezone could not be found in the database
Request URL: /users/invite
Stack Trace:
#0 API_V2/vendor/karixtech/karix-php/lib/ObjectSerializer.php(261): DateTime->__construct('2018-09-03T09:2...')
#1 API_V2/vendor/karixtech/karix-php/lib/ObjectSerializer.php(311): Swagger\Client\ObjectSerializer::deserialize('2018-09-03T09:2...', '\DateTime', NULL)
#2 API_V2/vendor/karixtech/karix-php/lib/ObjectSerializer.php(247): Swagger\Client\ObjectSerializer::deserialize(Object(stdClass), '\Swagger\Client...', NULL)
#3 API_V2/vendor/karixtech/karix-php/lib/ObjectSerializer.php(311): Swagger\Client\ObjectSerializer::deserialize(Array, '\Swagger\Client...', NULL)
#4 API_V2/vendor/karixtech/karix-php/lib/Api/MessageApi.php(775): Swagger\Client\ObjectSerializer::deserialize(Object(stdClass), '\Swagger\Client...', Array)
#5 API_V2/vendor/karixtech/karix-php/lib/Api/MessageApi.php(715): Swagger\Client\Api\MessageApi->sendMessageWithHttpInfo('1.0', Object(Swagger\Client\Model\CreateMessage))
#6 API_V2/src/Controller/Component/SmsProviders/KarixProvider.php(83): Swagger\Client\Api\MessageApi->sendMessage('1.0', Object(Swagger\Client\Model\CreateMessage))
#7 API_V2/src/Controller/Component/SmsComponent.php(52): App\Controller\Component\SmsProviders\KarixProvider->sendMessage('+380675872686', 'New user i...')
#8 API_V2/plugins/Invitations/src/Controller/AppController.php(56): App\Controller\Component\SmsComponent->sendMessage('+380675872686', 'New user i...')
#9 API_V2/vendor/cakephp/cakephp/src/Controller/Controller.php(440): Invitations\Controller\AppController->inviteBulk()
#10 API_V2/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(119): Cake\Controller\Controller->invokeAction()
#11 API_V2/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(93): Cake\Http\ActionDispatcher->_invoke(Object(Invitations\Controller\AppController))
#12 API_V2/vendor/cakephp/cakephp/src/Http/BaseApplication.php(78): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#13 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#14 API_V2/src/Routing/Middleware/CorsMiddleware.php(32): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#15 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): App\Routing\Middleware\CorsMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#16 API_V2/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(59): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#17 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#18 API_V2/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#20 API_V2/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(92): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#21 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#22 API_V2/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php(52): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#23 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(65): DebugKit\Middleware\DebugKitMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#24 API_V2/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#25 API_V2/vendor/cakephp/cakephp/src/Http/Server.php(80): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#26 API_V2/webroot/index.php(37): Cake\Http\Server->run()
#27 {main}

Here is my class for sending messages (according to article https://blog.karix.io/how-to-send-an-sms-using-php-helper-library):

use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Http\Client;
use Swagger\Client\Api\MessageApi;
use Swagger\Client\Configuration;
use Swagger\Client\Model\CreateMessage;

/**
 * Class KarixProvider
 * @package App\Controller\Component\SmsProviders
 */
class KarixProvider implements SmsProviderInterface
{
    /**
     * Host url
     *
     * @var string
     */
    private $host = 'https://api.karix.io';

    /**
     * Version of a Karix API
     *
     * @var string
     */
    private $apiVersion = '1.0';

    /**
     * configuration for the Karix platform
     *
     * @var
     */
    private $config;

    /**
     * KarixProvider constructor.
     * @param $params
     */
    public function __construct($params)
    {
        $config = new Configuration();
        $config->setUsername(Configure::read('SmsProviders.Karix.AUTH_ID'));
        $config->setPassword(Configure::read('SmsProviders.Karix.AUTH_TOKEN'));
        return $this->config = $config;
    }

    /**
     * Create instance of Message object
     *
     * @return MessageApi
     */
    public function apiInstance()
    {
        return new MessageApi(
        // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
        // This is optional, `GuzzleHttp\Client` will be used as default.
            new \GuzzleHttp\Client(),
            $this->config);
    }

    /**
     * Send message to recipient
     *
     * @param $recipient
     * @param $text
     * @return \Cake\Network\Response
     */
    public function sendMessage($recipient, $text)
    {
        $message = new CreateMessage();

        date_default_timezone_set('UTC');

        $message->setDestination([$recipient]);
        $message->setSource(Configure::read('SmsProviders.Karix.SOURCE_NUMBER'));
        $message->setText($text);

        try {
            $result = $this->apiInstance()->sendMessage($this->apiVersion, $message);
            return response(__("success"));
        } catch (Exception $e) {
            return response('Exception when calling MessageApi->createMessage: ' .
                $e->getMessage() . PHP_EOL, 400);
        }
    }

Class 'Karix\Configuration' not found

Got Class 'Karix\Configuration' not found error in laravel and when I try to install using
composer require "karixtech/karix-php" package folder is empty under vendor folder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.