facebookads 0.0.1 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +17 -0
- data/README.md +222 -0
- data/lib/facebook_ads/ad_object.rb +177 -0
- data/lib/facebook_ads/ad_objects/ad.rb +215 -0
- data/lib/facebook_ads/ad_objects/ad_account.rb +665 -0
- data/lib/facebook_ads/ad_objects/ad_account_roas.rb +97 -0
- data/lib/facebook_ads/ad_objects/ad_account_targeting_unified.rb +136 -0
- data/lib/facebook_ads/ad_objects/ad_account_user.rb +39 -0
- data/lib/facebook_ads/ad_objects/ad_activity.rb +123 -0
- data/lib/facebook_ads/ad_objects/ad_async_request.rb +66 -0
- data/lib/facebook_ads/ad_objects/ad_async_request_set.rb +68 -0
- data/lib/facebook_ads/ad_objects/ad_async_request_set_notification_result.rb +38 -0
- data/lib/facebook_ads/ad_objects/ad_creative.rb +163 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data.rb +62 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data_app_link_spec.rb +40 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data_call_to_action.rb +75 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data_call_to_action_value.rb +46 -0
- data/lib/facebook_ads/ad_objects/ad_creative_link_data_child_attachment.rb +47 -0
- data/lib/facebook_ads/ad_objects/ad_creative_object_story_spec.rb +43 -0
- data/lib/facebook_ads/ad_objects/ad_creative_offer_data.rb +44 -0
- data/lib/facebook_ads/ad_objects/ad_creative_photo_data.rb +42 -0
- data/lib/facebook_ads/ad_objects/ad_creative_place_data.rb +41 -0
- data/lib/facebook_ads/ad_objects/ad_creative_text_data.rb +37 -0
- data/lib/facebook_ads/ad_objects/ad_creative_video_data.rb +48 -0
- data/lib/facebook_ads/ad_objects/ad_image.rb +58 -0
- data/lib/facebook_ads/ad_objects/ad_keyword_stats.rb +55 -0
- data/lib/facebook_ads/ad_objects/ad_label.rb +57 -0
- data/lib/facebook_ads/ad_objects/ad_place_page_set.rb +44 -0
- data/lib/facebook_ads/ad_objects/ad_preview.rb +54 -0
- data/lib/facebook_ads/ad_objects/ad_promoted_object.rb +64 -0
- data/lib/facebook_ads/ad_objects/ad_recommendation.rb +55 -0
- data/lib/facebook_ads/ad_objects/ad_recommendation_data.rb +37 -0
- data/lib/facebook_ads/ad_objects/ad_report_run.rb +70 -0
- data/lib/facebook_ads/ad_objects/ad_set.rb +267 -0
- data/lib/facebook_ads/ad_objects/ad_study.rb +69 -0
- data/lib/facebook_ads/ad_objects/ad_study_cell.rb +39 -0
- data/lib/facebook_ads/ad_objects/ad_study_objective.rb +59 -0
- data/lib/facebook_ads/ad_objects/ad_video.rb +25 -0
- data/lib/facebook_ads/ad_objects/adgroup_placement_specific_review_feedback.rb +43 -0
- data/lib/facebook_ads/ad_objects/adgroup_relevance_score.rb +40 -0
- data/lib/facebook_ads/ad_objects/adgroup_review_feedback.rb +38 -0
- data/lib/facebook_ads/ad_objects/ads_action_stats.rb +53 -0
- data/lib/facebook_ads/ad_objects/ads_data_partner.rb +37 -0
- data/lib/facebook_ads/ad_objects/ads_image_crops.rb +42 -0
- data/lib/facebook_ads/ad_objects/ads_insights.rb +225 -0
- data/lib/facebook_ads/ad_objects/ads_pixel.rb +64 -0
- data/lib/facebook_ads/ad_objects/ads_pixel_stats.rb +39 -0
- data/lib/facebook_ads/ad_objects/ads_pixel_stats_result.rb +50 -0
- data/lib/facebook_ads/ad_objects/agency_client_declaration.rb +48 -0
- data/lib/facebook_ads/ad_objects/android_app_link.rb +40 -0
- data/lib/facebook_ads/ad_objects/app_links.rb +43 -0
- data/lib/facebook_ads/ad_objects/broad_targeting_categories.rb +46 -0
- data/lib/facebook_ads/ad_objects/business.rb +242 -0
- data/lib/facebook_ads/ad_objects/business_ad_account_request.rb +37 -0
- data/lib/facebook_ads/ad_objects/business_page_request.rb +37 -0
- data/lib/facebook_ads/ad_objects/campaign.rb +211 -0
- data/lib/facebook_ads/ad_objects/conversion_action_query.rb +63 -0
- data/lib/facebook_ads/ad_objects/custom_audience.rb +166 -0
- data/lib/facebook_ads/ad_objects/custom_audience_ad_account.rb +36 -0
- data/lib/facebook_ads/ad_objects/custom_audience_data_source.rb +94 -0
- data/lib/facebook_ads/ad_objects/custom_audience_permission.rb +41 -0
- data/lib/facebook_ads/ad_objects/custom_audience_prefill_state.rb +39 -0
- data/lib/facebook_ads/ad_objects/custom_audience_session.rb +44 -0
- data/lib/facebook_ads/ad_objects/custom_audience_status.rb +38 -0
- data/lib/facebook_ads/ad_objects/custom_audiences_tos.rb +38 -0
- data/lib/facebook_ads/ad_objects/custom_conversion.rb +78 -0
- data/lib/facebook_ads/ad_objects/custom_conversion_stats_result.rb +50 -0
- data/lib/facebook_ads/ad_objects/day_part.rb +40 -0
- data/lib/facebook_ads/ad_objects/delivery_check.rb +40 -0
- data/lib/facebook_ads/ad_objects/delivery_check_extra_info.rb +39 -0
- data/lib/facebook_ads/ad_objects/delivery_estimate.rb +41 -0
- data/lib/facebook_ads/ad_objects/domain.rb +37 -0
- data/lib/facebook_ads/ad_objects/event.rb +74 -0
- data/lib/facebook_ads/ad_objects/event_source_group.rb +43 -0
- data/lib/facebook_ads/ad_objects/external_event_source.rb +38 -0
- data/lib/facebook_ads/ad_objects/flexible_targeting.rb +64 -0
- data/lib/facebook_ads/ad_objects/funding_source_details.rb +39 -0
- data/lib/facebook_ads/ad_objects/funding_source_details_coupon.rb +40 -0
- data/lib/facebook_ads/ad_objects/helpers/custom_audience_helpers.rb +170 -0
- data/lib/facebook_ads/ad_objects/hotel.rb +61 -0
- data/lib/facebook_ads/ad_objects/hotel_room.rb +44 -0
- data/lib/facebook_ads/ad_objects/id_name.rb +37 -0
- data/lib/facebook_ads/ad_objects/ios_app_link.rb +39 -0
- data/lib/facebook_ads/ad_objects/lead.rb +47 -0
- data/lib/facebook_ads/ad_objects/lead_gen_qualifier.rb +40 -0
- data/lib/facebook_ads/ad_objects/lead_gen_question.rb +40 -0
- data/lib/facebook_ads/ad_objects/lead_gen_question_option.rb +38 -0
- data/lib/facebook_ads/ad_objects/leadgen_form.rb +70 -0
- data/lib/facebook_ads/ad_objects/legacy_business_ad_account_request.rb +38 -0
- data/lib/facebook_ads/ad_objects/lookalike_spec.rb +43 -0
- data/lib/facebook_ads/ad_objects/minimum_budget.rb +41 -0
- data/lib/facebook_ads/ad_objects/offsite_pixel.rb +57 -0
- data/lib/facebook_ads/ad_objects/outcome_prediction_point.rb +40 -0
- data/lib/facebook_ads/ad_objects/partner_category.rb +51 -0
- data/lib/facebook_ads/ad_objects/product_catalog.rb +257 -0
- data/lib/facebook_ads/ad_objects/product_catalog_hotel_rooms_batch.rb +50 -0
- data/lib/facebook_ads/ad_objects/product_catalog_image_settings.rb +38 -0
- data/lib/facebook_ads/ad_objects/product_catalog_image_settings_operation.rb +37 -0
- data/lib/facebook_ads/ad_objects/product_catalog_pricing_variables_batch.rb +50 -0
- data/lib/facebook_ads/ad_objects/product_feed.rb +88 -0
- data/lib/facebook_ads/ad_objects/product_feed_schedule.rb +61 -0
- data/lib/facebook_ads/ad_objects/product_feed_upload.rb +48 -0
- data/lib/facebook_ads/ad_objects/product_feed_upload_error.rb +49 -0
- data/lib/facebook_ads/ad_objects/product_feed_upload_error_sample.rb +37 -0
- data/lib/facebook_ads/ad_objects/product_group.rb +98 -0
- data/lib/facebook_ads/ad_objects/product_item.rb +147 -0
- data/lib/facebook_ads/ad_objects/product_item_commerce_insights.rb +39 -0
- data/lib/facebook_ads/ad_objects/product_set.rb +49 -0
- data/lib/facebook_ads/ad_objects/product_variant.rb +39 -0
- data/lib/facebook_ads/ad_objects/profile_picture_source.rb +52 -0
- data/lib/facebook_ads/ad_objects/rate_card.rb +39 -0
- data/lib/facebook_ads/ad_objects/reach_estimate.rb +60 -0
- data/lib/facebook_ads/ad_objects/reach_frequency_prediction.rb +89 -0
- data/lib/facebook_ads/ad_objects/reach_frequency_spec.rb +42 -0
- data/lib/facebook_ads/ad_objects/rev_share_policy.rb +38 -0
- data/lib/facebook_ads/ad_objects/roas_cohorts_data.rb +41 -0
- data/lib/facebook_ads/ad_objects/roas_cohorts_per_cohort_interval_unit.rb +38 -0
- data/lib/facebook_ads/ad_objects/targeting.rb +133 -0
- data/lib/facebook_ads/ad_objects/targeting_dynamic_rule.rb +44 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location.rb +47 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_city.rb +43 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_custom_location.rb +50 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_electoral_district.rb +40 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_market.rb +40 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_place.rb +45 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_political_district.rb +40 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_region.rb +39 -0
- data/lib/facebook_ads/ad_objects/targeting_geo_location_zip.rb +41 -0
- data/lib/facebook_ads/ad_objects/targeting_product_audience_spec.rb +39 -0
- data/lib/facebook_ads/ad_objects/targeting_product_audience_sub_spec.rb +38 -0
- data/lib/facebook_ads/ad_objects/targeting_sentence_line.rb +38 -0
- data/lib/facebook_ads/ad_objects/transaction.rb +56 -0
- data/lib/facebook_ads/ad_objects/transaction_currency_amount.rb +39 -0
- data/lib/facebook_ads/ad_objects/user.rb +127 -0
- data/lib/facebook_ads/ad_objects/user_lead_gen_disclaimer_response.rb +38 -0
- data/lib/facebook_ads/ad_objects/user_lead_gen_field_data.rb +38 -0
- data/lib/facebook_ads/ad_objects/video_thumbnail.rb +42 -0
- data/lib/facebook_ads/ad_objects/web_app_link.rb +38 -0
- data/lib/facebook_ads/ad_objects/windows_app_link.rb +40 -0
- data/lib/facebook_ads/ad_objects/windows_phone_app_link.rb +39 -0
- data/lib/facebook_ads/api_request.rb +123 -0
- data/lib/facebook_ads/api_response.rb +47 -0
- data/lib/facebook_ads/batch_api/batch.rb +86 -0
- data/lib/facebook_ads/batch_api/batch_proxy.rb +67 -0
- data/lib/facebook_ads/config.rb +43 -0
- data/lib/facebook_ads/edge.rb +184 -0
- data/lib/facebook_ads/errors.rb +55 -0
- data/lib/facebook_ads/field_types/ad_object.rb +37 -0
- data/lib/facebook_ads/field_types/base.rb +33 -0
- data/lib/facebook_ads/field_types/boolean.rb +25 -0
- data/lib/facebook_ads/field_types/datetime.rb +47 -0
- data/lib/facebook_ads/field_types/double.rb +29 -0
- data/lib/facebook_ads/field_types/enum.rb +31 -0
- data/lib/facebook_ads/field_types/integer.rb +33 -0
- data/lib/facebook_ads/field_types/list.rb +57 -0
- data/lib/facebook_ads/field_types/object.rb +33 -0
- data/lib/facebook_ads/field_types/string_type.rb +34 -0
- data/lib/facebook_ads/field_types/upload_file.rb +121 -0
- data/lib/facebook_ads/field_types.rb +65 -0
- data/lib/facebook_ads/fields.rb +66 -0
- data/lib/facebook_ads/helpers/edge_helpers.rb +57 -0
- data/lib/facebook_ads/helpers/node_helpers.rb +80 -0
- data/lib/facebook_ads/helpers/shortcuts.rb +34 -0
- data/lib/facebook_ads/param_set.rb +74 -0
- data/lib/facebook_ads/ruby2patch.rb +27 -0
- data/lib/facebook_ads/session.rb +99 -0
- data/lib/facebook_ads/utils/utils.rb +29 -0
- data/lib/facebook_ads/version.rb +24 -0
- data/lib/facebook_ads/videos/video_io.rb +25 -0
- data/lib/facebook_ads/videos/video_request.rb +42 -0
- data/lib/facebook_ads.rb +72 -0
- metadata +337 -13
- data/lib/facebookads.rb +0 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
# FB:AUTOGEN
|
20
|
+
|
21
|
+
module FacebookAds
|
22
|
+
# This class is auto-genereated.
|
23
|
+
|
24
|
+
# For any issues or feature requests related to this class, please let us know
|
25
|
+
# on github and we'll fix in our codegen framework. We'll not be able to accept
|
26
|
+
# pull request for this class.
|
27
|
+
|
28
|
+
class WindowsAppLink < AdObject
|
29
|
+
|
30
|
+
field :app_id, 'string'
|
31
|
+
field :app_name, 'string'
|
32
|
+
field :package_family_name, 'string'
|
33
|
+
field :url, 'string'
|
34
|
+
has_no_id
|
35
|
+
has_no_get
|
36
|
+
has_no_post
|
37
|
+
has_no_delete
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
# FB:AUTOGEN
|
20
|
+
|
21
|
+
module FacebookAds
|
22
|
+
# This class is auto-genereated.
|
23
|
+
|
24
|
+
# For any issues or feature requests related to this class, please let us know
|
25
|
+
# on github and we'll fix in our codegen framework. We'll not be able to accept
|
26
|
+
# pull request for this class.
|
27
|
+
|
28
|
+
class WindowsPhoneAppLink < AdObject
|
29
|
+
|
30
|
+
field :app_id, 'string'
|
31
|
+
field :app_name, 'string'
|
32
|
+
field :url, 'string'
|
33
|
+
has_no_id
|
34
|
+
has_no_get
|
35
|
+
has_no_post
|
36
|
+
has_no_delete
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
require 'securerandom'
|
20
|
+
|
21
|
+
module FacebookAds
|
22
|
+
class APIRequest
|
23
|
+
attr_reader :method, :path, :session, :params,
|
24
|
+
:options, :callback, :batch_proxy
|
25
|
+
|
26
|
+
def initialize(method, path, session: nil, params: nil, options: nil)
|
27
|
+
@method = method
|
28
|
+
@path = path
|
29
|
+
@session = session
|
30
|
+
@params = params
|
31
|
+
@options = options
|
32
|
+
@batch_proxy = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns either APIResponse instantly if not within a batch, or
|
36
|
+
# a Proxy object to the result if a batch is present.
|
37
|
+
#
|
38
|
+
# ==== Examples
|
39
|
+
#
|
40
|
+
# Illustrate the behaviour of the method using examples. Indent examples:
|
41
|
+
#
|
42
|
+
# api_request APIRequest.new(:get, '123545') do |response|
|
43
|
+
# update_attributes(response)
|
44
|
+
# end
|
45
|
+
|
46
|
+
def execute(&block)
|
47
|
+
@callback = block if block
|
48
|
+
is_in_batch? ? enqueue_to_batch : execute_now
|
49
|
+
end
|
50
|
+
|
51
|
+
def execute_now
|
52
|
+
faraday_response = session.request(method, path, params)
|
53
|
+
create_response(faraday_response.status, faraday_response.headers, faraday_response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
def enqueue_to_batch
|
57
|
+
current_batch << self
|
58
|
+
@batch_proxy = BatchProxy.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_response(status, headers, body)
|
62
|
+
api_response = APIResponse.new(status, headers, body)
|
63
|
+
|
64
|
+
if status.to_i >= 500
|
65
|
+
raise ServerError.new(api_response)
|
66
|
+
elsif status.to_i >= 400
|
67
|
+
raise ClientError.new(api_response)
|
68
|
+
end
|
69
|
+
|
70
|
+
(callback ? callback[api_response] : api_response).tap do |result|
|
71
|
+
batch_proxy.set_result(result) if batch_proxy
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def batch_name
|
76
|
+
@batch_name ||= (options.dig(:batch_args, :name) || generate_batch_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_batch_name
|
80
|
+
SecureRandom.hex(4)
|
81
|
+
end
|
82
|
+
|
83
|
+
def current_batch
|
84
|
+
options.dig(:batch_args, :batch) || Batch.current_batch
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_in_batch?
|
88
|
+
!current_batch.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_batch_params
|
92
|
+
{
|
93
|
+
name: batch_name,
|
94
|
+
method: method.to_s.upcase,
|
95
|
+
relative_url: path,
|
96
|
+
body: batch_body,
|
97
|
+
omit_response_on_success: false,
|
98
|
+
attached_files: files.empty? ? nil : files.keys.join(','),
|
99
|
+
}.compact
|
100
|
+
end
|
101
|
+
|
102
|
+
# For Batch API
|
103
|
+
def batch_body
|
104
|
+
# TODO Have our own encoders or param flattener?
|
105
|
+
params = Faraday::Utils::ParamsHash[params_without_files]
|
106
|
+
params.to_query(Faraday::FlatParamsEncoder)
|
107
|
+
end
|
108
|
+
|
109
|
+
# For Batch API
|
110
|
+
def params_without_files
|
111
|
+
params.reject do |_,v|
|
112
|
+
v.is_a?(UploadIO)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# For Batch API
|
117
|
+
def files
|
118
|
+
params.select do |_,v|
|
119
|
+
v.is_a?(UploadIO)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
module FacebookAds
|
20
|
+
class APIResponse
|
21
|
+
attr_reader :status_code, :headers, :body
|
22
|
+
|
23
|
+
def initialize(status_code, headers, body)
|
24
|
+
@status_code = status_code
|
25
|
+
@headers = headers
|
26
|
+
@body = body
|
27
|
+
end
|
28
|
+
|
29
|
+
def result
|
30
|
+
is_json_response? ? JSON.parse(body) : body
|
31
|
+
end
|
32
|
+
|
33
|
+
def fb_trace_id
|
34
|
+
@headers[:x_fb_trace_id]
|
35
|
+
end
|
36
|
+
|
37
|
+
def raw_body
|
38
|
+
@body
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def is_json_response?
|
43
|
+
headers[:content_type] =~ /application\/json/ ||
|
44
|
+
headers[:content_type] =~ /text\/javascript/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
module FacebookAds
|
20
|
+
class Batch
|
21
|
+
attr_accessor :operations, :session, :last_api_response
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@operations = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def <<(api_req)
|
28
|
+
@operations << api_req
|
29
|
+
@session ||= api_req.session
|
30
|
+
api_req
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute
|
34
|
+
return [] if operations.empty?
|
35
|
+
api_response = APIRequest.new(:post, '', session: session, params: batch_args).execute_now
|
36
|
+
self.last_api_response = api_response
|
37
|
+
operations.zip(api_response.result).map do |req, res|
|
38
|
+
next unless res
|
39
|
+
|
40
|
+
begin
|
41
|
+
req.create_response(
|
42
|
+
res['code'],
|
43
|
+
convert_headers_to_hash(res['headers']),
|
44
|
+
res['body'])
|
45
|
+
rescue APIError => e
|
46
|
+
e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def batch_args
|
52
|
+
{batch: JSON.dump(operations_args)}.merge(files_args)
|
53
|
+
end
|
54
|
+
|
55
|
+
def operations_args
|
56
|
+
operations.map do |api_req|
|
57
|
+
api_req.to_batch_params
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def files_args
|
62
|
+
operations.map do |api_req|
|
63
|
+
api_req.files
|
64
|
+
end.reduce(&:merge)
|
65
|
+
end
|
66
|
+
|
67
|
+
class << self
|
68
|
+
attr_accessor :current_batch
|
69
|
+
|
70
|
+
def with_batch
|
71
|
+
new.tap do |current_batch|
|
72
|
+
self.current_batch = current_batch
|
73
|
+
yield if block_given?
|
74
|
+
self.current_batch = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def convert_headers_to_hash(headers)
|
81
|
+
Faraday::Utils::Headers.new(
|
82
|
+
Hash[headers.map {|h| [h['name'], h['value']]}]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
module FacebookAds
|
20
|
+
class BatchProxy < BasicObject
|
21
|
+
def initialize(api_request)
|
22
|
+
@api_request = api_request
|
23
|
+
@loaded = false
|
24
|
+
@result = nil
|
25
|
+
@exception = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_result(result)
|
29
|
+
@result = result
|
30
|
+
@loaded = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_error(exception)
|
34
|
+
@exception = exception
|
35
|
+
@loaded = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(method_name, *args, &block)
|
39
|
+
if @loaded
|
40
|
+
if @result
|
41
|
+
@result.__send__(method_name, *args, &block)
|
42
|
+
else
|
43
|
+
::Object.send(:raise, @exception)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
__attr_ref(method_name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def __api_request
|
51
|
+
@api_request
|
52
|
+
end
|
53
|
+
|
54
|
+
def __result
|
55
|
+
@result
|
56
|
+
end
|
57
|
+
|
58
|
+
def __loaded?
|
59
|
+
@loaded
|
60
|
+
end
|
61
|
+
|
62
|
+
def __attr_ref(attr_name)
|
63
|
+
# generate JSONPath of the attribute
|
64
|
+
"{result=#{__api_request.batch_name}:$.#{attr_name}}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
4
|
+
# copy, modify, and distribute this software in source code or binary form for use
|
5
|
+
# in connection with the web services and APIs provided by Facebook.
|
6
|
+
#
|
7
|
+
# As with any software that integrates with the Facebook platform, your use of
|
8
|
+
# this software is subject to the Facebook Platform Policy
|
9
|
+
# [http://developers.facebook.com/policy/]. This copyright notice shall be
|
10
|
+
# included in all copies or substantial portions of the software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
16
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
17
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
18
|
+
|
19
|
+
module FacebookAds
|
20
|
+
class Config
|
21
|
+
def self.setting(name, default = nil)
|
22
|
+
attr_writer name
|
23
|
+
|
24
|
+
define_method name do
|
25
|
+
unless instance_variable_defined?("@#{name}")
|
26
|
+
instance_variable_set("@#{name}", default)
|
27
|
+
end
|
28
|
+
instance_variable_get("@#{name}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
setting :server_host, FacebookAds::DEFAULT_HOST
|
33
|
+
setting :api_version, FacebookAds::DEFAULT_API_VERSION
|
34
|
+
setting :access_token, ENV['FB_ACCESS_TOKEN']
|
35
|
+
setting :app_secret, ENV['FB_APP_SECRET']
|
36
|
+
|
37
|
+
setting :log_api_bodies, false
|
38
|
+
|
39
|
+
def logger=(logger)
|
40
|
+
Utils.logger = logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|