adparlor-facebook 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.gitlab-ci.yml +5 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +28 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +4 -0
  8. data/Gemfile +4 -0
  9. data/Gemfile.lock +136 -0
  10. data/Guardfile +13 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +164 -0
  13. data/Rakefile +3 -0
  14. data/adparlor-facebook.gemspec +38 -0
  15. data/bin/console +18 -0
  16. data/bin/gitlab_runner_specs.sh +22 -0
  17. data/bin/setup +7 -0
  18. data/lib/adparlor/facebook/api.rb +106 -0
  19. data/lib/adparlor/facebook/config.rb +24 -0
  20. data/lib/adparlor/facebook/error.rb +13 -0
  21. data/lib/adparlor/facebook/graph_api/activity.rb +11 -0
  22. data/lib/adparlor/facebook/graph_api/ad.rb +43 -0
  23. data/lib/adparlor/facebook/graph_api/ad_account.rb +168 -0
  24. data/lib/adparlor/facebook/graph_api/ad_creative.rb +22 -0
  25. data/lib/adparlor/facebook/graph_api/ad_image.rb +87 -0
  26. data/lib/adparlor/facebook/graph_api/ad_label.rb +12 -0
  27. data/lib/adparlor/facebook/graph_api/ad_preview.rb +15 -0
  28. data/lib/adparlor/facebook/graph_api/ad_set.rb +39 -0
  29. data/lib/adparlor/facebook/graph_api/ad_targeting_search.rb +64 -0
  30. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_education_major.rb +11 -0
  31. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_education_school.rb +11 -0
  32. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocation.rb +19 -0
  33. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocation_meta.rb +16 -0
  34. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocations/ad_city.rb +13 -0
  35. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocations/ad_country.rb +13 -0
  36. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocations/ad_geo_market.rb +13 -0
  37. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocations/ad_region.rb +13 -0
  38. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_geolocations/ad_zip_code.rb +13 -0
  39. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_interest.rb +11 -0
  40. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_interest_suggestion.rb +12 -0
  41. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_interest_validation.rb +18 -0
  42. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_locale.rb +11 -0
  43. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_radius_suggestion.rb +11 -0
  44. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_targeting_category.rb +18 -0
  45. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_work_employer.rb +11 -0
  46. data/lib/adparlor/facebook/graph_api/ad_targeting_types/ad_work_position.rb +11 -0
  47. data/lib/adparlor/facebook/graph_api/ad_video.rb +124 -0
  48. data/lib/adparlor/facebook/graph_api/ads_pixel.rb +22 -0
  49. data/lib/adparlor/facebook/graph_api/ads_pixel_stat.rb +25 -0
  50. data/lib/adparlor/facebook/graph_api/advertisable_application.rb +11 -0
  51. data/lib/adparlor/facebook/graph_api/app_event_type.rb +11 -0
  52. data/lib/adparlor/facebook/graph_api/application.rb +15 -0
  53. data/lib/adparlor/facebook/graph_api/batch_object.rb +147 -0
  54. data/lib/adparlor/facebook/graph_api/broad_targeting_category.rb +11 -0
  55. data/lib/adparlor/facebook/graph_api/business.rb +18 -0
  56. data/lib/adparlor/facebook/graph_api/campaign.rb +43 -0
  57. data/lib/adparlor/facebook/graph_api/collection_proxy.rb +36 -0
  58. data/lib/adparlor/facebook/graph_api/connection_object.rb +11 -0
  59. data/lib/adparlor/facebook/graph_api/custom_audience.rb +31 -0
  60. data/lib/adparlor/facebook/graph_api/custom_audience_tos.rb +11 -0
  61. data/lib/adparlor/facebook/graph_api/custom_audience_user.rb +85 -0
  62. data/lib/adparlor/facebook/graph_api/custom_conversion.rb +22 -0
  63. data/lib/adparlor/facebook/graph_api/delivery_estimate.rb +11 -0
  64. data/lib/adparlor/facebook/graph_api/fields/activity.rb +12 -0
  65. data/lib/adparlor/facebook/graph_api/fields/ad.rb +60 -0
  66. data/lib/adparlor/facebook/graph_api/fields/ad_account.rb +21 -0
  67. data/lib/adparlor/facebook/graph_api/fields/ad_creative.rb +23 -0
  68. data/lib/adparlor/facebook/graph_api/fields/ad_image.rb +14 -0
  69. data/lib/adparlor/facebook/graph_api/fields/ad_label.rb +11 -0
  70. data/lib/adparlor/facebook/graph_api/fields/ad_preview.rb +11 -0
  71. data/lib/adparlor/facebook/graph_api/fields/ad_set.rb +100 -0
  72. data/lib/adparlor/facebook/graph_api/fields/ad_video.rb +22 -0
  73. data/lib/adparlor/facebook/graph_api/fields/ads_pixel.rb +12 -0
  74. data/lib/adparlor/facebook/graph_api/fields/ads_pixel_stat.rb +11 -0
  75. data/lib/adparlor/facebook/graph_api/fields/advertisable_application.rb +17 -0
  76. data/lib/adparlor/facebook/graph_api/fields/app_event_type.rb +11 -0
  77. data/lib/adparlor/facebook/graph_api/fields/application.rb +31 -0
  78. data/lib/adparlor/facebook/graph_api/fields/broad_targeting_category.rb +12 -0
  79. data/lib/adparlor/facebook/graph_api/fields/business.rb +11 -0
  80. data/lib/adparlor/facebook/graph_api/fields/campaign.rb +17 -0
  81. data/lib/adparlor/facebook/graph_api/fields/connection_object.rb +16 -0
  82. data/lib/adparlor/facebook/graph_api/fields/custom_audience.rb +22 -0
  83. data/lib/adparlor/facebook/graph_api/fields/custom_audience_tos.rb +11 -0
  84. data/lib/adparlor/facebook/graph_api/fields/custom_audience_user.rb +14 -0
  85. data/lib/adparlor/facebook/graph_api/fields/custom_conversion.rb +14 -0
  86. data/lib/adparlor/facebook/graph_api/fields/delivery_estimate.rb +11 -0
  87. data/lib/adparlor/facebook/graph_api/fields/field_decorator.rb +51 -0
  88. data/lib/adparlor/facebook/graph_api/fields/insight.rb +16 -0
  89. data/lib/adparlor/facebook/graph_api/fields/instagram_account.rb +11 -0
  90. data/lib/adparlor/facebook/graph_api/fields/leadgen_form.rb +23 -0
  91. data/lib/adparlor/facebook/graph_api/fields/page.rb +121 -0
  92. data/lib/adparlor/facebook/graph_api/fields/page_and_place.rb +11 -0
  93. data/lib/adparlor/facebook/graph_api/fields/partner_category.rb +12 -0
  94. data/lib/adparlor/facebook/graph_api/fields/picture.rb +17 -0
  95. data/lib/adparlor/facebook/graph_api/fields/post.rb +17 -0
  96. data/lib/adparlor/facebook/graph_api/fields/product_audience.rb +12 -0
  97. data/lib/adparlor/facebook/graph_api/fields/product_catalog.rb +11 -0
  98. data/lib/adparlor/facebook/graph_api/fields/product_feed.rb +12 -0
  99. data/lib/adparlor/facebook/graph_api/fields/product_group.rb +11 -0
  100. data/lib/adparlor/facebook/graph_api/fields/product_item.rb +18 -0
  101. data/lib/adparlor/facebook/graph_api/fields/product_set.rb +13 -0
  102. data/lib/adparlor/facebook/graph_api/fields/reach_estimate.rb +11 -0
  103. data/lib/adparlor/facebook/graph_api/fields/reach_frequency_prediction.rb +24 -0
  104. data/lib/adparlor/facebook/graph_api/fields/targeting_sentence_line.rb +11 -0
  105. data/lib/adparlor/facebook/graph_api/fields/targeting_suggestion.rb +11 -0
  106. data/lib/adparlor/facebook/graph_api/fields/targeting_validation.rb +11 -0
  107. data/lib/adparlor/facebook/graph_api/fields/user_lead_gen_info.rb +18 -0
  108. data/lib/adparlor/facebook/graph_api/fields/video_thumbnail.rb +11 -0
  109. data/lib/adparlor/facebook/graph_api/graph_object.rb +140 -0
  110. data/lib/adparlor/facebook/graph_api/insight.rb +18 -0
  111. data/lib/adparlor/facebook/graph_api/instagram_account.rb +12 -0
  112. data/lib/adparlor/facebook/graph_api/leadgen_form.rb +10 -0
  113. data/lib/adparlor/facebook/graph_api/page.rb +27 -0
  114. data/lib/adparlor/facebook/graph_api/page_and_place.rb +11 -0
  115. data/lib/adparlor/facebook/graph_api/partner_category.rb +11 -0
  116. data/lib/adparlor/facebook/graph_api/picture.rb +15 -0
  117. data/lib/adparlor/facebook/graph_api/post.rb +17 -0
  118. data/lib/adparlor/facebook/graph_api/product_audience.rb +17 -0
  119. data/lib/adparlor/facebook/graph_api/product_catalog.rb +27 -0
  120. data/lib/adparlor/facebook/graph_api/product_feed.rb +11 -0
  121. data/lib/adparlor/facebook/graph_api/product_group.rb +11 -0
  122. data/lib/adparlor/facebook/graph_api/product_item.rb +11 -0
  123. data/lib/adparlor/facebook/graph_api/product_set.rb +26 -0
  124. data/lib/adparlor/facebook/graph_api/reach_estimate.rb +17 -0
  125. data/lib/adparlor/facebook/graph_api/reach_frequency_prediction.rb +18 -0
  126. data/lib/adparlor/facebook/graph_api/targeting_sentence_line.rb +11 -0
  127. data/lib/adparlor/facebook/graph_api/targeting_suggestion.rb +16 -0
  128. data/lib/adparlor/facebook/graph_api/targeting_validation.rb +16 -0
  129. data/lib/adparlor/facebook/graph_api/traits/methods.rb +64 -0
  130. data/lib/adparlor/facebook/graph_api/user_lead_gen_info.rb +11 -0
  131. data/lib/adparlor/facebook/graph_api/video_thumbnail.rb +11 -0
  132. data/lib/adparlor/facebook/graph_api.rb +9 -0
  133. data/lib/adparlor/facebook/version.rb +5 -0
  134. data/lib/adparlor/facebook.rb +9 -0
  135. data/solano.yml +15 -0
  136. metadata +391 -0
