2017 © Pedro Peláez
 

symfony-bundle hawk-api-bundle

Bundle for symfony based on post hawk api

image

post-hawk/hawk-api-bundle

Bundle for symfony based on post hawk api

  • Wednesday, July 27, 2016
  • by Slavenin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 86 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

HawkApiBundle

bundle for symfony based on post hawk api, (*1)

Установка:

composer require post-hawk/hawk-api-bundle dev-master

Для windows:, (*2)

cd path/to/project
mklink /J web\bundles\hawkapi vendor\post-hawk\hawk-api\Resources\public\

Для unix:, (*3)

cd path/to/project
ln -s web\bundles\hawkapi vendor\post-hawk\hawk-api\Resources\public\

Кофигурация:

//app/AppKernel.php
$bundles = array(
    ...
    new Hawk\ApiBundle\HawkApiBundle(),
);
#app/config/config.yml
hawk_api:
    client:
        host: client_addres #ip или домен
        port: 7777 #порт, который слушает клиент
        key: 'ваш апи ключ'
#app/config/routing.yml
hawk:
    resource: '@HawkApiBundle/Controller/'
    prefix:   /hawk
<script src="{{ asset('/bundles/hawkapi/js/hawk_api.js') }}"></script>

Использование

$api = $this->get('hawk_api.api')->getApi();
$api
    ->registerUser($id)
    ->getToken($id, $this->getApi()->getSalt())
    ->execute()
    ->getResult('getToken')
;

или так:, (*4)

$msg = new Message();
$msg
    ->setFrom('mail_demon')
    ->setTo($this->getUser())
    ->setText(['msg' => 'test'])
    ->setEvent('new_push')
;

$gMessage = new GroupMessage();
$gMessage
    ->setFrom('mail_demon')
    ->setGroups(['groups'])
    ->setText(['msg' => 'test'])
    ->setEvent('event')
;

$this
    ->container
    ->get('event_dispatcher')
    ->dispatch(Message::NEW_MESSAGE, $msg)
    ->getResult() //HawkApi
    ->getResult('sendMessage')
;

$this
    ->container
    ->get('event_dispatcher')
    ->dispatch(GroupMessage::NEW_MESSAGE, $gMessage)
    ->getResult() //HawkApi
    ->getResult('sendGroupMessage')
;

$.post(Routing.generate('hawk_token'), {}, function (data) {
    if(data.errors === false)
    {
        HAWK_API.init({
            user_id: data.result.id,
            token: data.result.token,
            url: data.result.ws,
            debug: true
        });

        HAWK_API.unbind_handler('new_push');
        HAWK_API.bind_handler('new_push', function(e, msg){
            if(msg.from === 'hawk_client')
            {
                return;
            }

            //делаем что-нибудь
        });
    }
    else
    {
        if(data.errors !== 'no_user')
        {
            console.error(data.errors);
        }
    }
});

Про методы, доступные для использования вы можете прочесть в документации, (*5)

The Versions

27/07 2016

dev-master

9999999-dev https://github.com/postHawk/HawkApiBundle

Bundle for symfony based on post hawk api

  Sources   Download

MIT

The Requires

 

by Barulin Maxim

api post hawk

27/07 2016

1.0.3

1.0.3.0 https://github.com/postHawk/HawkApiBundle

Bundle for symfony based on post hawk api

  Sources   Download

MIT

The Requires

 

by Barulin Maxim

api post hawk

16/06 2016

1.0.2

1.0.2.0 https://github.com/postHawk/HawkApiBundle

Bundle for symfony based on post hawk api

  Sources   Download

MIT

The Requires

 

by Barulin Maxim

api post hawk

14/06 2016

1.0.1

1.0.1.0 https://github.com/postHawk/HawkApiBundle

Bundle for symfony based on post hawk api

  Sources   Download

MIT

The Requires

 

by Barulin Maxim

api post hawk

11/05 2016

1.0.0

1.0.0.0 https://github.com/postHawk/HawkApiBundle

Bundle for symfony based on post hawk api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Barulin Maxim

api post hawk