Class: FacebookAds::ServerSide::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_ads/ad_objects/server_side/content.rb

Overview

Content object contains information about the products.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_id: nil, quantity: nil, item_price: nil, title: nil, description: nil, brand: nil, category: nil) ⇒ Content

Initializes the object

Parameters:

  • product_id (String) (defaults to: nil)
  • quantity (Integer) (defaults to: nil)
  • item_price (Float) (defaults to: nil)
  • title (String) (defaults to: nil)
  • description (String) (defaults to: nil)
  • brand (String) (defaults to: nil)
  • category (String) (defaults to: nil)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 41

def initialize(product_id: nil, quantity: nil, item_price: nil, title: nil, description: nil, brand: nil, category: nil)
  unless product_id.nil?
    self.product_id = String(product_id)
  end
  unless quantity.nil?
    self.quantity = Integer(quantity)
  end
  unless item_price.nil?
    self.item_price = Float(item_price)
  end
  unless title.nil?
    self.title = String(title)
  end
  unless description.nil?
    self.description = String(description)
  end
  unless brand.nil?
    self.brand = String(brand)
  end
  unless category.nil?
    self.category = String(category)
  end
end

Instance Attribute Details

#brandObject

Returns the value of attribute brand.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def brand
  @brand
end

#categoryObject

Returns the value of attribute category.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def description
  @description
end

#item_priceObject

Returns the value of attribute item_price.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def item_price
  @item_price
end

#product_idObject

Returns the value of attribute product_id.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def product_id
  @product_id
end

#quantityObject

Returns the value of attribute quantity.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def quantity
  @quantity
end

#titleObject

Returns the value of attribute title.



25
26
27
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 25

def title
  @title
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



103
104
105
106
107
108
109
110
111
112
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 103

def ==(o)
  return self.class == o.class &&
      product_id == o.product_id &&
      quantity == o.quantity &&
      item_price == o.item_price &&
      title == o.title &&
      description == o.description &&
      brand == o.brand &&
      category == o.category
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

  • attributes (Hash) (defaults to: {})

    attributes in the form of hash



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 67

def build(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  if attributes.has_key?(:'product_id')
    self.product_id = attributes[:'product_id']
  end

  if attributes.has_key?(:'quantity')
    self.quantity = attributes[:'quantity']
  end

  if attributes.has_key?(:'item_price')
    self.item_price = attributes[:'item_price']
  end

  if attributes.has_key?(:'title')
    self.title = attributes[:'title']
  end

  if attributes.has_key?(:'description')
    self.description = attributes[:'description']
  end

  if attributes.has_key?(:'brand')
    self.brand = attributes[:'brand']
  end

  if attributes.has_key?(:'category')
    self.category = attributes[:'category']
  end
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


115
116
117
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 115

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 121

def hash
  [
      product_id,
      quantity,
      item_price,
      title,
      description,
      brand,
      category
  ].hash
end

#normalizeObject

Normalize input fields to server request format.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 163

def normalize
  hash = {}
  unless product_id.nil?
    hash['id'] = product_id
  end
  unless quantity.nil?
    hash['quantity'] = quantity
  end
  unless item_price.nil?
    hash['item_price'] = item_price
  end
  unless title.nil?
    hash['title'] = title
  end
  unless description.nil?
    hash['description'] = description
  end
  unless brand.nil?
    hash['brand'] = brand
  end
  unless category.nil?
    hash['category'] = category
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 136

def to_s
  hash = {}
  unless product_id.nil?
    hash['product_id'] = product_id
  end
  unless quantity.nil?
    hash['quantity'] = quantity
  end
  unless item_price.nil?
    hash['item_price'] = item_price
  end
  unless title.nil?
    hash['title'] = title
  end
  unless description.nil?
    hash['description'] = description
  end
  unless brand.nil?
    hash['brand'] = brand
  end
  unless category.nil?
    hash['category'] = category
  end
  hash.to_s
end