Class: Adparlor::Facebook::GraphApi::AdImage
Constant Summary
Fields::AdImage::CREATE_FIELDS, Fields::AdImage::FIELDS
Fields::FieldDecorator::GLOBAL_FIELDS
Instance Attribute Summary
Attributes inherited from GraphObject
#access_token
Class Method Summary
collapse
Instance Method Summary
collapse
#create, #destroy, included, #update
Methods inherited from GraphObject
#batch, create, #create, data_pass_through, destroy, #destroy, get, #initialize, parse_data_for_collection, read, respond_for_data, #to_hash, #to_json, update, #update
Methods included from Api
#base_uri, #conn, #conn_multi, #delete, #get, #proxy_api_key
included
Class Method Details
.get_content_type(header_content_type, file_name) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 68
def get_content_type(, file_name)
content_type = MIME::Types.type_for(file_name)
return content_type.first.content_type if !file_name.include?('safe_image.php') && !content_type.nil?
.empty? ? nil :
end
|
.get_preferred_extension(content_type) ⇒ Object
64
65
66
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 64
def get_preferred_extension(content_type)
MIME::Types[content_type].first.preferred_extension
end
|
.upload_file_with_content_type(normalized_file_name, file, content_type, extension) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 54
def upload_file_with_content_type(normalized_file_name, file, content_type, extension)
tmp_file = Tempfile.new([File.basename(normalized_file_name), ".#{extension}"])
tmp_file.binmode
tmp_file.write(file.read)
tmp_file.rewind
Faraday::UploadIO.new(tmp_file.path, content_type)
end
|
Instance Method Details
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 14
def formatted_image
return unless @source
if %r{https?}.match(@source)
file = open(@source)
return nil if file.nil?
content_type = AdImage.get_content_type(file.content_type, normalized_file_name)
extension = AdImage.get_preferred_extension(content_type)
return nil if content_type.nil? || extension.nil?
@source = AdImage.upload_file_with_content_type(normalized_file_name, file, content_type, extension)
else
@source = Faraday::UploadIO.new(normalized_file_name, MIME::Types.type_for(normalized_file_name).first.content_type)
end
end
|
#path ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 34
def path
raise FbError.new('required parameter account_id missing', 500) unless account_id
if account_id.to_s.include?('act_')
"/#{account_id}/adimages"
else
"/act_#{account_id}/adimages"
end
end
|
#post(path, options, method = nil) ⇒ Object
43
44
45
46
47
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 43
def post(path, options, method = nil)
raise FbError.new('update not available', 500) if method == 'UPDATE'
formatted_image
super path, options
end
|
#update_path ⇒ Object
49
50
51
|
# File 'lib/adparlor/facebook/graph_api/ad_image.rb', line 49
def update_path
path
end
|