blib/lib/WWW/eNom/Role/Command/Raw.pm

filter: Statementstmt 46.3% 45 / 97 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 56.5% 13 / 23 Podpod 0.0% 0 / 2 totaltotal 35.1% 58 / 165 CC 18 SCAR 29.9
CC
18
Cov
34%
_serialize_xml_simple_response
56.0
_make_query_string
42.0
__ANON__
20.0
CRAP 19.9
« blib/lib/WWW/eNom/Contact.pm ↑ Summary blib/lib/WWW/eNom/Role/Command/Domain.pm »
1 package WWW::eNom::Role::Command::Raw;
2  
3 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 46 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 46 ▶use WWW::eNom::Types qw( HTTPTiny Str Strs );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 46 ▶use Data::Util qw( is_hash_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 46 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 46 ▶use XML::LibXML::Simple qw( XMLin );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 46 ▶use Mozilla::PublicSuffix qw( public_suffix );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 46 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 46 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 46 requires 'username', 'password', '_uri', 'response_type';
21  
22 46 our $VERSION = 'v2.6.0'; # VERSION
23 # ABSTRACT: Raw eNom API Commands
24  
25 46 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 # Create methods to support eNom API version 7.8:
27 46 Readonly my $COMMANDS => [qw(
28 AddBulkDomains AddContact AddDomainFolder AddDomainHeader AddHostHeader
29 AddToCart AdvancedDomainSearch AM_AutoRenew AM_Configure AM_GetAccountDetail
30 AM_GetAccounts AssignToDomainFolder AuthorizeTLD CalculateAllHostPackagePricing
31 CalculateHostPackagePricing CancelHostAccount CancelOrder CertChangeApproverEmail
32 CertConfigureCert CertGetApproverEmail CertGetCertDetail CertGetCerts CertModifyOrder
33 CertParseCSR CertReissueCert CertPurchaseCert CertResendApproverEmail
34 CertResendFulfillmentEmail Check CheckLogin CheckNSStatus CommissionAccount
35 Contacts CreateAccount CreateHostAccount CreateSubAccount DeleteAllPOPPaks DeleteContact
36 DeleteCustomerDefinedData DeleteDomainFolder DeleteDomainHeader DeleteFromCart
37 DeleteHostedDomain DeleteHostHeader DeleteNameServer DeletePOP3 DeletePOPPak
38 DeleteRegistration DeleteSubaccount DisableFolderApp DisableServices EnableFolderApp
39 EnableServices Extend Extend_RGP ExtendDomainDNS Forwarding GetAccountInfo GetAccountPassword
40 GetAccountValidation GetAddressBook GetAgreementPage GetAllAccountInfo GetAllDomains
41 GetAllHostAccounts GetAllResellerHostPricing GetBalance GetCartContent GetCatchAll GetCerts
42 GetConfirmationSettings GetContacts GetCusPreferences GetCustomerDefinedData GetCustomerPaymentInfo
43 GetDNS GetDNSStatus GetDomainCount GetDomainExp GetDomainFolderDetail GetDomainFolderList
44 GetDomainHeader GetDomainInfo GetDomainNameID GetDomains GetDomainServices GetDomainSLDTLD
45 GetDomainSRVHosts GetDomainStatus GetDomainSubServices GetDotNameForwarding GetExpiredDomains
46 GetExtAttributes GetExtendInfo GetFilePermissions GetForwarding GetGlobalChangeStatus
47 GetGlobalChangeStatusDetail GetHomeDomainList GetHostAccount GetHostAccounts GetHostHeader GetHosts
48 GetIDNCodes GetIPResolver GetMailHosts GetMetaTag GetNameSuggestions GetNews GetOrderDetail
49 GetOrderList GetPasswordBit GetPOP3 GetPOPExpirations GetPOPForwarding GetProductNews
50 GetProductSelectionList GetRegHosts GetRegistrationStatus GetRegLock GetRenew GetReport
51 GetResellerHostPricing GetResellerInfo GetServiceContact GetSPFHosts GetStorageUsage
52 GetSubAccountDetails GetSubAccountPassword GetSubAccounts GetSubaccountsDetailList GetTLDDetails
53 GetTLDList GetTransHistory GetWebHostingAll GetWhoisContact GetWPPSInfo GM_CancelSubscription
54 GM_CheckDomain GM_GetCancelReasons GM_GetControlPanelLoginURL GM_GetRedirectScript GM_GetStatuses
55 GM_GetSubscriptionDetails GM_GetSubscriptions GM_ReactivateSubscription GM_RenewSubscription
56 GM_UpdateBillingCycle GM_UpdateSubscriptionDetails HostPackageDefine HostPackageDelete HostPackageModify
57 HostPackageView HostParkingPage InsertNewOrder IsFolderEnabled ListDomainHeaders ListHostHeaders
58 ListWebFiles MetaBaseGetValue MetaBaseSetValue ModifyDomainHeader ModifyHostHeader ModifyNS
59 ModifyNSHosting ModifyPOP3 MySQL_GetDBInfo NameSpinner NM_CancelOrder NM_ExtendOrder
60 NM_GetPremiumDomainSettings NM_GetSearchCategories NM_ProcessOrder NM_Search
61 NM_SetPremiumDomainSettings ParseDomain PE_GetCustomerPricing PE_GetDomainPricing PE_GetEapPricing
62 PE_GetPOPPrice PE_GetPremiumPricing PE_GetProductPrice PE_GetResellerPrice PE_GetRetailPrice
63 PE_GetRetailPricing PE_GetRocketPrice PE_GetTLDID PE_SetPricing PP_CancelSubscription PP_CheckUpgrade
64 PP_GetCancelReasons PP_GetControlPanelLoginURL PP_GetStatuses PP_GetSubscriptionDetails PP_GetSubscriptions
65 PP_ReactivateSubscription PP_UpdateSubscriptionDetails PP_ValidatePassword Portal_GetDomainInfo
66 Portal_GetAwardedDomains Portal_GetToken Portal_UpdateAwardedDomains PreConfigure Purchase PurchaseHosting
67 PurchasePOPBundle PurchasePreview PurchaseServices PushDomain Queue_GetInfo Queue_GetExtAttributes
68 Queue_DomainPurchase Queue_GetDomains Queue_GetOrders Queue_GetOrderDetail RAA_GetInfo RAA_ResendNotification
69 RC_CancelSubscription RC_FreeTrialCheck RC_GetLoginToken RC_GetSubscriptionDetails RC_GetSubscriptions
70 RC_RebillSubscription RC_ResetPassword RC_SetBillingCycle RC_SetPassword RC_SetSubscriptionDomain
71 RC_SetSubscriptionName RefillAccount RegisterNameServer RemoveTLD RemoveUnsyncedDomains RenewPOPBundle
72 RenewServices RPT_GetReport SendAccountEmail ServiceSelect SetCatchAll SetCustomerDefinedData SetDNSHost
73 SetDomainSRVHosts SetDomainSubServices SetDotNameForwarding SetFilePermissions SetHosts SetIPResolver
74 SetPakRenew SetPassword SetPOPForwarding SetRegLock SetRenew SetResellerServicesPricing SetResellerTLDPricing
75 SetSPFHosts SetUpPOP3User SL_AutoRenew SL_Configure SL_GetAccountDetail SL_GetAccounts StatusDomain
76 SubAccountDomains SynchAuthInfo TEL_AddCTHUser TEL_GetCTHUserInfo TEL_GetCTHUserList TEL_GetPrivacy TEL_IsCTHUser
77 TEL_UpdateCTHUser TEL_UpdatePrivacy TLD_AddWatchlist TLD_DeleteWatchlist TLD_GetTLD TLD_GetWatchlist
78 TLD_GetWatchlistTlds TLD_Overview TLD_PortalGetAccountInfo TLD_PortalUpdateAccountInfo TM_Check TM_GetNotice
79 TM_UpdateCart TP_CancelOrder TP_CreateOrder TP_GetDetailsByDomain TP_GetOrder TP_GetOrderDetail TP_GetOrderReview
80 TP_GetOrdersByDomain TP_GetOrderStatuses TP_GetTLDInfo TP_ResendEmail TP_ResubmitLocked TP_SubmitOrder
81 TP_UpdateOrderDetail TS_AutoRenew TS_Configure TS_GetAccountDetail TS_GetAccounts UpdateAccountInfo
82 UpdateAccountPricing UpdateCart UpdateCusPreferences UpdateDomainFolder UpdateExpiredDomains
83 UpdateHostPackagePricing UpdateMetaTag UpdateNameServer UpdateNotificationAmount UpdatePushList
84 UpdateRenewalSettings ValidatePassword WBLConfigure WBLGetCategories WBLGetFields WBLGetStatus
85 WebHostCreateDirectory WebHostCreatePOPBox WebHostDeletePOPBox WebHostGetCartItem WebHostGetOverageOptions
86 WebHostGetOverages WebHostGetPackageComponentList WebHostGetPackageMinimums WebHostGetPackages WebHostGetPOPBoxes
87 WebHostGetResellerPackages WebHostGetStats WebHostHelpInfo WebHostSetCustomPackage WebHostSetOverageOptions
88 WebHostUpdatePassword WebHostUpdatePOPPassword WSC_GetAccountInfo WSC_GetAllPackages WSC_GetPricing WSC_Update_Ops
89 XXX_GetMemberId XXX_RemoveMemberId XXX_SetMemberId
90 )];
91  
92 has '_api_commands' => (
93 is => 'ro',
94 isa => Strs,
95 0 ▶ default => sub { $COMMANDS },
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 46 init_arg => undef,
97 );
98  
99 has '_ua' => (
100 is => 'ro',
101 isa => HTTPTiny,
102 lazy => 1,
103 0 ▶ default => sub { HTTP::Tiny->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 46 );
105  
106 sub BUILD {
107 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
108  
109 0 $self->install_methods();
110  
111 0 return;
112 }
113  
114 sub install_methods {
115 0 ▶ my $self = shift;
Subroutine install_methods: not called CC=2 SCAR=17.9
Pod undocumented
116  
117 0 for my $command (@{ $self->_api_commands }) {
118 $self->meta->add_method(
119 $command => sub {
120 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
121 0 ▶ my %args = @_ == 1 && is_hash_ref( $_[0] ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && is_hash_ref($_[0]) ? : 0 0 0
Condition0%0/3
@_ == 1 and is_hash_ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and is_hash_ref($_[0])
@_ == 1 is_hash_ref($_[0])
Truth table0%0/3
A and B
A= @_ == 1B= is_hash_ref($_[0])
ABresult
0X0
100
111
122  
123 0 my $uri = $self->_make_query_string( $command, \%args );
124 0 my $response = $self->_ua->get( $uri )->{content};
125  
126 # print STDERR "URI: $uri\n";
127 # print STDERR "Response: $response\n";
128  
129 0 ▶ if ( $self->response_type eq "xml_simple" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->response_type eq "xml_simple") 0 0 0
130 0 $response = $self->_serialize_xml_simple_response( $response );
131 }
132  
133 0 return $response;
134 }
135 0 );
136 };
137  
138 0 return;
139 }
140  
141 sub _make_query_string {
142 0 ▶ my $self = shift;
Subroutine _make_query_string: not called CC=6 SCAR=37.4
143 0 my $command = shift;
144 0 ▶ my %args = @_ == 1 && is_hash_ref( $_[0] ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && is_hash_ref($_[0]) ? : 0 0 0
Condition0%0/3
@_ == 1 and is_hash_ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and is_hash_ref($_[0])
@_ == 1 is_hash_ref($_[0])
Truth table0%0/3
A and B
A= @_ == 1B= is_hash_ref($_[0])
ABresult
0X0
100
111
145  
146 0 my $uri = $self->_uri;
147 0 ▶ if ( $command ne "CertGetApproverEmail" && exists $args{Domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command ne "CertGetApproverEmail" and exists $args{"Domain"}) 0 0 0
Condition0%0/3
$command ne "CertGetApproverEmail" and exists $args{"Domain"}
!ll&&!rl&&r
000
MC/DC0%0/2
$command ne "CertGetApproverEmail" and exists $args{"Domain"}
$command ne "CertGetApproverEmail" exists $args{"Domain"}
Truth table0%0/3
A and B
A= $command ne "CertGetApproverEmail"B= exists $args{"Domain"}
ABresult
0X0
100
111
148 0 @args{qw(SLD TLD)} = $self->_split_domain(delete $args{Domain});
149 }
150  
151 0 ▶ my $response_type = $self->response_type eq 'xml_simple' ? 'xml' : $self->response_type;
Branch: 1 branch
BranchTrueFalseTotal
$self->response_type eq 'xml_simple' ? : 0 0 0
152  
153 0 $uri->query_form(
154 command => $command,
155 uid => $self->username,
156 pw => $self->password,
157 responseType => $response_type,
158 %args,
159 );
160  
161 0 return $uri;
162 }
163  
164 sub _split_domain {
165 0 ▶ my $self = shift;
Subroutine _split_domain: not called CC=1 SCAR=6.9
166 0 my ( $domain ) = pos_validated_list( \@_, { isa => Str } );
167  
168 return try {
169 # Look for an eNom wildcard TLD:
170 0 ▶ if( $domain =~ qr|(.+)\.([*12@]+)$|x ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($domain =~ qr/(.+)\.([*12\@]+)$/x) 0 0 0
171 0 return ( $1, $2 );
172 }
173  
174 0 my $suffix = public_suffix($domain);
175 0 ▶ if( !$suffix ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($suffix) 0 0 0
176 0 croak 'Unable to find a suffix from the domain';
177 }
178  
179 # Finally, add in the neccesary API arguments:
180 0 my ( $sld ) = $domain =~ /^(.+)\.$suffix$/x;
181  
182 0 return ($sld, $suffix);
183 }
184 catch {
185 0 ▶ croak "Domain name, $domain, does not look like a valid domain.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
186 0 };
187 }
188  
189 sub _serialize_xml_simple_response {
190 0 ▶ my $self = shift;
Subroutine _serialize_xml_simple_response: not called CC=7 SCAR=40.3
191 0 my ( $response ) = pos_validated_list( \@_, { isa => Str } );
192  
193 0 $response = XMLin($response);
194  
195 0 ▶ $response->{errors} &&= [ values %{ $response->{errors} } ];
Condition0%0/2
$response->{"errors"} &&= [values %{$$response{"errors"};}]
!ll
00
MC/DC0%0/1
$response->{"errors"} &&= [values %{$$response{"errors"};}]
$response->{"errors"}
Truth table0%0/2
A
A= $response->{"errors"}
Aresult
00
11
196 0 ▶ $response->{responses} &&= $response->{responses}{response};
Condition0%0/3
$response->{"responses"} &&= $response->{"responses"}{"response"}
!ll&&!rl&&r
000
MC/DC0%0/2
$response->{"responses"} &&= $response->{"responses"}{"response"}
$response->{"responses"} $response->{"responses"}{"response"}
Truth table0%0/3
A &&= B
A= $response->{"responses"}B= $response->{"responses"}{"response"}
ABresult
0X0
100
111
197 $response->{responses} = [ $response->{responses} ]
198 0 ▶ if $response->{ResponseCount} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $response->{"ResponseCount"} == 1 0 0 0
199  
200 0 foreach my $key ( keys %{$response} ) {
201 0 ▶ next unless $key =~ /(.*?)(\d+)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /(.*?)(\d+)$/ 0 0 0
202  
203 0 ▶ $response->{$1} = undef if ref $response->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if ref $response->{$key} 0 0 0
204 0 $response->{$1}[ $2 - 1 ] = delete $response->{$key};
205 }
206  
207 0 return $response;
208 }
209  
210 46 1;
211  
212 __END__
213  
214 =pod
215  
216 =encoding utf8
217  
218 =head1 NAME
219  
220 WWW::eNom::Role::Command::Raw - Low Level Access to eNom API
221  
222 =head1 SYNOPSIS
223  
224 use WWW::eNom;
225  
226 my $eNom = WWW::eNom->new( ... );
227 my $response = $eNom->Check(
228 SLD => 'enom',
229 TLD => 'com',
230 );
231  
232 =head1 REQUIRES
233  
234 =over 4
235  
236 =item username
237  
238 =item password
239  
240 =item _uri
241  
242 =item response_type
243  
244 =back
245  
246 =head1 DESCRIPTION
247  
248 This role composes a series of methods into the consuming class (L<WWW::eNom>) that directly expose methods of the L<eNom|http://www.enom.com/APICommandCatalog/> API. It is the lowest level of access to the eNom API and is intended only for the most advanced usages that are not covered by other commands.
249  
250 B<NOTE> You almost never want to make this low level of a call. You really should be looking at the L<commands|WWW::eNom/COMMANDS> to find the specific method to accomplish your goals.
251  
252 =head1 METHODS
253  
254 Most of the eNom API Methods have been included and are exposed based on the name of the method as documented in L<eNom's API Reference Docs|http://www.enom.com/APICommandCatalog/API%20topics/api_alpha_list.htm>. If you really wish to use the eNom API directly this is how you would do it, but keep in mind you'll have to read the details of the documentation for that method and handle the parsing of request params and the response yourself. Again, you should try very hard to avoid doing this, if you find some functionalty that is not exposed through L<WWW::eNom> a bug report or pull request is your best bet.
255  
256 However, if your heart is set then let's use an example method to demonstrate how best to make use of these low level API calls.
257  
258 =head2 Check
259  
260 use WWW::eNom;
261  
262 my $eNom = WWW::eNom->new(
263 ...
264 response_type => 'xml_simple',
265 );
266  
267  my $response = $eNom->Check(
268 SLD => 'enom',
269 TLD => 'com',
270 );
271  
272 Although not required, it is recommend that you specify a response_type of 'xml_simple' when making low level requests. This will at least make the response a HashRef (rather than a string). This response should look very similar to the response documented by the specific method with eNom with the following modifications made to make the system easier to work with.
273  
274 =over 4
275  
276 =item "responses" returns an ArrayRef of HashRefs
277  
278 =item Keys which end with a number are transformed into an ArrayRef
279  
280 If you had a response:
281  
282 {
283 RRPText1 => 'Domain Not Available',
284 RRPText2 => 'Domain Available',
285 RRPText3 => 'Domain Not Available',
286 }
287  
288 This is automagically converted into...
289  
290 {
291 RRPText => [ 'Domain Not Available', 'Domain Available', 'Domain Not Available' ],
292 }
293  
294 This is especially important when looking at errors or the "ErrX" response. Rather than having the numbered responses, that is converted to an ArrayRef.
295  
296 =back
297  
298 These changes make a possible response look like:
299  
300 {
301 Domain => [qw(enom.com enom.net enom.org enom.biz enom.info)],
302 Command => "CHECK",
303 RRPCode => [qw(211 211 211 211 211)],
304 RRPText => [
305 "Domain not available",
306 "Domain not available",
307 "Domain not available",
308 "Domain not available",
309 "Domain not available"
310 ]
311 }
312  
313 However, keep in mind you will need to refer to the actual documentation from eNom because even similar methods could have vastly different responses.
314  
315 =for Pod::Coverage install_methods
316  
317 =cut
« blib/lib/WWW/eNom/Contact.pm ↑ Summary blib/lib/WWW/eNom/Role/Command/Domain.pm »