Difference between revisions of "Application Developers Example"

From Ace Stream Wiki
Jump to: navigation, search
(Работа с движком)
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
==Общая информация==
+
==Common information==
Данный пример пошагово описывает все необходимые шаги для настройки работы стороннего приложения с движком Ace Stream.
+
This example is a step-by-step description of all necessary steps to set up work of a third-party application with Ace Stream engine.
  
Во всех запросах для примера будут использоваться такие переменные:
+
All requests for the example will use the following variables:
* ключ продукта <tt>kjYX790gTytRaXV04IvC-xZH3A18sj5b1Tf3I-J5XVS1xsj-j0797KwxxLpBl26HPvWMm</tt>
+
* product key <tt>kjYX790gTytRaXV04IvC-xZH3A18sj5b1Tf3I-J5XVS1xsj-j0797KwxxLpBl26HPvWMm</tt>
 
* API Key: <tt>94d585bda4883a40d969d723adcaba36033e61d8</tt>
 
* API Key: <tt>94d585bda4883a40d969d723adcaba36033e61d8</tt>
 
* API Secret: <tt>b5dbd62b494664f5bfa9</tt>
 
* API Secret: <tt>b5dbd62b494664f5bfa9</tt>
  
==Регистрация разработчика и получение ключа продукта==
+
These data are presented only to illustrate the example, will not work in a "real life".
Для начала Вам необходимо зарегистрироваться в системе Ace Stream как разработчик приложений, после чего Вы сможете зарегистрировать свое приложение и получить для него ключ продукта. Как это сделать, описано в разделе [[Developers|Разработчики]].
 
  
==Работа с движком==
+
==Developer's registration and getting a product key==
Работать с Вашим приложением будет только движок, для которого активирована опция NoADs.
+
To start you have to register in Ace Stream system as application developer. After that you will be able to register your application and get the product key for it. How to do this is described in a section [[Developers/en|Developers]].
  
Если эта опция не активирована, то на любую попытку воспроизвести что-либо движок будет возвращать ошибку с таким текстом:
+
==Working with the engine==
No ADs option must be activated to use this product
+
By default only the engine with activated NoADs option will work with your application.
  
Для начала Вашему приложению необходимо проверить, активирована ли опция NoADs на движке.
+
If this option is not activated, the engine will return an error with the following text to any attempt to play anything:
 +
"No ADs option must be activated to use this product"
  
