Module: FbGraph::Connections::AdImages

Included in:
AdAccount
Defined in:
lib/fb_graph/connections/ad_images.rb

Instance Method Summary collapse

Instance Method Details

#ad_image!(options = {}) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fb_graph/connections/ad_images.rb', line 13

def ad_image!(options = {})
  ad_image = post options.merge(:connection => :adimages)

 # No ID is contained in the response.
  adimage_id = ad_image[:images].keys.first
  hash = ad_image[:images].values.first[:hash]
  url = ad_image[:images].values.first[:url]

  merged_attrs = options.merge(
    :access_token => options[:access_token] || self.access_token,
    :hash => hash,
    :url => url
  )

  if options[:redownload]
    merged_attrs = merged_attrs.merge(ad_image[:data][:adimages][adimage_id]).with_indifferent_access
  end
	
	# The first argument is the identifier, which is appended to the endpoint
  AdImage.new adimage_id, merged_attrs
end

#ad_images(options = {}) ⇒ Object


4
5
6
7
8
9
10
11
# File 'lib/fb_graph/connections/ad_images.rb', line 4

def ad_images(options = {})
  ad_images = self.connection :adimages, options
  ad_images.map! do |ad_image|
    AdImage.new ad_image[:id], ad_image.merge(
      :access_token => options[:access_token] || self.access_token
    )
  end
end