[cl-soap-cvs] CVS update: cl-soap/test/test-google-adwords.lisp

Sven Van Caekenberghe scaekenberghe at common-lisp.net
Wed Sep 28 09:26:12 UTC 2005


Update of /project/cl-soap/cvsroot/cl-soap/test
In directory common-lisp.net:/tmp/cvs-serv22719/test

Modified Files:
	test-google-adwords.lisp 
Log Message:
updated test code

Date: Wed Sep 28 11:26:11 2005
Author: scaekenberghe

Index: cl-soap/test/test-google-adwords.lisp
diff -u cl-soap/test/test-google-adwords.lisp:1.11 cl-soap/test/test-google-adwords.lisp:1.12
--- cl-soap/test/test-google-adwords.lisp:1.11	Tue Sep 27 18:25:18 2005
+++ cl-soap/test/test-google-adwords.lisp	Wed Sep 28 11:26:11 2005
@@ -1,8 +1,8 @@
 ;;;; -*- mode: lisp -*-
 ;;;;
-;;;; $Id: test-google-adwords.lisp,v 1.11 2005/09/27 16:25:18 scaekenberghe Exp $
+;;;; $Id: test-google-adwords.lisp,v 1.12 2005/09/28 09:26:11 scaekenberghe Exp $
 ;;;;
-;;;; Some test on the Google AdWords API (not publically available)
+;;;; Some tests on the Google AdWords API (not publically available)
 ;;;;
 ;;;; Copyright (C) 2005 Sven Van Caekenberghe, Beta Nine BVBA. All Rights Reserved.
 ;;;;
@@ -13,15 +13,7 @@
 
 (in-package :cl-soap)
 
-;;; account parameters
-
-(defvar *google-adwords-email*)
-(defvar *google-adwords-password*)
-(defvar *google-adwords-user-agent*)
-(defvar *google-adwords-token*)
-(defvar *google-client-email*)
-
-;;; constants
+;;; XML namespaces setup
 
 (defconstant +google-adwords-ns-uri+ "https://adwords.google.com/api/adwords/v2")
 
@@ -32,18 +24,19 @@
    "email" "password" "useragent" "token" "clientEmail"
    ;; info service
    "getUsageQuotaThisMonth" "getUsageQuotaThisMonthResponse" "getUsageQuotaThisMonthReturn"
-   "getCampaigns" "getCampaign" "getBillingAddress")
+   "getCampaigns" "getCampaign" "getBillingAddress"
+   ;; optionally add more exports, but this is not really needed for wsdl-soap-call's
+   )
   (:documentation "Package for symbols in the Google Adwords API XML Namespace"))
 
 (defparameter *google-adwords-ns* (s-xml:register-namespace +google-adwords-ns-uri+ "google" :google))
 
-;;; basic WSDL parsing
-
-;;; ******************************************************************
-;;; apparently there are different XML Schema Defintion namespace URIs
-;;; Google is using 
+;;; ***************************************************************************************
+;;; apparently there are different XML Schema Defintion namespace URIs, Google is using 
 (s-xml:register-namespace "http://www.w3.org/2001/XMLSchema" "xsd" :xsd)
-;;; ****************************************************************************************
+;;; ***************************************************************************************
+
+;;; basic WSDL parsing
 
 (defparameter *google-adwords-api-wsdl-urls*
   (loop :for service :in '("CreativeService"
@@ -59,6 +52,26 @@
 (defun parse-all-wsdl ()
   (mapcar #'parse-wsdl-url *google-adwords-api-wsdl-urls*))
 
+;;; account parameters
+
+(defvar *google-adwords-email*)
+(defvar *google-adwords-password*)
+(defvar *google-adwords-user-agent*)
+(defvar *google-adwords-token*)
+(defvar *google-client-email*)
+
+(defun make-google-headers (&key 
+                            (email *google-adwords-email*)
+                            (password *google-adwords-password*)
+                            (user-agent *google-adwords-user-agent*)
+                            (token *google-adwords-token*)
+                            (client-email *google-client-email*))
+  `("email" ,email 
+    "password" ,password 
+    "useragent" ,user-agent
+    "token" ,token
+    "clientEmail" ,client-email))
+
 ;;; some test calls
 
 #+NIL
@@ -81,11 +94,7 @@
 (defun get-usage-quota-this-month ()
   (wsdl-soap-call (wsdl-cache-get "https://adwords.google.com:443/api/adwords/v2/InfoService?wsdl")
                   "getUsageQuotaThisMonth"
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,*google-client-email*)))
+                  :headers (make-google-headers)))
 
 #+NIL
 (defun get-method-cost (service method &optional (date (ut)))
@@ -113,11 +122,7 @@
                   :input `("service" ,service
                            "method" ,method
                            "date" ,date)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,*google-client-email*)))
+                  :headers (make-google-headers)))
 
 #+NIL
 (defun get-operation-count (start-date &optional (end-date start-date)))