==Проверка активации опции NoADs на движке==
+
Example of such an error according to [[Engine_API/en|Engine API]]:
Метод [[Engine_Service_API#get_services|get_services]] сервисного API движка позволяет узнать, какие опции активированы на движке. Для этого нужно отправить HTTP GET запрос на движок:
+
<nowiki>>> START PID 94c2fd8fb9bc8f2fc71a2cbe9d4b866f227a0209 0
 +
<< STATE 1
 +
<< STATUS main:starting
 +
<< STATE 0
 +
<< STATUS main:idle
 +
<< STATUS main:err;0;No ADs option must be activated to use this product</nowiki>
 +
 
 +
So, to start working your application has to check whether NoADs option is activated on the engine.
 +
 
 +
==Checking activation of NoADs option on the engine==
 +
Method [[Engine_Service_API/en#get_services|get_services]] of service engine API allows to find out what options are activated on the engine. To do this you have to send HTTP GET request to the engine:
 
  <nowiki>http://localhost:6878/webui/api/service?method=get_services&product_key=kjYX790gTytRaXV04IvC</nowiki>
 
  <nowiki>http://localhost:6878/webui/api/service?method=get_services&product_key=kjYX790gTytRaXV04IvC</nowiki>
  
В запросе нужно передать публичную часть ключа продукта (kjYX790gTytRaXV04IvC) в параметре <tt>product_key</tt>.
+
In the request you have to send a public part of the product key (kjYX790gTytRaXV04IvC) in parameter <tt>product_key</tt>.
  
'''Варианты ответов'''
+
'''Response options'''
  
*если возникла ошибка (нужно выслать нам логи движка)
+
*if an error was occured (this should not happen, so in this case, please, send us engine's logs)
{"status": "error", "error": "error description"}
+
<nowiki>{"status": "error", "error": "error description"}</nowiki>
  
*если на движке не активирована опция NoADs
+
*if NoADs option is not activated on the engine
  <nowiki>{
+
  <nowiki>{"status": "ok", "services":[]}</nowiki>
“status”: “ok”,
 
“services”:[]
 
}</nowiki>
 
  
*если на движке активирована опция NoADs
+
*if NoADs option is activated on the engine
 
  <nowiki>{
 
  <nowiki>{
“status”: “ok”,
+
"status": "ok",
“services”:
+
"services":
 
[
 
[
 
   {
 
   {
Line 46: Line 53:
 
     "valid_to": 1411671946,
 
     "valid_to": 1411671946,
 
     "trial": false,
 
     "trial": false,
     "description": "\u041e\u0442\u043a\u043b\
+
     "description": "\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u043b\u0430\u043c\u044b Ace Stream"
u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u043b\u0430\u043c\u044b Ace Stream"
 
 
   }
 
   }
 
]
 
]
 
}</nowiki>
 
}</nowiki>
  
В возвращаемом списке могут быть и другие опции, кроме NoADs. Для того, чтобы узнать, активирована ли конкретная опция, нужно пройтись по списку и проверять поле <tt>id</tt> каждого элемента.
+
There may be other options except NoADs in the returned list. To find out, whether a specific option is activated, you have to go through the list and check field <tt>id</tt> of each element (<tt>id</tt> of NoADs option - <tt>noAds</tt>).
 +
 
 +
If NoADs option is not activated, your application can activate it. To do this you have to follow these steps:
 +
* create a new user key (method [[Reseller_API/en#createUserKey|createUserKey]] of API for resellers)
 +
* activate NoADs option for this user key (method [[Reseller_API/en#activateService|activateService]] of API for resellers)
 +
* load user key to the engine (method [[Engine_Service_API/en#load_extension|extension]] of service engine API)
 +
 
 +
Task of user key is to identify user of your application in Ace Stream system without the need for the user to register in our system,.
 +
 
 +
If you are able to bind user key, created using developer API, with a specific user of your application, we recommend you to do that. In this case, if necessary, for example, re-activate an additional option for the user you will not need to create a new user key. It will be enough to activate the option for existing one.
  
Если опция NoADs не активирована, ее нужно активировать. Для этого нужно выполнить такие шаги:
 
* создать новый ключ пользователя (метод [[Reseller_API#createUserKey|createUserKey]] API для реселлеров)
 
* активировать опцию NoADs для этого ключа пользователя (метод [[Reseller_API#activateService|activateService]] API для реселлеров)
 
* загрузить ключ пользователя в движок (метод [[Engine_Service_API#load_extension|extension]] сервисного API движка)
 
  
Ниже эти шаги описаны более подробно.
+
More detailed steps about creating a new user key and activation are below.
  
==Создание ключа пользователя==
+
==Creating user key==
Запрос:
+
Method [[Developer_API/en#createUserKey|createUserKey ]] of developer's API is used.
  <nowiki>https://api.acestream.net/reseller?method=createUserKey &crarr;
+
 
 +
Request:
 +
  <nowiki>https://api.acestream.net/developer?method=createUserKey &crarr;
 
     &api_key=94d585bda4883a40d969d723adcaba36033e61d8 &crarr;
 
     &api_key=94d585bda4883a40d969d723adcaba36033e61d8 &crarr;
 
     &api_version=1.0 &crarr;
 
     &api_version=1.0 &crarr;
Line 69: Line 82:
 
     &sign=fcf118b246892d80111de2661b79edb27ff48f08</nowiki>
 
     &sign=fcf118b246892d80111de2661b79edb27ff48f08</nowiki>
  
Ответ:
+
Response:
 
  <nowiki>{
 
  <nowiki>{
 
   "userKey":"84acee3a529bafaa65215af6f86d03fe38020b2d",
 
   "userKey":"84acee3a529bafaa65215af6f86d03fe38020b2d",
Line 83: Line 96:
 
}</nowiki>
 
}</nowiki>
  
==Активация==
+
==Activation==
Запрос:
+
Method [[Developer_API/en#activateService|activateService]] of developer's API is used.
  <nowiki>https://api.acestream.net/reseller?service=noAds &crarr;
+
 
    &period=m1 &crarr;
+
In the example NoADs option is activated for 1 month.
    &user_key=84acee3a529bafaa65215af6f86d03fe38020b2d &crarr;
+
 
    &method=activateService &crarr;
+
Request:
 +
  <nowiki>https://api.acestream.net/developer?method=activateService &crarr;
 
     &api_key=94d585bda4883a40d969d723adcaba36033e61d8 &crarr;
 
     &api_key=94d585bda4883a40d969d723adcaba36033e61d8 &crarr;
 
     &api_version=1.0 &crarr;
 
     &api_version=1.0 &crarr;
 
     &product=kjYX790gTytRaXV04IvC &crarr;
 
     &product=kjYX790gTytRaXV04IvC &crarr;
 +
    &user_key=84acee3a529bafaa65215af6f86d03fe38020b2d &crarr;
 +
    &service=noAds &crarr;
 +
    &period=m1 &crarr;
 
     &sign=2f55622fb9c21af5b950c210774ea34247d1a073</nowiki>
 
     &sign=2f55622fb9c21af5b950c210774ea34247d1a073</nowiki>
  
Ответ:
+
Response:
 
  <nowiki>{"validFrom":1401204680,"validTo":1403796680}</nowiki>
 
  <nowiki>{"validFrom":1401204680,"validTo":1403796680}</nowiki>
  
==Загрузка ключа в движок==
+
==Loading key to the engine==
Запрос:
+
Method [[Engine_Service_API/en#load_extension|load_extension]] of service engine API is used.
 +
 
 +
Request:
 
  <nowiki>POST /webui/api/service?method=load_extension HTTP/1.1
 
  <nowiki>POST /webui/api/service?method=load_extension HTTP/1.1
 
Host: localhost
 
Host: localhost
Line 112: Line 131:
 
L6OBnbrMrXSsjxahdQM2yFWRE\/gG91mEB6JNN0z99oswOiMghx0=</nowiki>
 
L6OBnbrMrXSsjxahdQM2yFWRE\/gG91mEB6JNN0z99oswOiMghx0=</nowiki>
  
Ответ:
+
Response:
 
  <nowiki>HTTP/1.0 200 OK
 
  <nowiki>HTTP/1.0 200 OK
 
Server: BaseHTTP/0.3 Python/2.7.2
 
Server: BaseHTTP/0.3 Python/2.7.2

Latest revision as of 12:18, 6 September 2017

Common information

This example is a step-by-step description of all necessary steps to set up work of a third-party application with Ace Stream engine.

All requests for the example will use the following variables:

  • product key kjYX790gTytRaXV04IvC-xZH3A18sj5b1Tf3I-J5XVS1xsj-j0797KwxxLpBl26HPvWMm
  • API Key: 94d585bda4883a40d969d723adcaba36033e61d8
  • API Secret: b5dbd62b494664f5bfa9

These data are presented only to illustrate the example, will not work in a "real life".

Developer's registration and getting a product key

To start you have to register in Ace Stream system as application developer. After that you will be able to register your application and get the product key for it. How to do this is described in a section Developers.

Working with the engine

By default only the engine with activated NoADs option will work with your application.

If this option is not activated, the engine will return an error with the following text to any attempt to play anything: "No ADs option must be activated to use this product"

Example of such an error according to Engine API:

>> START PID 94c2fd8fb9bc8f2fc71a2cbe9d4b866f227a0209 0
<< STATE 1
<< STATUS main:starting
<< STATE 0
<< STATUS main:idle
<< STATUS main:err;0;No ADs option must be activated to use this product

So, to start working your application has to check whether NoADs option is activated on the engine.

Checking activation of NoADs option on the engine

Method get_services of service engine API allows to find out what options are activated on the engine. To do this you have to send HTTP GET request to the engine:

http://localhost:6878/webui/api/service?method=get_services&product_key=kjYX790gTytRaXV04IvC

In the request you have to send a public part of the product key (kjYX790gTytRaXV04IvC) in parameter product_key.

Response options

  • if an error was occured (this should not happen, so in this case, please, send us engine's logs)
{"status": "error", "error": "error description"}
  • if NoADs option is not activated on the engine
{"status": "ok", "services":[]}
  • if NoADs option is activated on the engine
{
"status": "ok",
"services":
[
  {
    "id": "noAds",
    "name": "No ADs",
    "valid_from": 1376939146,
    "valid_to": 1411671946,
    "trial": false,
    "description": "\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u043b\u0430\u043c\u044b Ace Stream"
  }
]
}

There may be other options except NoADs in the returned list. To find out, whether a specific option is activated, you have to go through the list and check field id of each element (id of NoADs option - noAds).

If NoADs option is not activated, your application can activate it. To do this you have to follow these steps:

  • create a new user key (method createUserKey of API for resellers)
  • activate NoADs option for this user key (method activateService of API for resellers)
  • load user key to the engine (method extension of service engine API)

Task of user key is to identify user of your application in Ace Stream system without the need for the user to register in our system,.

If you are able to bind user key, created using developer API, with a specific user of your application, we recommend you to do that. In this case, if necessary, for example, re-activate an additional option for the user you will not need to create a new user key. It will be enough to activate the option for existing one.


More detailed steps about creating a new user key and activation are below.

Creating user key

Method createUserKey of developer's API is used.

Request:

https://api.acestream.net/developer?method=createUserKey ↵
    &api_key=94d585bda4883a40d969d723adcaba36033e61d8 ↵
    &api_version=1.0 ↵
    &product=kjYX790gTytRaXV04IvC ↵
    &sign=fcf118b246892d80111de2661b79edb27ff48f08

Response:

{
  "userKey":"84acee3a529bafaa65215af6f86d03fe38020b2d",
  "extension":"F5T6L+X\/TnhqoXP\/TyzlaaEmAT7uu97HHvJZ8u7 ↵
ShbGBf1w4OAgRhP7Hj0+DGzjK2AolsnfkMgOSFq4qYOlgQdWR3nRGJCq ↵
bX8QxqRC\/zbNu+3RerhylcdqvVEuAuWSuEQW0\/tgaqKaIVrfVSug\/ ↵
SVrBTLtXea\/4FLqXzz8lTYbv90p\/Nmw6jZcpaSaf4ISJQo9d+NTJ15 ↵
cz0emN+FtdABjIZNz91NVEWWyzMNl5iorzCWS8lYrdRQgT\/psdbf3N6 ↵
T2wfozL2b98yOkGH53eG4uc5wX+75xluvKwnKK32MJ7uDPZpDLHxTNc9 ↵
2GCXKEloLFl+IyC91gghJpry6erUN3g9musH9CKvk4TZoZ+RTQINXlxr ↵
+IDklEnL6OBnbrMrXSsjxahdQM2yFWRE\/gG91mEB6JNN0z99oswOiMg ↵
hx0="
}

Activation

Method activateService of developer's API is used.

In the example NoADs option is activated for 1 month.

Request:

https://api.acestream.net/developer?method=activateService ↵
    &api_key=94d585bda4883a40d969d723adcaba36033e61d8 ↵
    &api_version=1.0 ↵
    &product=kjYX790gTytRaXV04IvC ↵
    &user_key=84acee3a529bafaa65215af6f86d03fe38020b2d ↵
    &service=noAds ↵
    &period=m1 ↵
    &sign=2f55622fb9c21af5b950c210774ea34247d1a073

Response:

{"validFrom":1401204680,"validTo":1403796680}

Loading key to the engine

Method load_extension of service engine API is used.

Request:

POST /webui/api/service?method=load_extension HTTP/1.1
Host: localhost
Content-Type: text/plain
Content-Length: 437

F5T6L+X\/TnhqoXP\/TyzlaaEmAT7uu97HHvJZ8u7ShbGBf1w4OAgRhP7Hj0+DGz ↵
jK2AolsnfkMgOSFq4qYOlgQdWR3nRGJCqbX8QxqRC\/zbNu+3RerhylcdqvVEuAu ↵
WSuEQW0\/tgaqKaIVrfVSug\/SVrBTLtXea\/4FLqXzz8lTYbv90p\/Nmw6jZcpa ↵
Saf4ISJQo9d+NTJ15cz0emN+FtdABjIZNz91NVEWWyzMNl5iorzCWS8lYrdRQgT\ ↵
/psdbf3N6T2wfozL2b98yOkGH53eG4uc5wX+75xluvKwnKK32MJ7uDPZpDLHxTNc ↵
92GCXKEloLFl+IyC91gghJpry6erUN3g9musH9CKvk4TZoZ+RTQINXlxr+IDklEn ↵
L6OBnbrMrXSsjxahdQM2yFWRE\/gG91mEB6JNN0z99oswOiMghx0=

Response:

HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.2
Date: Tue, 27 May 2014 15:46:22 GMT
Content-Type: application/json
Content-Length: 16

{"status": "ok"}