Class: FacebookAds::ParamSet
- Inherits:
-
Object
- Object
- FacebookAds::ParamSet
- Defined in:
- lib/facebook_ads/param_set.rb
Instance Method Summary collapse
- #accepts_files! ⇒ Object
- #accepts_files? ⇒ Boolean
-
#deserialize(data) ⇒ Object
TODO.
- #empty? ⇒ Boolean
- #from_params(data) ⇒ Object
- #has_param(name, type) ⇒ Object
-
#initialize ⇒ ParamSet
constructor
A new instance of ParamSet.
- #to_params(data) ⇒ Object
Constructor Details
#initialize ⇒ ParamSet
Returns a new instance of ParamSet.
21 22 23 24 |
# File 'lib/facebook_ads/param_set.rb', line 21 def initialize @params = {} @accepts_files = false end |
Instance Method Details
#accepts_files! ⇒ Object
30 31 32 |
# File 'lib/facebook_ads/param_set.rb', line 30 def accepts_files! @accepts_files = true end |
#accepts_files? ⇒ Boolean
34 35 36 |
# File 'lib/facebook_ads/param_set.rb', line 34 def accepts_files? @accepts_files end |
#deserialize(data) ⇒ Object
TODO
66 67 68 |
# File 'lib/facebook_ads/param_set.rb', line 66 def deserialize(data) from_params(data) end |
#empty? ⇒ Boolean
70 71 72 |
# File 'lib/facebook_ads/param_set.rb', line 70 def empty? @params.empty? end |
#from_params(data) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/facebook_ads/param_set.rb', line 56 def from_params(data) Hash[data.map do |key,val| key = key.to_sym field_type = @params[key] [key, (field_type ? field_type.deserialize(val) : val)] end] end |
#has_param(name, type) ⇒ Object
26 27 28 |
# File 'lib/facebook_ads/param_set.rb', line 26 def has_param(name, type) @params[name.to_sym] = FieldTypes.for(type) end |
#to_params(data) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/facebook_ads/param_set.rb', line 38 def to_params(data) Hash[data.map do |key,val| key = key.to_sym field_type = @params[key] if (!field_type && accepts_files? && FieldTypes::UploadFile.acceptable?(val)) field_type = FieldTypes::UploadFile.new end if (!field_type && val.is_a?(Array)) # dynamic ads val = JSON.generate(val) end [key, (field_type ? field_type.serialize(val) : val)] # TODO CollectionProxy= end] end |