-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestAdWords.hs
167 lines (145 loc) · 3.92 KB
/
TestAdWords.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{-# LANGUAGE OverloadedStrings #-}
module Main where
import GHC.IO.Encoding
import AdWords
import AdWords.FS
import AdWords.Types
import AdWords.Details
import AdWords.Service
import AdWords.Auth
import AdWords.Auth.Server
import Network.OAuth.OAuth2
import Control.Monad.RWS
import Lens.Micro
import Data.Foldable (traverse_)
import Data.Map (Map)
import Data.Text (Text)
import Network.HTTP.Client
import Network.OAuth.OAuth2.TokenRequest (Errors)
import Data.Text.Prettyprint.Doc.Render.Text (putDoc)
import Data.Text.Prettyprint.Doc
import qualified Data.Map as Map
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.ByteString.Char8 as BS
testCreds :: InitialInfo
testCreds = defaultIInfo
"P3qxmMbAvMJuPpolIpsnHQ"
"288-897-8527"
call :: AdWords IO () -> IO Text
call = fmap go . withSaved "creds" . withCustomer "149-309-2425"
where go (_, _, res) = res
addCampaign = call $ do
refresh
printResponse CampaignService $ do
"mutate" #
"operations" # do
"operator" ## "ADD"
"operand" # do
"name" ## "camp1"
"budget" #
"budgetId" ## "1200785698"
"advertisingChannelType" ## "SEARCH"
"biddingStrategyConfiguration" #
"biddingStrategyId" ## "1573776619"
addBudget = call $ do
refresh
printResponse BudgetService $ do
"mutate" #
"operations" # do
"operator" ## "ADD"
"operand" # do
"name" ## "first budget"
"amount" #
"microAmount" ## "1000000000"
"status" ## "ENABLED"
addBiddingStrategy = call $ do
refresh
printResponse BiddingStrategyService $ do
"mutate" #
"operations" # do
"operator" ## "ADD"
"operand" # do
"name" ## "first bidding strategy"
"type" ## "TARGET_SPEND"
addAdGroup = call $ do
refresh
printResponse AdGroupService $
"mutate" #
"operations" # do
"operator" ## "ADD"
"operand" # do
"campaignId" ## "920518723"
"name" ## "adgroup1"
queries = call $ do
refresh
{-addCampaignCriterion 920518723 $ -}
{-Proximity (Right $ CityOnly "Bydgoszcz") KILOMETERS 20-}
-- addExpandedTextAd
-- 47620349193
-- "hd1"
-- "hd2"
-- "description"
-- "path1"
-- "path2"
-- ["https://time.is"]
{-pauseAd 47620349193 219215737667-}
{-enableAd 47620349193 219215737667-}
{-changeBudget 920518723 1200785698-}
{-changeBudget 920518723 1201521004-}
{-changeBidding 920518723 1573776619-}
{-changeBidding 920518723 1574236878-}
{-pauseAd 43187312846-}
{-enableAd 43187312846-}
campaigns
-- adGroups
{-adGroupAds-}
-- adDetails 219181330005
{-adRemove 219215737667 47620349193-}
{-biddingStrategies-}
{-adStats-}
{-campaignCriterions-}
{-budgets-}
{-campaignFeeds-}
{-adGroupFeeds-}
{-feeds-}
{-campaignGroupPerformanceTarget-}
-- >>= liftIO . putDoc . vsep . map dshow
>>= liftIO . putDoc . vsep . map dshow . responseBody
-- >>= liftIO . pprint . responseBody
serviceCall = call $ do
refresh
printResponse BudgetService $ do
"get" #
"selector" # do
"fields" ## "BudgetId"
"mutate" #
"operations" # do
"operator" ## "ADD"
"operand" #
"name" ## "onthenh"
xmlReport = call $ do
reportXML $ do
"selector" #
"fields" ## "Name"
"reportName" ## "custom report"
"reportType" ## "CAMPAIGN_GROUP_PERFORMANCE_REPORT"
"dateRangeType" ## "LAST_7_DAYS"
"downloadFormat" ## "CSV"
>>= liftIO . BL.putStrLn . responseBody
awqlReport = call $ do
refresh
reportAWQL
"select AdGroupId, Clicks, AveragePosition, Impressions, AverageCost from ADGROUP_PERFORMANCE_REPORT"
"CSV"
>>= liftIO . BL.putStrLn . responseBody
main = do
setLocaleEncoding utf8
-- awqlReport
{-serviceCall-}
{-xmlReport-}
{-printUrl-}
{-addBudget-}
{-addCampaign-}
{-addBiddingStrategy-}
{-addAdGroup-}
queries