File Coverage

blib/lib/Microsoft/AdCenter.pm
Criterion Covered Total %
statement 6 11 54.5
branch 0 2 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 17 52.9


line stmt bran cond sub pod time code
1             package Microsoft::AdCenter;
2             # Copyright (C) 2012 Xerxes Tsang
3             # This program is free software; you can redistribute it and/or modify it
4             # under the terms of Perl Artistic License.
5              
6 986     986   5003898 use strict;
  986         2880  
  986         88440  
7 986     986   12713 use warnings;
  986         2824  
  986         253350  
8              
9             =head1 NAME
10              
11             Microsoft::AdCenter - An interface which abstracts Microsoft adCenter API.
12              
13             =cut
14              
15             our $VERSION = '8.11';
16              
17             =head1 SYNOPSIS
18              
19             This collection of modules makes interacting with Microsoft adCenter APIs easier.
20              
21             Sample Usage:
22              
23             use Microsoft::AdCenter::V7::CampaignManagementService;
24             use Microsoft::AdCenter::V7::CampaignManagementService::Bid;
25             use Microsoft::AdCenter::V7::CampaignManagementService::Keyword;
26             use Microsoft::AdCenter::Retry;
27              
28             # Defines when and how to retry an failed API call due to a connection or internal server error
29             my $retry = Microsoft::AdCenter::Retry->new(
30             ErrorType => Microsoft::AdCenter::Retry->CONNECTION_ERROR | Microsoft::AdCenter::Retry->INTERNAL_SERVER_ERROR,
31             RetryTimes => 3,
32             WaitTime => 30
33             );
34              
35             # Create the service client
36             my $campaign_mgmt_service = Microsoft::AdCenter::V7::CampaignManagementService->new(
37             ApplicationToken => "your_application_token",
38             CustomerAccountId => "your_customer_account_id",
39             CustomerId => "your_customer_id",
40             DeveloperToken => "your_developer_token",
41             Password => "your_password",
42             UserName => "your_user_name",
43             RetrySettings => [$retry]
44             );
45              
46             # Create a Keyword object
47             my $keyword = Microsoft::AdCenter::V7::CampaignManagementService::Keyword->new
48             ->Text("some text")
49             ->BroadMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1))
50             ->ExactMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1));
51              
52             # Call AddKeywords
53             my $response = $campaign_mgmt_service->AddKeywords(
54             AdGroupId => "",
55             Keywords => [$keyword]
56             );
57              
58             # Check the response
59             my $keyword_ids = $response->KeywordIds;
60             ...
61              
62             =head1 OVERVIEW
63              
64             Microsoft adCenter API allows you to manage your adCenter account in an automated fashion rather than manually. The API is exposed as a standard SOAP service that you can make calls to. This set of modules is designed to make using the SOAP service easier than using SOAP::Lite (for example) directly. There are 2 main types of modules available. The service modules (AdministrationService, CampaignManagementService, CustomerManagementService, etc.) are used to make the actual calls to each of the SOAP services in the API. The other type of module provided are the complex type modules, each of which represents one of the complex types defined in one of the WSDLs of the SOAP service. Examples include Campaign, AdGroup, Ad, Keyword, etc.
65              
66             The calls you can make to the various services are documented on MSDN. See
67              
68             L
69              
70             Where the documentation indicates that a complex type must be passed in to a particular service call, you must pass in the appropriate Microsoft::AdCenter::ComplexType object. For example, CampaignManagementService->AddCampaigns requires that an array of Campaigns be passed in:
71              
72             use Microsoft::AdCenter::V7::CampaignManagementService;
73             use Microsoft::AdCenter::V7::CampaignManagementService::Campaign;
74              
75             # Create the service client
76             my $campaign_mgmt_service = Microsoft::AdCenter::V7::CampaignManagementService->new(
77             ApplicationToken => "your_application_token",
78             CustomerAccountId => "your_customer_account_id",
79             CustomerId => "your_customer_id",
80             DeveloperToken => "your_developer_token",
81             Password => "your_password",
82             UserName => "your_user_name"
83             );
84              
85             # Create a Campaign object
86             my $campaign = Microsoft::AdCenter::V7::CampaignManagementService::Campaign->new
87             ->BudgetType("MonthlyBudgetDivideDailyAcrossMonth")
88             ->ConversionTrackingEnabled("false")
89             ->DaylightSaving("true")
90             ->Description("the campaign description")
91             ->MonthlyBudget(1000)
92             ->Name("the campaign name")
93             ->TimeZone("EasternTimeUSCanada")
94              
95             # Call AddCampaigns
96             my $response = $campaign_mgmt_service->AddCampaigns(
97             AccountId => "",
98             Campaigns => [$campaign]
99             );
100              
101             # Check the response
102             my $campaign_ids = $response->CampaignIds;
103             ...
104              
105             Note that all simple types referenced in the WSDLs are automatically handled for you - just pass in an appropriate string, and let Microsoft::AdCenter do the rest.
106              
107             When a method expects an array of objects / strings / numbers / etc., you must pass an array reference.
108              
109             If the SOAP call succeeded, you will receive a response object. See the perldoc for the specific service client module for the return types.
110              
111             If a SOAP Fault is encountered (whenever a call fails), the service client will throw a Microsoft::AdCenter::SOAPFault object.
112              
113             =head1 METHODS
114              
115             There are no methods available in Microsoft::AdCenter directly. All functionality is exposed by the various service client modules and complex types.
116              
117             =head1 EXAMPLES
118              
119             =head2 Example 1 - Create a new campaign
120              
121             use Microsoft::AdCenter::V7::CampaignManagementService;
122             use Microsoft::AdCenter::V7::CampaignManagementService::Campaign;
123              
124             # Create the service client
125             my $campaign_mgmt_service = Microsoft::AdCenter::V7::CampaignManagementService->new
126             ->ApplicationToken("your_application_token")
127             ->CustomerAccountId("your_customer_account_id")
128             ->CustomerId("your_customer_id")
129             ->DeveloperToken("your_developer_token")
130             ->Password("your_password")
131             ->UserName("your_user_name");
132              
133             # Create a Campaign object
134             my $campaign = Microsoft::AdCenter::V7::CampaignManagementService::Campaign->new
135             ->BudgetType("MonthlyBudgetDivideDailyAcrossMonth")
136             ->ConversionTrackingEnabled("false")
137             ->DaylightSaving("true")
138             ->Description("the campaign description")
139             ->MonthlyBudget(1000)
140             ->Name("the campaign name")
141             ->TimeZone("EasternTimeUSCanada")
142              
143             # Call AddCampaigns
144             my $response = $campaign_mgmt_service->AddCampaigns(
145             AccountId => "",
146             Campaigns => [$campaign]
147             );
148              
149             # Check the response header
150             my $tracking_id = $campaign_mgmt_service->response_header->{TrackingId};
151              
152             # Check the response
153             my $campaign_ids = $response->CampaignIds;
154             ...
155              
156             =head2 Example 2 - Get accounts
157              
158             use Microsoft::AdCenter::V7::CustomerManagementService;
159              
160             # Create the service client
161             my $customer_mgmt_service = Microsoft::AdCenter::V7::CustomerManagementService->new(
162             UserName => "your_user_name",
163             Password => "your_password",
164             ApplicationToken => "your_application_token",
165             DeveloperToken => "your_developer_token"
166             );
167              
168             # Get accounts
169             my $response = $customer_mgmt_service->GetAccountsInfo(CustomerId => "your_customer_id");
170              
171             # Check the response
172             foreach my $account (@{$response->GetAccountsResult}) {
173             ...
174             }
175              
176             =head2 Example 3 - Error handling
177              
178             use Microsoft::AdCenter::V7::CampaignManagementService;
179             use Microsoft::AdCenter::V7::CampaignManagementService::Bid;
180             use Microsoft::AdCenter::V7::CampaignManagementService::Keyword;
181              
182             # Create the service client
183             my $campaign_mgmt_service = Microsoft::AdCenter::V7::CampaignManagementService->new(
184             ApplicationToken => "your_application_token",
185             CustomerAccountId => "your_customer_account_id",
186             CustomerId => "your_customer_id",
187             DeveloperToken => "your_developer_token",
188             Password => "INVALID PASSWORD", # An invalid password
189             UserName => "your_user_name"
190             );
191              
192             my $response;
193             eval {
194             $response = $campaign_mgmt_service->AddKeywords(
195             AdGroupId => "",
196             Keywords => [
197             Microsoft::AdCenter::V7::CampaignManagementService::Keyword->new
198             ->Text("some text")
199             ->BroadMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1))
200             ->ExactMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1))
201             ]
202             );
203             };
204             if (my $e = $@) {
205             print "Fault code: @{[$e->faultcode]}\n";
206             print "Fault string: @{[$e->faultstring]}\n";
207             print "Error messages:\n";
208             print $_->Message . "\n" foreach @{$e->detail->Errors};
209             }
210              
211             =head2 Example 4 - Retrying an API call when an expected temporary network issue comes up
212              
213             use Microsoft::AdCenter::V7::CampaignManagementService;
214             use Microsoft::AdCenter::V7::CampaignManagementService::Bid;
215             use Microsoft::AdCenter::V7::CampaignManagementService::Keyword;
216             use Microsoft::AdCenter::Retry;
217              
218             # Defines when and how to retry an failed API call due to a temporary network connection issue
219             my $retry = Microsoft::AdCenter::Retry->new(
220             ErrorType => Microsoft::AdCenter::Retry->CONNECTION_ERROR,
221             RetryTimes => 3,
222             WaitTime => 30,
223             ScalingWaitTime => 2,
224             Callback => sub { my $e = shift; warn "Successfully retried API call for " . __PACKAGE__ . " after error $e was caught"; }
225             );
226              
227             # Create the service client
228             my $campaign_mgmt_service = Microsoft::AdCenter::V7::CampaignManagementService->new(
229             ApplicationToken => "your_application_token",
230             CustomerAccountId => "your_customer_account_id",
231             CustomerId => "your_customer_id",
232             DeveloperToken => "your_developer_token",
233             Password => "your_password",
234             UserName => "your_user_name",
235             RetrySettings => [$retry]
236             );
237              
238             # Create a Keyword object
239             my $keyword = Microsoft::AdCenter::V7::CampaignManagementService::Keyword->new
240             ->Text("some text")
241             ->BroadMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1))
242             ->ExactMatchBid(Microsoft::AdCenter::V7::CampaignManagementService::Bid->new->Amount(0.1));
243              
244             # Call AddKeywords
245             my $response = $campaign_mgmt_service->AddKeywords(
246             AdGroupId => "",
247             Keywords => [$keyword]
248             );
249              
250             # Check the response
251             my $keyword_ids = $response->KeywordIds;
252             ...
253              
254             =head1 DEBUGGING
255              
256             If you'd like to see the SOAP requests and responses, or other debugging information available from SOAP::Lite, you can turn it on just as you would for SOAP::Lite. See perldoc SOAP::Trace. As an example, if you wanted to see all trace information available, you could add the following to the module or script you use Microsoft::AdCenter in:
257              
258             use SOAP::Lite +trace;
259              
260             =head1 AUTHOR
261              
262             Xerxes Tsang
263              
264             =head1 BUGS
265              
266             Please report any bugs or feature requests to
267             C, or through the web interface at
268             L.
269             I will be notified, and then you'll automatically be notified of progress on
270             your bug as I make changes.
271              
272             =head1 SUPPORT
273              
274             You can find documentation for this module with the perldoc command.
275              
276             perldoc Microsoft::AdCenter
277              
278             You can also look for information at:
279              
280             =over 4
281              
282             =item * AnnoCPAN: Annotated CPAN documentation
283              
284             L
285              
286             =item * CPAN Ratings
287              
288             L
289              
290             =item * RT: CPAN's request tracker
291              
292             L
293              
294             =item * Search CPAN
295              
296             L
297              
298             =back
299              
300             =head1 COPYRIGHT & LICENSE
301              
302             Copyright (C) 2010 Xerxes Tsang
303              
304             This program is free software; you can redistribute it and/or modify it under the terms of Perl Artistic License.
305              
306             =head1 TODO
307              
308             The TODO list is empty - if you have suggestions, please file a wishlist entry in RT (link above)
309              
310             =cut
311              
312             sub new {
313 0     0 1   my ($class, %args) = @_;
314 0 0         die "Cannot instantiate @{[ __PACKAGE__ ]} directly"
  0            
315             if $class eq __PACKAGE__;
316 0           my $self = bless %args, $class;
317 0           return $self;
318             }
319              
320             1; # End of Microsoft::AdCenter