[cl-soap-cvs] CVS update: cl-soap/test/test-google-adwords.lisp
Sven Van Caekenberghe
scaekenberghe at common-lisp.net
Wed Sep 21 17:08:23 UTC 2005
Update of /project/cl-soap/cvsroot/cl-soap/test
In directory common-lisp.net:/tmp/cvs-serv31405/test
Modified Files:
test-google-adwords.lisp
Log Message:
added more code to actually implement wsd-soap-call for document oriented soap calls with xsd type descriptions
Date: Wed Sep 21 19:08:05 2005
Author: scaekenberghe
Index: cl-soap/test/test-google-adwords.lisp
diff -u cl-soap/test/test-google-adwords.lisp:1.4 cl-soap/test/test-google-adwords.lisp:1.5
--- cl-soap/test/test-google-adwords.lisp:1.4 Mon Sep 19 19:54:49 2005
+++ cl-soap/test/test-google-adwords.lisp Wed Sep 21 19:08:04 2005
@@ -1,6 +1,6 @@
;;;; -*- mode: lisp -*-
;;;;
-;;;; $Id: test-google-adwords.lisp,v 1.4 2005/09/19 17:54:49 scaekenberghe Exp $
+;;;; $Id: test-google-adwords.lisp,v 1.5 2005/09/21 17:08:04 scaekenberghe Exp $
;;;;
;;;; Some test on the Google AdWords API (not publically available)
;;;;
@@ -19,6 +19,7 @@
(defvar *google-adwords-password*)
(defvar *google-adwords-user-agent)
(defvar *google-adwords-token*)
+(defvar *google-client-email*)
;;; constants
@@ -28,15 +29,21 @@
(:nicknames "google")
(:export
;; headers
- "email" "password" "useragent" "token"
+ "email" "password" "useragent" "token" "clientEmail"
;; info service
- "getUsageQuotaThisMonth" "getUsageQuotaThisMonthResponse" "getUsageQuotaThisMonthReturn")
+ "getUsageQuotaThisMonth" "getUsageQuotaThisMonthResponse" "getUsageQuotaThisMonthReturn"
+ "getCampaigns" "getCampaign" "getBillingAddress")
(: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 (s-xml:register-namespace "http://www.w3.org/2001/XMLSchema" "xsd" :xsd)
+;;; ****************************************************************************************
+
(defparameter *google-adwords-api-wsdl-urls*
(loop :for service :in '("CreativeService"
"KeywordService"
@@ -51,9 +58,9 @@
(defun parse-all-wsdl ()
(mapcar #'parse-wsdl-url *google-adwords-api-wsdl-urls*))
-;;; manual calls
+;;; some test calls
-(defun getUsageQuotaThisMonth ()
+(defun get-usage-quota-this-month ()
(multiple-value-bind (result headers)
(soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/InfoService")
`((google:|email| ,*google-adwords-email*)
@@ -70,13 +77,135 @@
(error "Expected a <getUsageQuotaThisMonthResponse> element"))))
#+NIL
-(defun getUsageQuotaThisMonth ()
- ;; when we can handle the google type schema this will work ;-)
+(defun get-usage-quota-this-month ()
(wsdl-soap-call "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*)))
-
+ "token" ,*google-adwords-token*
+ "clientEmail" *google-client-email*)))
+
+(defun get-method-cost (service method &optional (date (ut)))
+ (multiple-value-bind (result headers)
+ (soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/InfoService")
+ `((google:|email| ,*google-adwords-email*)
+ (google:|password| ,*google-adwords-password*)
+ (google:|useragent| ,*google-adwords-user-agent*)
+ (google:|token| ,*google-adwords-token*))
+ `(google:|getMethodCost|
+ (google:|service| ,service)
+ (google:|method| ,method)
+ (google:|date| ,(lisp->xsd-date date)))
+ :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
+ (if (eql (lxml-get-tag result) 'google:|getMethodCostResponse|)
+ (let ((contents (lxml-find-tag 'google:|getMethodCostReturn| (rest result))))
+ (if contents
+ (values (parse-integer (second contents)) headers)
+ (error "Expected a <getMethodCostReturn> element")))
+ (error "Expected a <getMethodCostResponse> element"))))
+
+#+NIL
+(defun get-method-cost (service method &optional (date (ut)))
+ (wsdl-soap-call "https://adwords.google.com:443/api/adwords/v2/InfoService?wsdl"
+ "getMethodCost"
+ :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*)))
+
+(defun get-operation-count (start-date &optional (end-date start-date)))
+
+(defun get-unit-count (&optional (start-date (ut)) (end-date start-date))
+ (wsdl-soap-call "https://adwords.google.com:443/api/adwords/v2/InfoService?wsdl"
+ "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*)))
+
+(defun get-unit-count-for-method (service method &optional (start-date (ut)) (end-date start-date)))
+
+(defun get-billing-address (client-email)
+ (multiple-value-bind (result headers)
+ (soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/AccountService")
+ `((google:|email| ,*google-adwords-email*)
+ (google:|password| ,*google-adwords-password*)
+ (google:|useragent| ,*google-adwords-user-agent*)
+ (google:|token| ,*google-adwords-token*)
+ (google:|clientEmail| ,client-email))
+ `(google:|getBillingAddress|)
+ :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
+ (if (eql (lxml-get-tag result) 'google:|getBillingAddressResponse|)
+ (values (rest result) headers)
+ (error "Expected a <getBillingAddressResponse> element"))))
+
+(defun get-all-adwords-campaigns (client-email)
+ (multiple-value-bind (result headers)
+ (soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/CampaignService")
+ `((google:|email| ,*google-adwords-email*)
+ (google:|password| ,*google-adwords-password*)
+ (google:|useragent| ,*google-adwords-user-agent*)
+ (google:|token| ,*google-adwords-token*)
+ (google:|clientEmail| ,client-email))
+ `(google:|getAllAdWordsCampaigns|
+ (google:|dummy| "1"))
+ :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
+ (values result headers)))
+
+(defun get-campaign (id client-email)
+ (multiple-value-bind (result headers)
+ (soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/CampaignService")
+ `((google:|email| ,*google-adwords-email*)
+ (google:|password| ,*google-adwords-password*)
+ (google:|useragent| ,*google-adwords-user-agent*)
+ (google:|token| ,*google-adwords-token*)
+ (google:|clientEmail| ,client-email))
+ `(google:|getCampaign|
+ (google:|id| ,(princ-to-string id)))
+ :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
+ (values result headers)))
+
+(defun estimate-keyword-list (keywords)
+ "((<text> <type> <max-cpc>)*) where type is Broad|Phrase|Exact"
+ (multiple-value-bind (result headers)
+ (soap-call (make-soap-end-point "https://adwords.google.com:443/api/adwords/v2/TrafficEstimatorService")
+ `((google:|email| ,*google-adwords-email*)
+ (google:|password| ,*google-adwords-password*)
+ (google:|useragent| ,*google-adwords-user-agent*)
+ (google:|token| ,*google-adwords-token*))
+ `(google::|estimateKeywordList|
+ ,@(mapcar #'(lambda (keyword)
+ (destructuring-bind (text type max-cpc)
+ keyword
+ `(google::|keywordRequest|
+ (google::|text| ,text)
+ (google::|type| ,type)
+ (google::|maxCpc| ,max-cpc))))
+ keywords))
+ :envelope-attributes `(:|xmlns| ,+google-adwords-ns-uri+))
+ (values result headers)))
+
+(defun estimate-keyword-list (keywords)
+ "((<text> <type> <max-cpc>)*) where type is Broad|Phrase|Exact"
+ (wsdl-soap-call "https://adwords.google.com:443/api/adwords/v2/TrafficEstimatorService?wsdl"
+ "estimateKeywordList"
+ :input (mapcar #'(lambda (keyword)
+ (destructuring-bind (text type max-cpc)
+ 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*)))
+
;;;; eof
More information about the Cl-soap-cvs
mailing list