Class: Moysklad::Resources::Base
- Inherits:
-
Object
- Object
- Moysklad::Resources::Base
- Includes:
- Positions
- Defined in:
- lib/moysklad/resources/base.rb
Direct Known Subclasses
Assortments, CustomEntities, CustomEntityMetadata, EmbeddedEntityMetadata, ProductImages, Products, Stock
Constant Summary collapse
- PREFIX_PATH =
'entity/'
Class Method Summary collapse
-
.indexed(client: nil, list_path: nil) ⇒ Moysklad::Resources::Indexed
Возвращает этот-же ресурс только индексированный.
- .inherited(superclass) ⇒ Object
- .pluralized_type ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
-
#create(model) ⇒ Moysklad::Entities::Base
Создаем запись.
-
#delete(uuid) ⇒ Object
Удаляем запись по uuid.
-
#get(uuid, params = {}) ⇒ Moysklad::Entities::Base
Забираем элемент по uuid.
-
#initialize(client: nil, list_path: nil) ⇒ Base
constructor
support.moysklad.ru/hc/ru/articles/203404253-REST-сервис-синхронизации-данных.
-
#list(params = {}) ⇒ Array of Moysklad::Entities::Base
Возвращает список элементов как есть.
- #metadata ⇒ Object
-
#update(model) ⇒ Moysklad::Entities::Base
Модифицируем элемент по uuid.
Methods included from Positions
#create_position, #create_position_path
Constructor Details
#initialize(client: nil, list_path: nil) ⇒ Base
support.moysklad.ru/hc/ru/articles/203404253-REST-сервис-синхронизации-данных
19 20 21 22 23 |
# File 'lib/moysklad/resources/base.rb', line 19 def initialize client: nil, list_path: nil @list_path = list_path raise "Должен быть Moysklad::Client" unless client.is_a? Moysklad::Client @client = client end |
Class Method Details
.indexed(client: nil, list_path: nil) ⇒ Moysklad::Resources::Indexed
Возвращает этот-же ресурс только индексированный
14 15 16 |
# File 'lib/moysklad/resources/base.rb', line 14 def self.indexed client: nil, list_path: nil Moysklad::Resources::Indexed.new new(client: client, list_path: list_path) end |
.inherited(superclass) ⇒ Object
6 7 8 9 |
# File 'lib/moysklad/resources/base.rb', line 6 def self.inherited superclass super Moysklad::Resources.register_resource superclass end |
.pluralized_type ⇒ Object
73 74 75 |
# File 'lib/moysklad/resources/base.rb', line 73 def self.pluralized_type ActiveSupport::Inflector.underscore ActiveSupport::Inflector.pluralize type end |
.type ⇒ Object
69 70 71 |
# File 'lib/moysklad/resources/base.rb', line 69 def self.type ActiveSupport::Inflector.singularize name.split('::').last.to_sym end |
Instance Method Details
#create(model) ⇒ Moysklad::Entities::Base
Создаем запись
Возвращается созданная на сервере сущность
57 58 59 60 |
# File 'lib/moysklad/resources/base.rb', line 57 def create model raise "Должна быть модель типа Moysklad::Entities::Base" unless model.is_a? Moysklad::Entities::Base parse_get client.post create_path, model.to_json end |
#delete(uuid) ⇒ Object
Удаляем запись по uuid
65 66 67 |
# File 'lib/moysklad/resources/base.rb', line 65 def delete uuid client.delete item_path uuid end |
#get(uuid, params = {}) ⇒ Moysklad::Entities::Base
Забираем элемент по uuid
39 40 41 |
# File 'lib/moysklad/resources/base.rb', line 39 def get uuid, params = {} parse_get client.get item_path(uuid), params end |
#list(params = {}) ⇒ Array of Moysklad::Entities::Base
Возвращает список элементов как есть
32 33 34 |
# File 'lib/moysklad/resources/base.rb', line 32 def list params={} load_collection client.get list_path, params end |
#metadata ⇒ Object
25 26 27 |
# File 'lib/moysklad/resources/base.rb', line 25 def Moysklad::Entities::ResourceMetadata.build client.get(), self end |
#update(model) ⇒ Moysklad::Entities::Base
Модифицируем элемент по uuid
46 47 48 |
# File 'lib/moysklad/resources/base.rb', line 46 def update model create model end |