Sha256: 8f5c06c692a8bf37ec045e66f2f488b2374821eac48191eeeb3b87a74b0229c8

Contents?: true

Size: 1.09 KB

Versions: 33

Compression:

Stored size: 1.09 KB

Contents

module FbGraph
  class AdCampaign < Node
    include Connections::AdGroups

    attr_accessor :campaign_id, :account_id, :name, :start_time, :end_time, :updated_time, :daily_budget, :daily_imps, :campaign_status, :lifetime_budget, :lifetime_imps

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

    def update(options)
      response = super(options)

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

      response
    end

    protected

    def set_attrs(attributes)
      %w(campaign_id account_id name daily_budget daily_imps campaign_status lifetime_budget lifetime_imps).each do |field|
        send("#{field}=", attributes[field.to_sym])
      end

      %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

33 entries across 33 versions & 1 rubygems

Version Path
fb_graph-2.7.15 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.14 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.13 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.12 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.11 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.10 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.9 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.8 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.7 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.6 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.5 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.4 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.3 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.2 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.1 lib/fb_graph/ad_campaign.rb
fb_graph-2.7.0 lib/fb_graph/ad_campaign.rb
fb_graph-2.6.7 lib/fb_graph/ad_campaign.rb
fb_graph-2.6.6 lib/fb_graph/ad_campaign.rb
fb_graph-2.6.5 lib/fb_graph/ad_campaign.rb
fb_graph-2.6.4 lib/fb_graph/ad_campaign.rb