Module: TPEX::Client::Products
- Included in:
- TPEX::Client
- Defined in:
- lib/tpex/client/products.rb
Defined Under Namespace
Classes: Product
Constant Summary collapse
- FIELDS =
{ manufacturer: {machine_name: "manufacturer"}, certified: {machine_name: "field_certified", required: true}, tags: {machine_name: "field_tags", required: true, label:"tid"}, model_no: {machine_name: "field_model_num", required: true, enclosed: true}, brand: {machine_name: "field_product_brand", required: true, enclosed: true}, product_line: {machine_name: "field_product_line_family_name", enclosed: true}, femp: {machine_name: "field_femp", required: true}, upc: {machine_name: "field_universal_product_code_upc"}, energy_star_no: {machine_name: "field_energy_star_specification_", enclosed: true}, uuid: {machine_name: "uuid"} }
Instance Method Summary collapse
- #build_product(options = {}) ⇒ Object
- #jsonify_product(product) ⇒ Object
-
#post_product(product) ⇒ Object
end.
Instance Method Details
#build_product(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tpex/client/products.rb', line 31 def build_product(={}) required_fields = [] arguments = [] TPEX::Client::Products::FIELDS.each do |key, value| required_fields << key if value[:required] arguments << [key] end required_fields.each do |key| return nil if [key].nil? end return Product.new(*arguments); end |
#jsonify_product(product) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tpex/client/products.rb', line 47 def jsonify_product(product) if !product[:uuid].nil? jsonobject = {"title" => "Json Object", "uuid" => product[:uuid]} else jsonobject = {"title" => "Json Object"} end fields = TPEX::Client::Products::FIELDS product.each_pair do |name, value| if name != :uuid if !value.nil? label = fields[name][:label] || "value" contents = {label => value} contents = [{label => value}] if fields[name][:enclosed] jsonobject[fields[name][:machine_name]] = {"und" => contents} end end end JSON.generate({"product" => jsonobject}) end |
#post_product(product) ⇒ Object
end
26 27 28 29 |
# File 'lib/tpex/client/products.rb', line 26 def post_product(product) data = jsonify_product(product) response = post("content", data) end |