class AboutYou::SDK::Model::Autocomplete

This Class represents an autocomplete model

Constants

NOT_REQUESTED

this constant is used for values which are not requested

TYPE_BRANDS

argument for api when requiring brands

TYPE_CATEGORIES

argument for api when requiring categories

TYPE_PRODUCTS

argument for api when requiring products

Attributes

brands[RW]

the brands of the autocomplete

categories[RW]

the categories of the autocomplete

products[RW]

the products of the autocomplete

Public Class Methods

create_from_json(json_object, factory) click to toggle source

This method lets you build an autocomplete model by a json response from the api

  • Args :

    • json_object -> the json response from the api

    • factory -> the model factory responsible for building the models

  • Returns :

    • Instance of AboutYou::SDK::Model::AutoComplete

# File lib/AboutYou/Model/autocomplete.rb, line 51
def self.create_from_json(json_object, factory)
  new(
    parse_categories(json_object, factory),
    parse_products(json_object, factory),
    parse_brands(json_object, factory)
  )
end
new(categories = nil, products = nil, brands = nil) click to toggle source

the Constructor for the autocomplete class

  • Args :

    • categories -> the products of the autocomplete

    • products -> the categories of the autocomplete

    • brands -> the brands of the autocomplete

  • Returns :

    • Instance of AboutYou::SDK::Model::AutoComplete

# File lib/AboutYou/Model/autocomplete.rb, line 35
def initialize(categories = nil, products = nil, brands = nil)
  self.categories = categories
  self.products   = products
  self.brands     = brands
end
parse_brands(json_object, factory) click to toggle source

This method parses the json object and builds product models from it

  • Args :

    • json_object -> the json response from the api

    • factory -> the model factory responsible for building the models

  • Returns :

# File lib/AboutYou/Model/autocomplete.rb, line 113
def self.parse_brands(json_object, factory)
  return NOT_REQUESTED unless json_object.key?('brands')
  return [] if json_object['brands'].nil?

  brands = []
  json_object['brands'].each do |brand|
      brands.push(factory.create_brand(brand))
  end

  brands
end
parse_categories(json_object, factory) click to toggle source

This method parses the json object and builds category models from it

  • Args :

    • json_object -> the json response from the api

    • factory -> the model factory responsible for building the models

  • Returns :

# File lib/AboutYou/Model/autocomplete.rb, line 69
def self.parse_categories(json_object, factory)
  return NOT_REQUESTED unless json_object.key?('categories')
  return [] if json_object['categories'].nil?

  categories = []
  json_object['categories'].each do |category|
    categories.push(factory.create_category(category))
  end

  categories
end
parse_products(json_object, factory) click to toggle source

This method parses the json object and builds product models from it

  • Args :

    • json_object -> the json response from the api

    • factory -> the model factory responsible for building the models

  • Returns :

# File lib/AboutYou/Model/autocomplete.rb, line 91
def self.parse_products(json_object, factory)
  return NOT_REQUESTED unless json_object.key?('products')
  return [] if json_object['products'].nil?

  products = []
  json_object['products'].each do |product|
    products.push(factory.create_product(product))
  end

  products
end