Module: WeChat::Product::ClassMethods
- Defined in:
- lib/we_chat/product.rb
Instance Method Summary collapse
- #get_instance_data_from_reponse(response) ⇒ Object
- #prepare_instance_data(data) ⇒ Object
- #prepare_one_type_of_children(instance, child_type, child_data) ⇒ Object
- #prepare_one_type_of_children_data(data, child_type, definition) ⇒ Object
Instance Method Details
#get_instance_data_from_reponse(response) ⇒ Object
63 64 65 |
# File 'lib/we_chat/product.rb', line 63 def get_instance_data_from_reponse(response) response[:product_info] end |
#prepare_instance_data(data) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/we_chat/product.rb', line 67 def prepare_instance_data(data) result = {} result[:we_chat_id] = data[:product_id] result[:name] = data[:product_base][:name] result[:buy_limit] = data[:product_base][:buy_limit] result[:main_image_url] = data[:product_base][:main_img] result[:description] = data[:product_base][:detail_html] result end |
#prepare_one_type_of_children(instance, child_type, child_data) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/we_chat/product.rb', line 86 def prepare_one_type_of_children(instance, child_type, child_data) case child_type when :category child_data[:data].each do |category_id| child_instance = child_data[:klass].send(:find_by_we_chat_id, category_id) instance.send(child_data[:method]) << child_instance if child_instance end when :category_property_item child_data[:data].each do |item| category_property_id = item[:id] category_property_item_id = item[:vid] child_instance = child_data[:klass].send(:find_by_we_chat_id, category_property_item_id) instance.send(child_data[:method]) << child_instance if child_instance end when :product_attribute child_data[:data].map do |key, value| if key != :location child_instance = child_data[:klass].send(:create_by_we_chat_data, { key: key.to_s.underscore, value: value, we_chat_id: key.to_s }) instance.send(child_data[:method]) << child_instance if child_instance else value.map do |k, v| child_instance = child_data[:klass].send(:create_by_we_chat_data, { key: "location.#{k.to_s.underscore}", value: v, we_chat_id: k.to_s }) instance.send(child_data[:method]) << child_instance if child_instance end end end else super(instance, child_type, child_data) end end |
#prepare_one_type_of_children_data(data, child_type, definition) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/we_chat/product.rb', line 77 def prepare_one_type_of_children_data(data, child_type, definition) if [:category, :category_property_item].include?(child_type) data_key = definition[:data_key] definition.merge(data: data[:product_base][data_key]) else super(data, child_type, definition) end end |