InSales API - Asset — различия между версиями

Материал из Insales Wiki
Перейти к: навигация, поиск
(Новая страница: «=Добавление асета= Запрос: POST /admin/themes/#{theme_id}/assets.xml <pre> <?xml version="1.0" encoding="UTF-8"?> <asset> <name>product.m…»)
 
Строка 15: Строка 15:
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<template>
+
<asset>
 
   <account-id type="integer">10</account-id>
 
   <account-id type="integer">10</account-id>
   <created-at type="timestamp">2013-06-13 19:14:04 +0400</created-at>
+
   <id type="integer">1460299</id>
  <id type="integer">1460298</id>
 
  <inner-content-type>text/x-liquid</inner-content-type>
 
  <inner-file-name>product.my_template.liquid</inner-file-name>
 
  <inner-file-size type="integer">38</inner-file-size>
 
  <inner-synced-to-s3 type="boolean">false</inner-synced-to-s3>
 
  <name>Товар: my_template</name>
 
  <parent-id type="integer" nil="true"/>
 
  <svg-error-message nil="true"/>
 
 
   <theme-id type="integer">14522</theme-id>
 
   <theme-id type="integer">14522</theme-id>
   <updated-at type="timestamp">2013-06-13 19:14:04 +0400</updated-at>
+
   <type>Asset::Template</type>
</template>
+
  <name>product.my_template.liquid</name>
 +
  <content-type>text/x-liquid</content-type>
 +
  <file-size type="integer">38</file-size>
 +
</asset>
 
</pre>
 
</pre>
  
 +
=Список асетов=
 +
 +
Запрос: GET /admin/themes/#{theme_id}/assets.xml
 +
 +
Ответ:
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<assets type="array">
 +
  <asset>
 +
    <account-id type="integer">10</account-id>
 +
    <id type="integer">1460299</id>
 +
    <theme-id type="integer">14522</theme-id>
 +
    <type>Asset::Template</type>
 +
    <name>product.my_template.liquid</name>
 +
    <content-type>text/x-liquid</content-type>
 +
    <file-size type="integer">38</file-size>
 +
  </asset>
 +
  <asset>
 +
    <account-id type="integer">10</account-id>
 +
    <id type="integer">1460010</id>
 +
    <theme-id type="integer">14522</theme-id>
 +
    <type>Asset::Media</type>
 +
    <name>style.css</name>
 +
    <content-type>text/css</content-type>
 +
    <file-size type="integer">34438</file-size>
 +
    <asset_url type="string">/assets/1/6330/14522/style.css</asset_url>
 +
  </asset>
 +
</assets>
 +
</pre>
  
=Получить данные об асете=
+
=Получение асета=
  
 
Запрос: GET /admin/themes/#{theme_id}/assets/#{id}.xml
 
Запрос: GET /admin/themes/#{theme_id}/assets/#{id}.xml
  
 
Ответ:
 
Ответ:
 +
 +
Если запрошен текстовый файл
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<template>
+
<asset>
 
   <account-id type="integer">10</account-id>
 
   <account-id type="integer">10</account-id>
   <created-at type="timestamp">2013-06-13 19:14:04 +0400</created-at>
+
   <id type="integer">1460299</id>
  <id type="integer">1460298</id>
 
  <inner-content-type>text/x-liquid</inner-content-type>
 
  <inner-file-name>product.my_template.liquid</inner-file-name>
 
  <inner-file-size type="integer">38</inner-file-size>
 
  <inner-synced-to-s3 type="boolean">false</inner-synced-to-s3>
 
  <name>Товар: my_template</name>
 
  <parent-id type="integer" nil="true"/>
 
  <svg-error-message nil="true"/>
 
 
   <theme-id type="integer">14522</theme-id>
 
   <theme-id type="integer">14522</theme-id>
   <updated-at type="timestamp">2013-06-13 19:14:04 +0400</updated-at>
+
   <type>Asset::Template</type>
</template>
+
  <name>product.my_template.liquid</name>
 +
  <content-type>text/x-liquid</content-type>
 +
  <file-size type="integer">38</file-size>
 +
  <content type="string">template for product {{product.title}}</content>
 +
</asset>
 
</pre>
 
</pre>
  
=Загрузить асет=
+
Если запрошена картинка, то в ответ добавляется поле attachment с закодированным в Base64 содержимым файла.
 
 
Запрос: GET Запрос: POST /admin/themes/#{theme_id}/assets/#{id}/raw.xml
 
 
 
Ответ:
 
 
<pre>
 
<pre>
   Файл асета
+
<?xml version="1.0" encoding="UTF-8"?>
 +
<asset>
 +
   <account-id type="integer">10</account-id>
 +
  <id type="integer">1460005</id>
 +
  <theme-id type="integer">14522</theme-id>
 +
  <type>Asset::Media</type>
 +
  <name>arrows.png</name>
 +
  <content-type>image/png</content-type>
 +
  <file-size type="integer">1078</file-size>
 +
  <asset_url type="string">/assets/1/6330/14522/arrows.png</asset_url>
 +
  <attachment type="string">iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAGXRFWHRTb2Z0
 +
d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9i
 +
ZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2Vo
 +
aUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6
 +
bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2
 +
LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpS
 +
REYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJk
 +
Zi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIg
 +
eG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8i
 +
IHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5
 +
cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5j
 +
b20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRp
 +
ZDpFQ0I3MDhCMDIyMjA2ODExODA4MzlFOThFQ0ZFQjk2QyIgeG1wTU06RG9j
 +
dW1lbnRJRD0ieG1wLmRpZDoyNTlCMkVFMzJCRTYxMUUyQjY5MUZFN0UxNTJE
 +
QjNFRSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoyNTlCMkVFMjJCRTYx
 +
MUUyQjY5MUZFN0UxNTJEQjNFRSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQ
 +
aG90b3Nob3AgQ1M2IChNYWNpbnRvc2gpIj4gPHhtcE1NOkRlcml2ZWRGcm9t
 +
IHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QjQ5OUIwMzkzMzIwNjgxMTgw
 +
ODM5OEVDQzQ5MzgxQ0EiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6RUNC
 +
NzA4QjAyMjIwNjgxMTgwODM5RTk4RUNGRUI5NkMiLz4gPC9yZGY6RGVzY3Jp
 +
cHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9
 +
InIiPz4qOKNNAAAAZElEQVR42mJcuGABAxRwAfFUKDsbiL+BGCxQAU0gXgXE
 +
OlC+CRBHAPFVJiCRAMRnkCQZoOxTIDmQCQugGCtgYiAAYFZ8BeL/aBgklsAE
 +
Nd4c5CAkjdehYgtgvrgCxGbYvAkQYABadBdFxtx8lAAAAABJRU5ErkJggg==
 +
</attachment>
 +
</asset>
 
</pre>
 
</pre>
  
Строка 78: Строка 131:
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<template>
+
<asset>
 
   <account-id type="integer">10</account-id>
 
   <account-id type="integer">10</account-id>
   <created-at type="timestamp">2013-06-13 19:14:04 +0400</created-at>
+
   <id type="integer">1460299</id>
  <id type="integer">1460298</id>
 
  <inner-content-type>text/x-liquid</inner-content-type>
 
  <inner-file-name>product.my_template.liquid</inner-file-name>
 
  <inner-file-size type="integer">46</inner-file-size>
 
  <inner-synced-to-s3 type="boolean">false</inner-synced-to-s3>
 
  <name>Товар: my_template</name>
 
  <parent-id type="integer" nil="true"/>
 
  <svg-error-message nil="true"/>
 
 
   <theme-id type="integer">14522</theme-id>
 
   <theme-id type="integer">14522</theme-id>
   <updated-at type="timestamp">2013-06-13 19:33:12 +0400</updated-at>
+
   <type>Asset::Template</type>
</template>
+
  <name>product.my_template.liquid</name>
 +
  <content-type>text/x-liquid</content-type>
 +
  <file-size type="integer">46</file-size>
 +
</asset>
 
</pre>
 
</pre>
  
Строка 108: Строка 156:
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<template>
+
<asset>
 
   <account-id type="integer">10</account-id>
 
   <account-id type="integer">10</account-id>
   <created-at type="timestamp">2013-06-13 19:14:04 +0400</created-at>
+
   <id type="integer">1460299</id>
  <id type="integer">1460298</id>
 
  <inner-content-type>text/x-liquid</inner-content-type>
 
  <inner-file-name>product.my_template.liquid</inner-file-name>
 
  <inner-file-size type="integer">46</inner-file-size>
 
  <inner-synced-to-s3 type="boolean">false</inner-synced-to-s3>
 
  <name>Товар: my_template</name>
 
  <parent-id type="integer" nil="true"/>
 
  <svg-error-message nil="true"/>
 
 
   <theme-id type="integer">14522</theme-id>
 
   <theme-id type="integer">14522</theme-id>
   <updated-at type="timestamp">2013-06-13 19:33:12 +0400</updated-at>
+
   <type>Asset::Template</type>
</template>
+
  <name>product.my_amazing_template.liquid</name>
 +
  <content-type>text/x-liquid</content-type>
 +
  <file-size type="integer">46</file-size>
 +
</asset>
 
</pre>
 
</pre>
  

Версия 13:04, 14 июня 2013

Добавление асета

Запрос: POST /admin/themes/#{theme_id}/assets.xml

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <name>product.my_template.liquid</name>
  <content><![CDATA[template for product {{product.title}}]]></content>
  <type>Asset::Template</type>
</asset>

Ответ:

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <account-id type="integer">10</account-id>
  <id type="integer">1460299</id>
  <theme-id type="integer">14522</theme-id>
  <type>Asset::Template</type>
  <name>product.my_template.liquid</name>
  <content-type>text/x-liquid</content-type>
  <file-size type="integer">38</file-size>
</asset>

Список асетов

Запрос: GET /admin/themes/#{theme_id}/assets.xml

Ответ:

<?xml version="1.0" encoding="UTF-8"?>
<assets type="array">
  <asset>
    <account-id type="integer">10</account-id>
    <id type="integer">1460299</id>
    <theme-id type="integer">14522</theme-id>
    <type>Asset::Template</type>
    <name>product.my_template.liquid</name>
    <content-type>text/x-liquid</content-type>
    <file-size type="integer">38</file-size>
  </asset>
  <asset>
    <account-id type="integer">10</account-id>
    <id type="integer">1460010</id>
    <theme-id type="integer">14522</theme-id>
    <type>Asset::Media</type>
    <name>style.css</name>
    <content-type>text/css</content-type>
    <file-size type="integer">34438</file-size>
    <asset_url type="string">/assets/1/6330/14522/style.css</asset_url>
  </asset>
</assets>

Получение асета

Запрос: GET /admin/themes/#{theme_id}/assets/#{id}.xml

Ответ:

Если запрошен текстовый файл

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <account-id type="integer">10</account-id>
  <id type="integer">1460299</id>
  <theme-id type="integer">14522</theme-id>
  <type>Asset::Template</type>
  <name>product.my_template.liquid</name>
  <content-type>text/x-liquid</content-type>
  <file-size type="integer">38</file-size>
  <content type="string">template for product {{product.title}}</content>
</asset>

Если запрошена картинка, то в ответ добавляется поле attachment с закодированным в Base64 содержимым файла.

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <account-id type="integer">10</account-id>
  <id type="integer">1460005</id>
  <theme-id type="integer">14522</theme-id>
  <type>Asset::Media</type>
  <name>arrows.png</name>
  <content-type>image/png</content-type>
  <file-size type="integer">1078</file-size>
  <asset_url type="string">/assets/1/6330/14522/arrows.png</asset_url>
  <attachment type="string">iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAGXRFWHRTb2Z0
d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9i
ZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2Vo
aUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG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ldGE+IDw/eHBhY2tldCBlbmQ9
InIiPz4qOKNNAAAAZElEQVR42mJcuGABAxRwAfFUKDsbiL+BGCxQAU0gXgXE
OlC+CRBHAPFVJiCRAMRnkCQZoOxTIDmQCQugGCtgYiAAYFZ8BeL/aBgklsAE
Nd4c5CAkjdehYgtgvrgCxGbYvAkQYABadBdFxtx8lAAAAABJRU5ErkJggg==
</attachment>
</asset>

Обновление асета

Запрос: PUT /admin/themes/#{theme_id}/assets/#{id}.xml

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <content><![CDATA[amazing template for product {{product.title}}]]></content>
</asset>

Ответ:

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <account-id type="integer">10</account-id>
  <id type="integer">1460299</id>
  <theme-id type="integer">14522</theme-id>
  <type>Asset::Template</type>
  <name>product.my_template.liquid</name>
  <content-type>text/x-liquid</content-type>
  <file-size type="integer">46</file-size>
</asset>

Переименование асета

Запрос: PUT /admin/themes/#{theme_id}/assets/#{id}/rename.xml

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <new_name>product.my_amazing_template.liquid</new_name>
</asset>

Ответ:

<?xml version="1.0" encoding="UTF-8"?>
<asset>
  <account-id type="integer">10</account-id>
  <id type="integer">1460299</id>
  <theme-id type="integer">14522</theme-id>
  <type>Asset::Template</type>
  <name>product.my_amazing_template.liquid</name>
  <content-type>text/x-liquid</content-type>
  <file-size type="integer">46</file-size>
</asset>

Удаление асета

Запрос: DELETE /admin/themes/#{theme_id}/assets/#{id}.xml

Ответ:

HTTP/1.1 200 OK