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
- #base_path ⇒ Object
-
#deserialize(data) ⇒ Object
TODO.
- #empty? ⇒ Boolean
- #from_params(data) ⇒ Object
- #has_base_path(path) ⇒ 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.
9 10 11 12 13 |
# File 'lib/facebook_ads/param_set.rb', line 9 def initialize @params = {} @accepts_files = false @base_path = nil end |
Instance Method Details
#accepts_files! ⇒ Object
19 20 21 |
# File 'lib/facebook_ads/param_set.rb', line 19 def accepts_files! @accepts_files = true end |
#accepts_files? ⇒ Boolean
23 24 25 |
# File 'lib/facebook_ads/param_set.rb', line 23 def accepts_files? @accepts_files end |
#base_path ⇒ Object
31 32 33 |
# File 'lib/facebook_ads/param_set.rb', line 31 def base_path @base_path end |
#deserialize(data) ⇒ Object
TODO
63 64 65 |
# File 'lib/facebook_ads/param_set.rb', line 63 def deserialize(data) from_params(data) end |
#empty? ⇒ Boolean
67 68 69 |
# File 'lib/facebook_ads/param_set.rb', line 67 def empty? @params.empty? end |
#from_params(data) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/facebook_ads/param_set.rb', line 53 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_base_path(path) ⇒ Object
27 28 29 |
# File 'lib/facebook_ads/param_set.rb', line 27 def has_base_path(path) @base_path = path end |
#has_param(name, type) ⇒ Object
15 16 17 |
# File 'lib/facebook_ads/param_set.rb', line 15 def has_param(name, type) @params[name.to_sym] = FieldTypes.for(type) end |
#to_params(data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/facebook_ads/param_set.rb', line 35 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 |