@@ -127,11 +132,7 @@
                   "getUnitCount"
                   :input `("startDate" ,start-date
                            "endDate" ,end-date)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,*google-client-email*)))
+                  :headers (make-google-headers)))
 
 #+NIL
 (defun get-unit-count-for-method (service method &optional (start-date (ut)) (end-date start-date)))
@@ -165,15 +166,11 @@
                  :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
     (values result headers)))
 
-(defun get-all-adwords-campaigns (client-email)
+(defun get-all-adwords-campaigns (&optional (client-email *google-client-email*))
   (wsdl-soap-call (wsdl-cache-get "https://adwords.google.com:443/api/adwords/v2/CampaignService?wsdl")
                   "getAllAdWordsCampaigns"
                   :input '("dummy" 1)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,client-email)))
+                  :headers (make-google-headers :client-email client-email)))
 
 #+NIL
 (defun get-campaign (id client-email)
@@ -219,21 +216,13 @@
                                          keyword
                                        `("KeywordRequest" ("text" ,text "type" ,type "maxCpc" ,max-cpc))))
                                  keywords)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,*google-client-email*)))
+                  :headers (make-google-headers)))
 
 (defun get-all-adgroups (campaign-id)
   (wsdl-soap-call (wsdl-cache-get "https://adwords.google.com:443/api/adwords/v2/AdGroupService?wsdl")
                   "getAllAdGroups"
                   :input `("campaignID" ,campaign-id)
-                  :headers `("email" ,*google-adwords-email*
-                             "password" ,*google-adwords-password*
-                             "useragent" ,*google-adwords-user-agent*
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,*google-client-email*)))
+                  :headers (make-google-headers)))
 
 (defun add-campaign (client-email daily-budget status &key name language-targeting geo-targeting)
   ;; to be completed
@@ -241,11 +230,7 @@
                   "addCampaign"
                   ;; input placeholder !!
                   :input `(,daily-budget ,status name ,name ,language-targeting ,geo-targeting)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,client-email)))
+                  :headers (make-google-headers :client-email client-email)))
 
 (defun schedule-report-job (client-email report-job)
   ;; to be completed
@@ -253,10 +238,26 @@
                   "scheduleReportJob"
                   ;; input placeholder !!
                   :input `(,report-job)
-                  :headers `("email" ,*google-adwords-email* 
-                             "password" ,*google-adwords-password* 
-                             "useragent" ,*google-adwords-user-agent* 
-                             "token" ,*google-adwords-token*
-                             "clientEmail" ,client-email)))
+                  :headers (make-google-headers :client-email client-email)))
+
+(defun make-ad-group (&key max-cpc max-cpm name (status "Enabled") (id -1) (campaign-id -1))
+  (let (fields)
+    (when max-cpc
+      (push `("maxCpc" ,max-cpc) fields))
+    (when max-cpm
+      (push `("maxCpm" ,max-cpm) fields))
+    (push `("name" ,name) fields)
+    (push `("status" ,status) fields)
+    (push `("id" ,id) fields)
+    (push `("campaignId" ,campaign-id) fields)
+    (apply #'append fields)))
+
+(defun add-ad-group (campaign-id new-data)
+  (wsdl-soap-call (wsdl-cache-get "https://adwords.google.com:443/api/adwords/v2/AdGroupService?wsdl")
+                  "addAdGroup"
+                  :input
+                  `("campaignID" ,campaign-id "AdGroup" ,new-data)
+                  :headers
+                  (make-google-headers)))
 
 ;;;; eof




More information about the Cl-soap-cvs mailing list