Skip to content

Commit

Permalink
Merge branch 'release/v1.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
w00lf committed May 11, 2020
2 parents 8d09fb2 + 0eda722 commit 7828dd6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/admin/facebook_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
link_to('more', admin_parse_result_path(last_parse_result)) if last_parse_result.status == 'error'
end
end
column :account_status
column :disable_reason
column :daily_limit_updated_at
column :daily_limit do |obj|
if obj.daily_limit_updated_at
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/facebook_account_stats_retrieve_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def perform(date_unix, facebook_account_id)
date = Time.at(date_unix)
initialize_logger(facebook_account)
ad_account = ::FacebookAccountApiRepresentation.new(facebook_account: facebook_account, date: date, logger: logger)
facebook_account.update!(account_status: ad_account.formated_account_status,
disable_reason: ad_account.formated_disable_reason)

logger.info("Scanning #{ad_account.name}")

Expand Down
20 changes: 18 additions & 2 deletions app/representations/facebook_account_api_representation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class FacebookAccountApiRepresentation < FacebookAPIBaseRepresenter
201 => 'Any_active',
202 => 'Any_closed'
}
DISABLE_REASON = {
0 => 'NONE',
1 => 'ADS_INTEGRITY_POLICY',
2 => 'ADS_IP_REVIEW',
3 => 'RISK_PAYMENT',
4 => 'GRAY_ACCOUNT_SHUT_DOWN',
5 => 'ADS_AFC_REVIEW',
6 => 'BUSINESS_INTEGRITY_RAR',
7 => 'PERMANENT_CLOSE',
8 => 'UNUSED_RESELLER_ACCOUNT',
9 => 'UNUSED_ACCOUNT'
}

attr_accessor :time_range, :session, :ad_account, :object, :logger, :facebook_account

Expand All @@ -19,7 +31,7 @@ def initialize(facebook_account:, logger: Logger.new(STDOUT), date: nil)
@time_range = { 'since' => date.strftime('%Y-%m-%d'), 'until' => date.strftime('%Y-%m-%d') }
account_id = facebook_account.api_identificator
@session = FacebookAds::Session.new(access_token: facebook_account.api_token)
@object = FacebookAds::AdAccount.get("act_#{account_id}", %w[name id currency account_status], session)
@object = FacebookAds::AdAccount.get("act_#{account_id}", %w[name id currency account_status disable_reason], session)
@logger = logger
@facebook_account = facebook_account
end
Expand All @@ -39,6 +51,10 @@ def adcreatives(limit: 50, fields: %w[id object_id effective_object_story_id])
end

def formated_account_status
ACCOUNT_STATUS.fetch(account_status)
ACCOUNT_STATUS.fetch(account_status) rescue nil
end

def formated_disable_reason
DISABLE_REASON.fetch(disable_reason) rescue nil
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddAccountStatusAndDisableReasonToFacebookAccounts < ActiveRecord::Migration[5.1]
def change
add_column :facebook_accounts, :account_status, :string
add_column :facebook_accounts, :disable_reason, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20200422184653) do
ActiveRecord::Schema.define(version: 20200511133031) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -87,6 +87,8 @@
t.string "api_identificator"
t.string "daily_limit"
t.datetime "daily_limit_updated_at"
t.string "account_status"
t.string "disable_reason"
t.index ["facebook_group_account_id"], name: "index_facebook_accounts_on_facebook_group_account_id"
end

Expand Down

0 comments on commit 7828dd6

Please sign in to comment.