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, delivery_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)
  • delivery_category (String) (defaults to: nil)


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

def initialize(product_id: nil, quantity: nil, item_price: nil, title: nil, description: nil, brand: nil, category: nil, delivery_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
  unless delivery_category.nil?
    self.delivery_category = String(delivery_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

#delivery_categoryObject

Returns the value of attribute delivery_category.



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

def delivery_category
  @delivery_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.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 112

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 &&
      delivery_category == o.delivery_category
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

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

    attributes in the form of hash



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
101
102
103
104
105
106
107
108
109
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 72

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

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


125
126
127
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 125

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 131

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

#normalizeObject

Normalize input fields to server request format.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 177

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
  unless delivery_category.nil?
    hash['delivery_category'] = FacebookAds::ServerSide::Util.normalize_delivery_category(
      delivery_category
    )
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/facebook_ads/ad_objects/server_side/content.rb', line 147

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
  unless delivery_category.nil?
    hash['delivery_category'] = delivery_category
  end
  hash.to_s
end