lib/moysklad/resources/base.rb in moysklad-0.0.2 vs lib/moysklad/resources/base.rb in moysklad-0.1.1

- old
+ new

@@ -4,10 +4,14 @@ def self.inherited superclass super Moysklad::Resources.register_resource superclass end + def self.indexed *args + Moysklad::Resources::Indexed.new new(*args) + end + # https://support.moysklad.ru/hc/ru/articles/203404253-REST-сервис-синхронизации-данных def initialize client: nil raise "Должен быть Moysklad::Client" unless client.is_a? Moysklad::Client @client = client end @@ -18,11 +22,11 @@ def collection params={} parse_collection client.get list_path, params end - def find uuid + def get uuid parse client.get item_path uuid end def create resource parse client.put create_path, prepare_resource(resource) @@ -41,15 +45,20 @@ end def self.entity_class ActiveSupport::Inflector.constantize "Moysklad::Entities::#{type.to_s}" end + private attr_reader :client def prepare_resource resource - resource + if resource.is_a? Moysklad::Entities::Base + resource.to_xml.to_s + else + resource.to_s + end end def parse content self.class.entity_class.parse content end