app/helpers/spree/api/api_helpers.rb in spree_api-2.1.2 vs app/helpers/spree/api/api_helpers.rb in spree_api-2.1.3
- old
+ new
@@ -1,115 +1,148 @@
module Spree
module Api
module ApiHelpers
+ ATTRIBUTES = [
+ :product_attributes,
+ :product_property_attributes,
+ :variant_attributes,
+ :image_attributes,
+ :option_value_attributes,
+ :order_attributes,
+ :line_item_attributes,
+ :option_type_attributes,
+ :payment_attributes,
+ :payment_method_attributes,
+ :shipment_attributes,
+ :taxonomy_attributes,
+ :taxon_attributes,
+ :inventory_unit_attributes,
+ :return_authorization_attributes,
+ :address_attributes,
+ :country_attributes,
+ :state_attributes,
+ :adjustment_attributes,
+ :taxon_attributes,
+ :inventory_unit_attributes,
+ :return_authorization_attributes,
+ :adjustment_attributes,
+ :creditcard_attributes,
+ :user_attributes,
+ :property_attributes,
+ :stock_location_attributes,
+ :stock_movement_attributes,
+ :stock_item_attributes
+ ]
+
+ mattr_reader *ATTRIBUTES
+
def required_fields_for(model)
required_fields = model._validators.select do |field, validations|
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
end.map(&:first) # get fields that are invalid
# Permalinks presence is validated, but are really automatically generated
# Therefore we shouldn't tell API clients that they MUST send one through
required_fields.map!(&:to_s).delete("permalink")
required_fields
end
- def product_attributes
- [:id, :name, :description, :price, :display_price, :available_on, :permalink, :meta_description, :meta_keywords, :shipping_category_id, :taxon_ids]
- end
+ @@product_attributes = [
+ :id, :name, :description, :price, :display_price, :available_on,
+ :permalink, :meta_description, :meta_keywords, :shipping_category_id,
+ :taxon_ids
+ ]
- def product_property_attributes
- [:id, :product_id, :property_id, :value, :property_name]
- end
+ @@product_property_attributes = [
+ :id, :product_id, :property_id, :value, :property_name
+ ]
- def variant_attributes
- [:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master, :cost_price, :permalink, :description]
- end
+ @@variant_attributes = [
+ :id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
+ :cost_price, :permalink, :description
+ ]
- def image_attributes
- [:id, :position, :attachment_content_type, :attachment_file_name, :type, :attachment_updated_at, :attachment_width, :attachment_height, :alt]
- end
+ @@image_attributes = [
+ :id, :position, :attachment_content_type, :attachment_file_name, :type,
+ :attachment_updated_at, :attachment_width, :attachment_height, :alt
+ ]
- def option_value_attributes
- [:id, :name, :presentation, :option_type_name, :option_type_id, :option_type_presentation]
- end
+ @@option_value_attributes = [
+ :id, :name, :presentation, :option_type_name, :option_type_id,
+ :option_type_presentation
+ ]
- def order_attributes
- [:id, :number, :item_total, :total, :state, :adjustment_total, :user_id, :created_at, :updated_at, :completed_at, :payment_total, :shipment_state, :payment_state, :email, :special_instructions]
- end
+ @@order_attributes = [
+ :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
+ :user_id, :created_at, :updated_at, :completed_at, :payment_total,
+ :shipment_state, :payment_state, :email, :special_instructions, :channel
+ ]
- def line_item_attributes
- [:id, :quantity, :price, :variant_id]
- end
+ @@line_item_attributes = [:id, :quantity, :price, :variant_id]
- def option_type_attributes
- [:id, :name, :presentation, :position]
- end
+ @@option_type_attributes = [:id, :name, :presentation, :position]
- def payment_attributes
- [:id, :source_type, :source_id, :amount, :display_amount, :payment_method_id, :response_code, :state, :avs_response, :created_at, :updated_at]
- end
+ @@payment_attributes = [
+ :id, :source_type, :source_id, :amount, :display_amount,
+ :payment_method_id, :response_code, :state, :avs_response, :created_at,
+ :updated_at
+ ]
- def payment_method_attributes
- [:id, :name, :description]
- end
+ @@payment_method_attributes = [:id, :name, :description]
- def shipment_attributes
- [:id, :tracking, :number, :cost, :shipped_at, :state]
- end
+ @@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
- def taxonomy_attributes
- [:id, :name]
- end
+ @@taxonomy_attributes = [:id, :name]
- def taxon_attributes
- [:id, :name, :pretty_name, :permalink, :position, :parent_id, :taxonomy_id]
- end
+ @@taxon_attributes = [
+ :id, :name, :pretty_name, :permalink, :position, :parent_id,
+ :taxonomy_id
+ ]
- def inventory_unit_attributes
- [:id, :lock_version, :state, :variant_id, :shipment_id, :return_authorization_id]
- end
+ @@inventory_unit_attributes = [
+ :id, :lock_version, :state, :variant_id, :shipment_id,
+ :return_authorization_id
+ ]
- def return_authorization_attributes
- [:id, :number, :state, :amount, :order_id, :reason, :created_at, :updated_at]
- end
+ @@return_authorization_attributes = [
+ :id, :number, :state, :amount, :order_id, :reason, :created_at,
+ :updated_at
+ ]
- def address_attributes
- [:id, :firstname, :lastname, :full_name, :address1, :address2, :city, :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id, :state_name]
- end
+ @@address_attributes = [
+ :id, :firstname, :lastname, :full_name, :address1, :address2, :city,
+ :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
+ :state_name
+ ]
- def country_attributes
- [:id, :iso_name, :iso, :iso3, :name, :numcode]
- end
+ @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
- def state_attributes
- [:id, :name, :abbr, :country_id]
- end
+ @@state_attributes = [:id, :name, :abbr, :country_id]
- def adjustment_attributes
- [:id, :source_type, :source_id, :adjustable_type, :adjustable_id, :originator_type, :originator_id, :amount, :label, :mandatory, :locked, :eligible, :created_at, :updated_at]
- end
+ @@adjustment_attributes = [
+ :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
+ :originator_type, :originator_id, :amount, :label, :mandatory,
+ :locked, :eligible, :created_at, :updated_at
+ ]
- def creditcard_attributes
- [:id, :month, :year, :cc_type, :last_digits, :first_name, :last_name, :gateway_customer_profile_id, :gateway_payment_profile_id]
- end
+ @@creditcard_attributes = [
+ :id, :month, :year, :cc_type, :last_digits, :first_name, :last_name,
+ :gateway_customer_profile_id, :gateway_payment_profile_id
+ ]
- def user_attributes
- [:id, :email, :created_at, :updated_at]
- end
+ @@user_attributes = [:id, :email, :created_at, :updated_at]
- def property_attributes
- [:id, :name, :presentation]
- end
+ @@property_attributes = [:id, :name, :presentation]
- def stock_location_attributes
- [:id, :name, :address1, :address2, :city, :state_id, :state_name, :country_id, :zipcode, :phone, :active]
- end
+ @@stock_location_attributes = [
+ :id, :name, :address1, :address2, :city, :state_id, :state_name,
+ :country_id, :zipcode, :phone, :active
+ ]
- def stock_movement_attributes
- [:id, :quantity, :stock_item_id]
- end
+ @@stock_movement_attributes = [:id, :quantity, :stock_item_id]
- def stock_item_attributes
- [:id, :count_on_hand, :backorderable, :lock_version, :stock_location_id, :variant_id]
- end
+ @@stock_item_attributes = [
+ :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
+ :variant_id
+ ]
end
end
end