34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/adtraction/api/models/program.rb', line 34
def self.parse(data)
programs = []
mappings = {
"channelId" => :channel_id,
"programId" => :id,
"market" => :market,
"currency" => :currency,
"feed" => :feed,
"programName" => :name,
"programURL" => :url,
"currentSegment" => :current_segment,
"pendingActive" => :pending_active,
"cookieDuration" => :cookie_duration,
"adId" => :ad_id,
"compensations" => :compensations,
"logoURL" => :logo_url,
"trackingURL" => :tracking_url,
"category" => :category
}
data.each do |item|
program = self.new
mappings.each do |api_column, column|
program.send("#{column}=", item.fetch(api_column, nil))
end
program.approval_status = Adtraction::Api::Constants::APPROVAL_STATUS_ENUM.fetch(item.fetch("approvalStatus"))
program.email_marketing = Adtraction::Api::Constants::EMAIL_MARKETING_ENUM.fetch(item.fetch("emailMarketing"))
program.sem_marketing = Adtraction::Api::Constants::SEM_MARKETING_ENUM.fetch(item.fetch("semMarketing"))
program.social_marketing = Adtraction::Api::Constants::SOCIAL_MARKETING_ENUM.fetch(item.fetch("socialMarketing"))
program.cashback_marketing = Adtraction::Api::Constants::CASHBACK_MARKETING_ENUM.fetch(item.fetch("cashbackMarketing"))
program.coupon_marketing = Adtraction::Api::Constants::COUPON_MARKETING_ENUM.fetch(item.fetch("couponMarketing"))
program.compensations&.each do |compensation|
enum = Adtraction::Api::Constants::TRANSACTION_TYPE_ENUM.fetch(compensation["transactionType"], :unknown)
compensation["transactionType"] = enum unless enum.nil?
end
programs << program
end
return programs
end
|