@@ -0,0 +1,121 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module Page
6
+ FIELDS = [
7
+ :id,
8
+ :about,
9
+ :access_token,
10
+ :ad_campaign,
11
+ :affiliation,
12
+ :app_id,
13
+ :app_links,
14
+ :artists_we_like,
15
+ :attire,
16
+ :awards,
17
+ :band_interests,
18
+ :band_members,
19
+ :best_page,
20
+ :bio,
21
+ :birthday,
22
+ :booking_agent,
23
+ :built,
24
+ :business,
25
+ :can_checkin,
26
+ :can_post,
27
+ :category,
28
+ :category_list,
29
+ :company_overview,
30
+ :contact_address,
31
+ :context,
32
+ :country_page_likes,
33
+ :cover,
34
+ :culinary_team,
35
+ :current_location,
36
+ :description,
37
+ :description_html,
38
+ :directed_by,
39
+ :display_subtext,
40
+ :emails,
41
+ :features,
42
+ :food_styles,
43
+ :founded,
44
+ :general_info,
45
+ :general_manager,
46
+ :genre,
47
+ :global_brand_page_name,
48
+ :global_brand_root_id,
49
+ :has_added_app,
50
+ :leadgen_tos_accepted,
51
+ :hometown,
52
+ :hours,
53
+ :impressum,
54
+ :influences,
55
+ :is_always_open,
56
+ :is_community_page,
57
+ :is_permanently_closed,
58
+ :is_published,
59
+ :is_unclaimed,
60
+ :is_verified,
61
+ :link,
62
+ :location,
63
+ :mission,
64
+ :mpg,
65
+ :name,
66
+ :name_with_location_descriptor,
67
+ :network,
68
+ :new_like_count,
69
+ :offer_eligible,
70
+ :parent_page,
71
+ :parking,
72
+ :payment_options,
73
+ :personal_info,
74
+ :personal_interests,
75
+ :pharma_safety_info,
76
+ :phone,
77
+ :plot_outline,
78
+ :press_contact,
79
+ :price_range,
80
+ :produced_by,
81
+ :products,
82
+ # NOTE: Documentation still supports these fields but all requests with them
83
+ # are failing. Removing as it is not currently in use in relevant applications
84
+ # :promotion_eligible,
85
+ # :promotion_ineligible_reason,
86
+ :public_transit,
87
+ :record_label,
88
+ :release_date,
89
+ :restaurant_services,
90
+ :restaurant_specialties,
91
+ :schedule,
92
+ :screenplay_by,
93
+ :season,
94
+ :starring,
95
+ :start_info,
96
+ :store_location_descriptor,
97
+ :store_number,
98
+ :studio,
99
+ :talking_about_count,
100
+ :engagement,
101
+ :single_line_address,
102
+ :place_type,
103
+ :unread_message_count,
104
+ :unread_notif_count,
105
+ :unseen_message_count,
106
+ :username,
107
+ :verification_status,
108
+ :voip_info,
109
+ :website,
110
+ :were_here_count,
111
+ :written_by,
112
+ :featured_video,
113
+ :checkins,
114
+ :likes,
115
+ :members
116
+ ]
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module PageAndPlace
6
+ FIELDS = [:id, :name, :name_with_location_descriptor].freeze
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module PartnerCategory
6
+ FIELDS = [:id, :name, :approximate_count, :path, :description, :source,
7
+ :partner, :type]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module Picture
6
+ FIELDS = [
7
+ :cache_key,
8
+ :height,
9
+ :is_silhouette,
10
+ :url,
11
+ :width
12
+ ]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module Post
6
+ FIELDS = [:id, :admin_creator, :application, :child_attachments, :call_to_action, :caption, :created_time, :description,
7
+ :feed_targeting, :from, :icon, :is_instagram_eligible, :is_hidden, :is_published, :link, :message, :message_tags,
8
+ :name, :picture, :place, :privacy, :properties, :shares, :source, :status_type, :story, :story_tags,
9
+ :targeting, :to, :type, :updated_time, :with_tags, :object_id, :full_picture, :actions, :likes, :attachments
10
+ ]
11
+
12
+ CREATE_FIELDS = FIELDS + [:scheduled_published_time]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductAudience
6
+ FIELDS = [:account_id]
7
+ CREATE_FIELDS = [:account_id, :description, :exclusions, :inclusions, :name, :product_set_id]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductCatalog
6
+ FIELDS = [:id, :access_status, :access_type, :business, :feed_count, :name, :permitted_roles, :product_count]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductFeed
6
+ FIELDS = [:id, :country, :created_time, :default_currency, :deletion_enabled, :delimiter,
7
+ :encoding, :file_name, :latest_upload, :name, :product_count, :schedule]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductGroup
6
+ FIELDS = [:id, :retailer_id, :variants]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductItem
6
+ FIELDS = [:id, :additional_image_urls, :age_group, :applinks, :availability, :brand,
7
+ :category, :color, :commerce_insights, :condition, :custom_data, :custom_label_0,
8
+ :custom_label_1, :custom_label_2, :custom_label_3, :custom_label_4, :description,
9
+ :expiration_date, :gender, :gtin, :image_url, :manufacturer_part_number, :material,
10
+ :name, :ordering_index, :pattern, :price, :product_feed, :product_type, :retailer_id,
11
+ :retailer_product_group_id, :review_rejection_reasons, :review_status, :sale_price,
12
+ :sale_price_end_date, :sale_price_start_date, :shipping_weight_unit,
13
+ :shipping_weight_value, :size, :start_date, :url, :visibility]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ProductSet
6
+ FIELDS = [:id, :filter, :name, :product_catalog, :product_count]
7
+ CREATE_FIELDS = [:name, :filter, :product_catalog_id]
8
+ UPDATE_FIELDS = [:name, :filter, :product_catalog_id]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ReachEstimate
6
+ FIELDS = [:users, :bid_estimations, :estimate_ready]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module ReachFrequencyPrediction
6
+ FIELDS = [:id, :account_id, :activity_status, :buying_type, :campaign_group_id, :campaign_id, :campaign_time_start,
7
+ :campaign_time_stop, :currency, :daily_impression_curve, :demo_breakdown, :destination_id,
8
+ :expiration_time, :external_budget, :external_impression, :external_maximum_budget, :external_maximum_impression,
9
+ :external_maximum_reach, :external_minimum_budget, :external_minimum_impression, :external_minimum_reach, :external_reach,
10
+ :frequency_cap, :frequency_distribution, :grp_audience_size, :grp_country_audience_size, :grp_dmas_audience_size,
11
+ :grp_points, :grp_ratio, :grp_reach_ratio, :grp_status, :holdout_percentage, :impression_curve, :instagram_destination_id,
12
+ :interval_frequency_cap, :interval_frequency_cap_reset_period, :is_bonus_media, :is_conversion_goal, :name, :objective_name,
13
+ :pause_periods, :placement_breakdown, :prediction_mode, :prediction_progress, :reference_id, :reservation_status, :status,
14
+ :story_event_type, :target_audience_size, :target_cpm, :target_spec, :time_created, :time_updated, :timezone_id,
15
+ :timezone_name, :topline_id]
16
+ CREATE_FIELDS = [:action, :budget, :campaign_group_id, :day_parting_schedule, :destination_id, :destination_ids, :end_time,
17
+ :frequency_cap, :impression, :interval_frequency_cap_reset_period, :num_curve_points, :objective, :prediction_mode,
18
+ :reach, :rf_prediction_id, :rf_prediction_id_to_release, :rf_prediction_id_to_share, :start_time, :stop_time,
19
+ :story_event_type, :target_spec]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module TargetingSentenceLine
6
+ FIELDS = [:id, :params, :targetingsentencelines]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module TargetingSuggestion
6
+ FIELDS = [:id, :audience_size, :description, :name, :path, :type]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module TargetingValidation
6
+ FIELDS = [:audience_size, :id, :name, :path, :type, :valid]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module UserLeadGenInfo
6
+ FIELDS = [
7
+ :id,
8
+ :ad_group_id,
9
+ :created_time,
10
+ :field_data,
11
+ :form_id,
12
+ :post
13
+ ]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ module Fields
5
+ module VideoThumbnail
6
+ FIELDS = [:id, :height, :is_preferred, :name, :scale, :uri, :width].freeze
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,140 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class GraphObject
5
+ include Fields::FieldDecorator
6
+ include Adparlor::Facebook::Api
7
+ attr_accessor :access_token
8
+
9
+ class << self
10
+ def read(attributes = {}, options = {})
11
+ self.get(new(attributes).path, options)
12
+ end
13
+
14
+ def create(attributes = {}, options = {})
15
+ obj = new(attributes)
16
+ obj.post(obj.path, options)
17
+ end
18
+
19
+ def update(attributes = {}, options = {})
20
+ obj = new(attributes)
21
+ obj.post(obj.update_path, options, 'UPDATE')
22
+ end
23
+
24
+ def destroy(attributes = {}, options = {})
25
+ obj = new(attributes)
26
+ obj.delete(obj.update_path, options)
27
+ end
28
+
29
+ # TODO: make each of the gets a read shift get into method on Adparlor::Facebook::Api
30
+ def get(path, options = {})
31
+ max_results = options.delete(:max_results)
32
+
33
+ unless max_results.nil?
34
+ options[:limit] ||= 100
35
+ options[:limit] = [max_results, options[:limit]].min
36
+ end
37
+
38
+ response = new.get(path.to_s, options).body
39
+ raise FbError.new(response['error'], 500) if response.key?('error')
40
+ response['data'] = response.values if options[:ids]
41
+
42
+ if response.key?('data')
43
+ respond_for_data(response, options[:limit], max_results)
44
+ else
45
+ obj = new(response)
46
+ obj.access_token ||= options[:access_token]
47
+ obj
48
+ end
49
+ end
50
+
51
+ def respond_for_data(response, limit, max_results)
52
+ if data_pass_through
53
+ new(response['data'])
54
+ else
55
+ return response['summary'] if response['summary']
56
+ data = parse_data_for_collection(response)
57
+ while response['paging'] && response['paging']['next']
58
+ if max_results.nil? || data.size < max_results
59
+ options = max_results.nil? ? {} : { limit: [(max_results - data.size), limit].min } # remaining limit
60
+ response = new.get(response['paging']['next'].delete('\\'), options).body
61
+ data += parse_data_for_collection(response)
62
+ else
63
+ break
64
+ end
65
+ end
66
+ data.map { |object| new(object) } || []
67
+ end
68
+ end
69
+
70
+ def parse_data_for_collection(response)
71
+ response['data']
72
+ end
73
+
74
+ def data_pass_through
75
+ false
76
+ end
77
+ end
78
+
79
+ def initialize(attributes = {})
80
+ self.class.validate_initialize_fields(*attributes.keys) if self.class.respond_to?(:validate_initialize_fields)
81
+ if self.class != AdImage && attributes[:source]
82
+ @files = {}
83
+ attach_file(attributes)
84
+ end
85
+ attributes.each { |key, value| instance_variable_set("@#{key}".to_sym, value) }
86
+ self
87
+ end
88
+
89
+ def batch
90
+ batch_api = BatchObject.new(self)
91
+ if block_given?
92
+ yield batch_api
93
+ batch_api.execute
94
+ else
95
+ batch_api
96
+ end
97
+ end
98
+
99
+ def create(path, options = {})
100
+ post(path, options)
101
+ end
102
+
103
+ def destroy(path, options = {})
104
+ delete(path, options)
105
+ end
106
+
107
+ def update(path, options = {})
108
+ post(path, options, 'UPDATE')
109
+ end
110
+
111
+ def to_hash
112
+ {}.tap do |h|
113
+ self.instance_variables.each do |v|
114
+ attribute = v.to_s.gsub('@','')
115
+ h[attribute] = self.send(attribute)
116
+ end
117
+ end
118
+ end
119
+
120
+ def to_json
121
+ self.to_hash.to_json
122
+ end
123
+
124
+ private
125
+
126
+ def attach_file(attributes = {})
127
+ return nil unless attributes[:source]
128
+ # Strips the query string when present
129
+ if %r{image}.match(MIME::Types.type_for(attributes[:source].split('?').first).first.content_type)
130
+ file = AdImage.new(source: attributes.delete(:source)).formatted_image
131
+ attributes[:image_file] = file.original_filename
132
+ attached_file = "file#{@files.length}"
133
+ @files[attached_file] = file
134
+ attached_file
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,18 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class Insight < GraphObject
5
+ include Fields::Insight
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ allow_method :read
9
+
10
+ def path
11
+ raise FbError.new('required parameter account_id missing', 500) unless account_id
12
+ body = instance_variables.each_with_object({}) { |var, hash| hash[var.to_s.sub(/@/, '').to_sym] = instance_variable_get(var) }
13
+ "/act_#{account_id}/insights?#{Faraday::NestedParamsEncoder.encode(body)}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class InstagramAccount < GraphObject
5
+ include Fields::InstagramAccount
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ allow_method :create
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class LeadgenForm < GraphObject
5
+ include Fields::LeadgenForm
6
+ field_attrs FIELDS
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class Page < GraphObject
5
+ include Fields::Page
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+
9
+ def promotable_posts
10
+ @promotable_posts ||= CollectionProxy.new(Post, "/#{id}/promotable_posts", access_token)
11
+ end
12
+
13
+ def picture
14
+ @picture ||= CollectionProxy.new(Picture, "/#{id}/picture", access_token)
15
+ end
16
+
17
+ def page_backed_instagram_accounts
18
+ @page_backed_instagram_accounts ||= CollectionProxy.new(InstagramAccount, "/#{id}/page_backed_instagram_accounts", access_token)
19
+ end
20
+
21
+ def leadgen_forms
22
+ @leadgen_forms ||= CollectionProxy.new(LeadgenForm, "/#{id}/leadgen_forms", access_token)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class PageAndPlace < GraphObject
5
+ include Fields::PageAndPlace
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class PartnerCategory < GraphObject
5
+ include Fields::PartnerCategory
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class Picture < GraphObject
5
+ include Fields::Picture
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+
9
+ def self.data_pass_through
10
+ true
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class Post < GraphObject
5
+ include Fields::Post
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ allow_local_method :destroy
9
+
10
+ def update_path
11
+ raise FbError.new('required parameter id missing', 500) unless @id
12
+ "/#{@id}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Adparlor
2
+ module Facebook
3
+ module GraphApi
4
+ class ProductAudience < GraphObject
5
+ include Fields::ProductAudience
6
+ include Traits::Methods
7
+ field_attrs FIELDS
8
+ allow_local_method :create
9
+
10
+ def path
11
+ raise FbError.new('required parameter account_id missing', 500) unless account_id
12
+ "/act_#{account_id}/product_audiences"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end