Sha256: 5e27ea8c9c6c45744c369fac581cce164a76e0d21c404ad2dab56db65f3ed9aa

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

module FbGraph
  class AdGroup < Node
    attr_accessor :ad_id, :campaign_id, :name, :adgroup_status, :bid_type, :max_bid, :targeting, :creative, :creative_ids, :adgroup_id,
      :end_time, :start_time, :updated_time, :bid_info, :disapprove_reason_descriptions

    def initialize(identifier, attributes = {})
      super
      set_attrs(attributes)
    end

    # We override update to handle the "redownload" parameter
    # If redownload is specified, the FbGraph::AdGroup object will be updated with the data returned from Facebook.
    def update(options)
      response = super(options)

      if options[:redownload]
        attributes = options.merge(response[:data][:adgroups][identifier]).with_indifferent_access
        set_attrs(attributes)
      end

      response
    end

    protected

    def set_attrs(attributes)
      %w(ad_id campaign_id name adgroup_status bid_type max_bid targeting creative creative_ids adgroup_id bid_info disapprove_reason_descriptions).each do |field|
        send("#{field}=", attributes[field.to_sym])
      end

      # max_bid is string only when reloaded for some reason..
      self.max_bid = max_bid.try(:to_i)

      %w(start_time end_time updated_time).each do |field|
        if val = attributes[field.to_sym]
          # Handles integer timestamps and ISO8601 strings
          time = Time.parse(val) rescue Time.at(val.to_i)
          send("#{field}=", time)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fb_graph-2.4.20 lib/fb_graph/ad_group.rb
fb_graph-2.4.19 lib/fb_graph/ad_group.rb
fb_graph-2.4.18 lib/fb_graph/ad_group.rb
fb_graph-2.4.17 lib/fb_graph/ad_group.rb
fb_graph-2.4.16 lib/fb_graph/ad_group.rb
fb_graph-2.4.15 lib/fb_graph/ad_group.rb
fb_graph-2.4.14 lib/fb_graph/ad_group.rb
fb_graph-2.4.13 lib/fb_graph/ad_group.rb
fb_graph-2.4.12 lib/fb_graph/ad_group.rb
fb_graph-2.4.11 lib/fb_graph/ad_group.rb
fb_graph-2.4.10 lib/fb_graph/ad_group.rb
fb_graph-2.4.9 lib/fb_graph/ad_group.rb
fb_graph-2.4.8 lib/fb_graph/ad_group.rb
fb_graph-2.4.7 lib/fb_graph/ad_group.rb
fb_graph-2.4.6 lib/fb_graph/ad_group.rb
fb_graph-2.4.4 lib/fb_graph/ad_group.rb
fb_graph-2.4.3 lib/fb_graph/ad_group.rb