File Coverage

blib/lib/Net/DSLProvider/Murphx.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Net::DSLProvider::Murphx;
2 2     2   57188 use strict;
  2         5  
  2         79  
3 2     2   10 use warnings;
  2         4  
  2         97  
4 2     2   2382 use HTML::Entities qw(encode_entities_numeric);
  2         26168  
  2         603  
5 2     2   20 use base 'Net::DSLProvider';
  2         5  
  2         1484  
6 2     2   13 use constant ENDPOINT => "https://xml.xps.murphx.com/";
  2         3  
  2         163  
7 2     2   4623 use LWP::UserAgent;
  2         135333  
  2         74  
8 2     2   6860 use XML::Simple;
  0            
  0            
9             use Time::Piece;
10             my $ua = LWP::UserAgent->new;
11             __PACKAGE__->mk_accessors(qw/clientid/);
12              
13             my %formats = (
14             selftest => { sysinfo => { type => "text" }},
15             availability => { cli => "phone", detailed => "yesno", ordertype =>
16             "text", postcode => "postcode"},
17             leadtime => { "product-id" => "counting", "order-type" => "text" },
18             order_status => {"order-id" => "counting" },
19             order_eventlog_history => { "order-id" => "counting" },
20             order_eventlog_changes => { "date" => "datetime" },
21             woosh_request_oneshot => { "service-id" => "counting",
22             "fault-type" => "text", "has-worked" => "yesno", "disruptive" => "yesno",
23             "fault-time" => "datetime" },
24             woosh_list => { "service-id" => "counting" },
25             woosh_response => { "woosh-id" => "counting" },
26             change_password => { "service-id" => "counting", "password" => "password" },
27             service_actions => { "service-id" => "counting" },
28             service_details => { "service-id" => "counting", "detailed" => "yesno" },
29             service_status => { "service-id" => "counting", "order-id" => "counting" },
30             service_view => { "service-id" => "counting" },
31             service_usage_summary => { "service-id" => "counting",
32             "year" => "counting", "month" => "text" },
33             service_auth_log => { "service-id" => "counting", "rows" => "counting" },
34             service_session_log => { "service-id" => "counting", "rows" => "counting" },
35             service_eventlog_changes => { "start-date" => "datetime", "stop-date" => "datetime" },
36             service_eventlog_history => { "service-id" => "counting" },
37             service_terminate_session => { "service-id" => "counting" },
38             services_overusage => { "period" => "text", "limit" => "counting" },
39             speed_limit_enable => { "upstream-limit" => "counting",
40             "downstream-limit" => "counting", "service-id" => "counting" },
41             speed_limit_disable => { "service-id" => "counting" },
42             speed_limit_status => { "service-id" => "counting" },
43             service_suspend => { "service-id" => "counting", "reason" => "text" },
44             service_unsuspend => { "service-id" => "counting" },
45             walledgarden_status => { "service-id" => "counting" },
46             walledgarden_enable => { "service-id" => "counting", "redirect-to" => "ip-address" },
47             walledgarden_disable => { "service-id" => "counting" },
48             change_carelevel => { "service-id" => "counting", "care-level" => "text" },
49             requestmac => { "service-id" => "counting", "reason" => "text" },
50             modify_options => { "service-id" => "counting" },
51             cease => {
52             order => {
53             "service-id" => "counting", "reason" => "text",
54             "client-ref" => "text", "crd" => "datetime", "accepts-charges" => "yesno"
55             }
56             },
57             modify => {
58             order => {
59             "service-id" => "counting", "client-ref" => "text", "crd" => "date",
60             "prod-id" => "counting", "cli" => "phone",
61             attributes => { "care-level" => "text", "inclusive-transfer" => "counting",
62             "test-mode" => "yesno" },
63             }
64             },
65             provide => {
66             order => {
67             "client-ref" => "text", cli => "phone", "prod-id" => "counting",
68             crd => "datetime", username => "text",
69             attributes => {
70             password => "password", realm => "text",
71             "fixed-ip" => "yesno", "routed-ip" => "yesno",
72             "allocation-size" => "counting", "care-level" => "text",
73             "hardware-product" => "counting",
74             "max-interleaving" => "text", "test-mode" => "yesno",
75             "inclusive-transfer" => "counting", "pstn-order-id" => "text"
76             }
77             }, customer => {
78             (map { $_ => "text" } qw/title forename surname company building
79             street city county sub-premise/),
80             postcode => "postcode", telephone => "phone",
81             mobile => "phone", fax => "phone", email => "email"
82             }
83             },
84             migrate => {
85             order => {
86             "client-ref" => "text", cli => "phone", "prod-id" => "counting",
87             crd => "datetime", username => "text",
88             attributes => {
89             password => "password", realm => "text",
90             "fixed-ip" => "yesno", "routed-ip" => "yesno",
91             "allocation-size" => "counting", "care-level" => "text",
92             "hardware-product" => "counting",
93             "max-interleaving" => "text", "test-mode" => "yesno",
94             "mac" => "text", "losing-isp" => "text",
95             "inclusive-transfer" => "counting", "pstn-order-id" => "text"
96             }
97             }, customer => {
98             (map { $_ => "text" } qw/title forename surname company building
99             street city county sub-premise/),
100             postcode => "postcode", telephone => "phone",
101             mobile => "phone", fax => "phone", email => "email"
102             }
103             },
104             case_new => {
105             "service-id" => "counting", "service-type" => "text",
106             "appsource" => "text", "cli" => "phone", "client-id" => "counting",
107             "customer-id" => "counting", "experienced" => "datetime",
108             "hardware-product" => "text", "os" => "text", "priority" => "text",
109             "problem-type" => "text", "reported" => "text",
110             "username" => "text",
111             },
112             case_view => { "case-id" => "counting" },
113             case_update => { "case-id" => "counting", "reason" => "text",
114             "priority" => "text"
115             },
116             case_history => { "case-id" => "counting" },
117             case_search => { "case-id" => "counting", "service-id" => "counting",
118             "customer-id" => "counting", "service-type" => "text",
119             "username" => "text", "partial-cli" => "text", engineer => "text",
120             "problem-type" => "text", "priority" => "text", status => "text",
121             },
122             customer_details => { "service-id" => "counting", "detailed" => "yesno" },
123             product_details => { "product-id" => "counting", "detailed" => "yesno" },
124             );
125              
126              
127             sub _request_xml {
128             my ($self, $method, $data) = @_;
129             my $id = time.$$;
130             my $xml = qq{
131            
132            
133             @{[$self->clientid]}
134             @{[$self->user]}
135             @{[$self->pass]}
136            
137             };
138              
139             my $recurse;
140             $recurse = sub {
141             my ($format, $data) = @_;
142             while (my ($key, $contents) = each %$format) {
143             if (ref $contents eq "HASH") {
144             if ($key) { $xml .= "\t\n"; }
145             $recurse->($contents, $data->{$key});
146             if ($key) { $xml .= "\t\n"; }
147             } else {
148             $xml .= qq{\t\t}.encode_entities_numeric($data->{$key})."\n"
149             if $data->{$key};
150             }
151             }
152             };
153             $recurse->($formats{$method}, $data);
154             $xml .= "\n";
155              
156             return $xml;
157             }
158              
159             sub _make_request {
160             my ($self, $method, $data) = @_;
161             my $xml = $self->_request_xml($method, $data);
162             my $request = HTTP::Request->new(POST => ENDPOINT);
163             $request->content_type('text/xml');
164             $request->content($xml);
165             if ($self->debug) { warn "Sending request: \n".$request->as_string;}
166             my $resp = $ua->request($request);
167             die "Request for Murphx method $method failed: " . $resp->message if $resp->is_error;
168             if ($self->debug) { warn "Got response: \n".$resp->content;}
169             my $resp_o = XMLin($resp->content);
170             if ($resp_o->{status}{no} > 0) { die $resp_o->{status}{text} };
171              
172             my $recurse = undef;
173             $recurse = sub {
174             my $input = shift;
175             while ( my ($oldkey, $contents) = each %$input ) {
176             my $newkey = $oldkey;
177             $newkey =~ s/-/_/g;
178             $recurse->($contents) if ref $contents eq 'HASH';
179             if ( ref $contents eq "ARRAY" ) {
180             for my $r ( @{$contents} ) {
181             $recurse->($r);
182             }
183             }
184             $input->{$newkey} = $contents;
185             delete $input->{$oldkey} if $oldkey =~ /-/;
186             }
187             };
188             $recurse->($resp_o);
189              
190             return $resp_o;
191             }
192              
193             =head2 services_available
194              
195             $murphx->services_available( cli => "02071112222" );
196              
197             Returns an hash showing the available services and line qualifications
198             as follows:
199              
200             ( qualification => {
201             classic => '2048000',
202             max => '4096000',
203             2plus => '5120000',
204             fttc => {
205             'up' => '6348800',
206             'down' => '27750400'
207             },
208             'first_date' => '2011-03-01'
209             },
210             product_id => {
211             'first_date' => '2011-03-01',
212             'max_speed' => '4096000',
213             'product_name' => 'DSL Product Name'
214             },
215             ...
216             )
217              
218             =cut
219              
220             sub services_available {
221             my ($self, %args) = @_;
222             $self->_check_params(\%args);
223              
224             %args = ( %args, detailed => "Y", ordertype => "migrate" );
225              
226             my $response = $self->_make_request("availability", \%args);
227              
228             my %crd = ();
229             while ( my $a = pop @{$response->{block}->{leadtimes}->{block}} ) {
230             my $pid = $a->{a}->{'product_id'}->{content};
231             $crd{$pid} = $a->{a}->{'first_date_text'}->{content};
232             }
233              
234             my %rv = ();
235              
236             my $a = $response->{block}->{availability}->{block};
237             foreach (qw/classic max 2plus fttc/) {
238             my $q = $a->{$_.'_qualification'};
239             if ( $_ ne 'fttc' ) {
240             $rv{qualification}->{$_} = $q->{a}->{'likely_max_speed'}->{content};
241             if ( $_ eq '2plus' && $q->{block}->{'name'} eq 'annex-m' ) {
242             $rv{qualification}->{$_.'_m_up'} = $q->{block}->{a}->{'likely_max_speed_up'}->{content};
243             $rv{qualification}->{$_.'_m_down'} = $q->{block}->{a}->{'likely_max_speed_down'}->{content};
244             }
245             $rv{qualification}->{top} = $rv{qualification}->{$_};
246             }
247             else {
248             $rv{qualification}->{$_}->{'down'} = $q->{a}->{'likely_max_speed_down'}->{content};
249             $rv{qualification}->{$_}->{'up'} = $q->{a}->{'likely_max_speed_up'}->{content};
250             }
251             }
252             return if ! $rv{qualification}->{classic} > 0; # There is no data to report!
253              
254             $rv{qualification}->{first_date} = $crd{1317}; # ADSL MAX Classic first available CRD
255              
256             # Now return the list of actual services available
257             while ( my $a = pop @{$response->{block}->{products}->{block}} ) {
258             $rv{$a->{a}->{'product_id'}->{content}} = {
259             first_date => $crd{$a->{a}->{'product_id'}->{content}},
260             product_name => $a->{a}->{'product_name'}->{content},
261             max_speed => $a->{a}->{'service_speed'}->{content},
262             };
263             }
264             return %rv;
265             }
266              
267             =head2 modify
268              
269             $murphx->modify(
270             "service-id" => "12345", "client-ref" => "myref", "prod-id" => "1000",
271             "crd" => "2009-12-31", "care-level" => "standard" "inclusive-transfer" => "3",
272             "test-mode" = "N" );
273              
274             Modify the service specificed in service-id. Parameters are as per the Murphx documentation
275              
276             Returns order-id for the modify order.
277              
278             =cut
279              
280             sub modify {
281             my ($self, %args) = @_;
282             $self->_check_params(\%args, qw/service-id client-ref myref prod-id
283             crd care-level inclusive-transfer test-mode / );
284              
285             my $response = $self->_make_request("modify", \%args);
286              
287             return $response->{a}->{"order_id"}->{content};
288             }
289              
290             =head2 change_password
291              
292             $murphx->change_password( "service-id" => "12345", "password" => "secret" );
293              
294             Changes the password for the ADSL login on the given service.
295              
296             Requires service-id and password
297              
298             Returns 1 for successful password change.
299              
300             =cut
301              
302             sub change_password {
303             my ($self, %args) = @_;
304             $self->_check_params(\%args, qw/service-id password/);
305              
306             my $response = $self->_make_request("change_password", \%args);
307              
308             return 1;
309             }
310              
311             =head2 woosh_response
312              
313             $murphx->woosh_response( "12345" );
314              
315             Obtains the results of a Woosh test, previously requested using
316             request_woosh(). Takes the ID of the woosh test as its only parameter.
317             Note that this will only return results for completed Woosh tests. Use
318             woosh_list() to determine if the woosh test is completed.
319              
320             Returns an hash containing a hash for each set of test results. See
321             Murphx documentation for details of the test result fields.
322              
323             =cut
324              
325             sub woosh_response {
326             my ($self, $id) = @_;
327             die "You must provide the woosh-id parameter" unless $id;
328             my $response = $self->_make_request("woosh_response", { "woosh-id" => $id });
329              
330             my %results = ();
331             foreach ( keys %{$response->{block}->{block}} ) {
332             my $b = $_;
333             foreach ( keys %{$response->{block}->{block}->{$b}->{a}} ) {
334             $results{$b}{$_} = $response->{block}->{block}->{$b}->{a}->{$_}->{content};
335             }
336             }
337             return \%results;
338             }
339              
340             =head2 woosh_list
341              
342             $murphx->woosh_list( "12345" );
343              
344             Obtain a list of all woosh tests requested for the given service-id and
345             their status.
346              
347             Requires service-id as the single parameter.
348              
349             Returns an array, each element of which is a hash containing the
350             following fields for each requested Woosh test:
351              
352             service-id woosh-id start-time stop-time status
353              
354             The array elements are sorted by date with the most recent being first.
355              
356             =cut
357              
358             sub woosh_list {
359             my ($self, $id) = @_;
360             die "You must provide the woosh-id parameter" unless $id;
361             my $response = $self->_make_request("woosh_list", { "woosh-id" => $id });
362              
363             my @list = ();
364             if ( ref $response->{block}->{block} eq "ARRAY" ) {
365             while ( my $b = shift @{$response->{block}->{block}} ) {
366             my %a = ();
367             foreach ( keys %{$b->{a}} ) {
368             $a{$_} = $b->{a}->{$_}->{content};
369             }
370             push @list, \%a;
371             }
372             } else {
373             my %a = ();
374             foreach ( keys %{$response->{block}->{block}->{a}} ) {
375             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
376             }
377             push @list, \%a;
378             }
379              
380             return @list;
381             }
382              
383             =head2 request_woosh
384              
385             $murphx->request_woosh( "service-id" => "12345", "fault-type" => "EPP",
386             "has-worked" => "Y", "disruptive" => "Y", "fault-time" => "2007-01-04 15:33:00");
387              
388             Alias to woosh_request_oneshot
389              
390             =cut
391              
392             sub request_woosh { goto &woosh_request_oneshot; }
393              
394             =head2 woosh_request_oneshot
395              
396             $murphx->woosh_request_oneshot( "service-id" => "12345", "fault-type" => "EPP",
397             "has-worked" => "Y", "disruptive" => "Y", "fault-time" => "2007-01-04 15:33:00");
398              
399             Places a request for Woosh test to be run on the given service.
400             Parameters are passed as a hash which must contain:
401              
402             service-id - ID of the service
403             fault-type - Type of fault to check. See Murphx documentation for available types
404             has-worked - Y if the service has worked in the past, N if it has not
405             disruptive - Y to allow Woosh to run a test which will be disruptive to the service.
406             fault-time - date and time (ISO format) the fault occured
407              
408             Returns a scalar which is the id of the woosh test. Use woosh_response
409             with this id to get the results of the Woosh test.
410              
411             =cut
412              
413             sub woosh_request_oneshot {
414             my ($self, %args) = @_;
415             $self->_check_params(\%args, qw/service-id fault-type has-worked
416             disruptive fault-time /);
417              
418             my $response = $self->_make_request("woosh_request_oneshot", \%args);
419              
420             return $response->{a}->{"woosh_id"}->{content};
421             }
422              
423             =head2 order_updates_since
424              
425             $murphx->order_updates_since( "date" => "2007-02-01 16:10:05" );
426              
427             Alias to order_eventlog_changes
428              
429             =cut
430              
431             sub order_updates_since { goto &order_eventlog_changes; }
432              
433             =head2 order_eventlog_changes
434              
435             $murphx->order_eventlog_changes( "date" => "2007-02-01 16:10:05" );
436              
437             Returns a list of events that have occurred on all orders since the provided date/time.
438              
439             The return is an date/time sorted array of hashes each of which contains the following fields:
440             order-id date name value
441              
442             =cut
443              
444             sub order_eventlog_changes {
445             my ($self, %args) = @_;
446             $self->_check_params(\%args, qw/date/);
447              
448             my $response = $self->_make_request("order_eventlog_changes", \%args);
449              
450             my @updates = ();
451              
452             if ( ref $response->{block}->{block} eq "ARRAY" ) {
453             while (my $b = shift @{$response->{block}->{block}} ) {
454             my %a = ();
455             foreach ( keys %{$b->{a}} ) {
456             $a{$_} = $b->{a}->{$_}->{content};
457             if ( $_ eq 'date' && $args{dateformat} ) {
458             my $d = Time::Piece->strptime($a{$_}, "%Y-%m-%d %H:%M:%S");
459             $a{$_} = $d->strftime($args{dateformat});
460             }
461             }
462             push @updates, \%a;
463             }
464             } else {
465             my %a = ();
466             foreach (keys %{$response->{block}->{block}->{a}} ) {
467             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
468             if ( $_ eq 'date' && $args{dateformat} ) {
469             my $d = Time::Piece->strptime($a{$_}, "%Y-%m-%d %H:%M:%S");
470             $a{$_} = $d->strftime($args{dateformat});
471             }
472             }
473             push @updates, \%a;
474             }
475             return @updates;
476             }
477              
478             =head2 auth_log
479              
480             $murphx->auth_log( "service-id" => '12345', "rows" => "5" );
481              
482             Alias for service_auth_log
483              
484             =cut
485              
486             sub auth_log { goto &service_auth_log; }
487              
488             =head2 service_auth_log
489              
490             $murphx->service_auth_log( "service-id" => '12345', "rows" => "5" );
491              
492             Gets the last n rows, as specified in the rows parameter, of authentication log entries for the service
493              
494             Returns an array, each element of which is a hash containing:
495             auth-date, username, result and, if the login failed, error-message
496              
497             =cut
498              
499             sub service_auth_log {
500             my ($self, %args) = @_;
501             $self->_check_params(\%args, qw/service-id rows/);
502              
503             my $response = $self->_make_request("service_auth_log", \%args);
504              
505             my @auth = ();
506             if ( ref $response->{block} eq "ARRAY" ) {
507             while ( my $r = shift @{$response->{block}} ) {
508             my %a = ();
509             foreach ( keys %{$r->{block}->{a}} ) {
510             $a{$_} = $r->{block}->{a}->{$_}->{content};
511             if ( $_ eq 'auth_date' && $args{dateformat} ) {
512             my $d = Time::Piece->strptime($r->{block}->{a}->{$_}->{content}, "%Y-%m-%d %H:%M:%S");
513             $a{$_} = $d->strftime($args{dateformat});
514             }
515             }
516             push @auth, \%a;
517             }
518             } else {
519             my %a = ();
520             foreach (keys %{$response->{block}->{block}->{a}} ) {
521             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
522             if ( $_ eq 'auth_date' && $args{dateformat} ) {
523             my $d = Time::Piece->strptime($response->{block}->{block}->{a}->{$_}->{content}, "%Y-%m-%d %H:%M:%S");
524             $a{$_} = $d->strftime($args{dateformat});
525             }
526             }
527             push @auth, \%a;
528             }
529              
530             return @auth;
531             }
532              
533             =head2 session_log
534              
535             $murphx->session_log( { } );
536              
537             Alias for service_session_log
538              
539             =cut
540              
541             sub session_log { goto &service_session_log; }
542              
543             =head2 service_session_log
544              
545             $murphx->service_session_log( "session-id" => "12345", "rows" => "5" );
546              
547             Gets the last entries in the session log for the service. The number of
548             entries is specified in the "rows" parameter.
549              
550             Returns an array each element of which is a hash containing:
551              
552             start-time stop-time download upload termination-reason
553              
554             =cut
555              
556             sub service_session_log {
557             my ($self, %args) = @_;
558             for (qw/service-id rows/) {
559             if (!$args{$_}) { die "You must provide the $_ parameter"; }
560             }
561              
562             my $response = $self->_make_request("service_session_log", \%args);
563              
564             my @sessions = ();
565             if ( ref $response->{block} eq "ARRAY" ) {
566             while ( my $r = shift @{$response->{block}} ) {
567             my %a = ();
568              
569             foreach ( keys %{$r->{block}->{a}} ) {
570             $a{$_} = $r->{block}->{a}->{$_}->{content};
571             if ( $args{dateformat} && ($_ eq 'start_time' || $_ eq "stop_time") ) {
572             my $d = Time::Piece->strptime($a{$_}, "%Y-%m-%d %H:%M:%S");
573             $a{$_} = $d->strftime($args{dateformat});
574             }
575             }
576              
577              
578             $a{"download"} = delete $a{"output-octets"};
579             $a{"upload"} = delete $a{"input-octets"};
580             push @sessions, \%a;
581             }
582             } else {
583             my %a = ();
584             foreach (keys %{$response->{block}->{block}->{a}} ) {
585             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
586             if ( $args{dateformat} && ($_ eq 'start_time' || $_ eq "stop_time") ) {
587             my $d = Time::Piece->strptime($a{$_}, "%Y-%m-%d %H:%M:%S");
588             $a{$_} = $d->strftime($args{dateformat});
589             }
590             }
591              
592             $a{"download"} = delete $a{"output_octets"};
593             $a{"upload"} = delete $a{"input_octets"};
594             push @sessions, \%a;
595             }
596             return @sessions;
597             }
598              
599             =head2 usage_summary
600              
601             $murphx->usage_summary( "service-id" =>'12345', "year" => '2009', "month" => '01' );
602              
603             Alias for service_usage_summary()
604              
605             =cut
606              
607             sub usage_summary { goto &service_usage_summary; }
608              
609             =head2 service_usage_summary
610              
611             $murphx->service_usage_summary( "service-id" =>'12345', "year" => '2009', "month" => '01' );
612              
613             Gets a summary of usage in the given month. Inputs are service-id, year, month.
614              
615             Returns a hash with the following fields:
616              
617             year, month, username, total-sessions, total-session-time,
618             total-input-octets, total-output-octets
619              
620             Input octets are upload bandwidth. Output octets are download bandwidth.
621              
622             Be warned that the total-input-octets and total-output-octets fields
623             returned appear to be MB rather than octets contrary to the Murphx
624             documentation.
625              
626             =cut
627              
628             sub service_usage_summary {
629             my ($self, %args) = @_;
630             for (qw/ service-id year month /) {
631             if ( ! $args{$_} ) { die "You must provide the $_ parameter"; }
632             }
633              
634             my $response = $self->_make_request("service_usage_summary", \%args);
635              
636             my %usage = ();
637             foreach ( keys %{$response->{block}->{a}} ) {
638             $usage{$_} = $response->{block}->{a}->{$_}->{content};
639             }
640             return %usage;
641             }
642              
643             =head2 service_terminate_session
644              
645             $murphx->service_terminate_session( "12345" );
646              
647             Terminates the current session on the given service-id.
648              
649             Returns 1 if successful
650              
651             =cut
652              
653             sub service_terminate_session {
654             my ($self, $id) = @_;
655             die "You must provide the service-id parameter" unless $id;
656              
657             my $response = $self->_make_request("service_terminate_session",
658             {"service-id" => $id});
659              
660             return 1;
661             }
662              
663             =head2 cease
664              
665             $murphx->cease( "service-id" => 12345, "reason" => "This service is no longer required"
666             "client-ref" => "ABX129", "crd" => "1970-01-01", "accepts-charges" => 'Y' );
667              
668             Places a cease order to terminate the ADSL service completely. Takes input as a hash.
669              
670             Required parameters are : service-id, crd, client-ref
671              
672             Returns order-id which is the ID of the cease order for tracking purposes.
673              
674             =cut
675              
676             sub cease {
677             my ($self, %args) = @_;
678             for (qw/service-id crd client-ref reason/) {
679             if (!$args{$_}) { die "You must provide the $_ parameter"; }
680             }
681              
682             # The cease method parameters have to be passed inside $data->{order}
683             my $data = { };
684             foreach (keys %args) {
685             $data->{order}{$_} = $args{$_};
686             }
687              
688             my $response = $self->_make_request("cease", $data);
689             return $response->{"order_id"}->{content};
690             }
691              
692             =head2 request_mac
693              
694             $murphx->requestmac( "service-id" => '12345', "reason" => "EU wishes to change ISP" );
695              
696             Obtains a MAC for the given service. Parameters are service-id and
697             reason the customer wants a MAC.
698              
699             Returns a hash comprising: mac, expiry-date
700              
701             =cut
702              
703             sub request_mac {
704             my ($self, %args) = @_;
705             for (qw/service-id reason/) {
706             if ( ! $args{$_} ) { die "You must provide the $_ parameter"; }
707             }
708              
709             my $response = $self->_make_request("requestmac", \%args);
710              
711             return (
712             mac => $response->{a}->{"mac"}->{content},
713             "expiry_date" => $response->{a}->{"expiry_date"}->{content}
714             );
715             }
716              
717             =head2 service_status
718              
719             $murphx->service_status( "12345" );
720              
721             Gets the current status for the given service id.
722              
723             Returns a hash containing:
724              
725             live, username, ip-address, session-established, session-start-date,
726             ping-test, average-latency
727              
728             =cut
729              
730             sub service_status {
731             my ($self, $id) = @_;
732             die "You must provide the service-id parameter" unless $id;
733             my $response = $self->_make_request("service_status",
734             { "service-id" => $id });
735              
736             my %status = ();
737             foreach ( keys %{$response->{block}->{a}} ) {
738             $status{$_} = $response->{block}->{a}->{$_}->{content};
739             }
740             return %status
741             }
742              
743             =head2 service_history
744              
745             $murphx->service_history( "12345" );
746              
747             Returns the full history for the given service as an array each element
748             of which is a hash:
749              
750             order-id name date value
751              
752             =cut
753              
754             sub service_history { goto &service_eventlog_history; }
755              
756             =head2 service_eventlog_history
757              
758             $murphx->service_eventlog_history( "12345" );
759              
760             Returns the full history for the given service as an array each element
761             of which is a hash:
762              
763             order-id name date value
764              
765             =cut
766              
767             sub service_eventlog_history {
768             my ($self, $id) = @_;
769             die "You must provide the service-id parameter" unless $id;
770             my @history = ();
771              
772             my $response = $self->_make_request("service_eventlog_history",
773             {"service-id" => $id });
774              
775             if ( ref $response->{block}->{block} eq "ARRAY" ) {
776             while ( my $a = pop @{$response->{block}->{block}} ) {
777             my %a = ();
778             foreach (keys %{$a->{a}}) {
779             $a{$_} = $a->{'a'}->{$_}->{'content'};
780             }
781             push @history, \%a;
782             }
783             } else {
784             my %a = ();
785             foreach (keys %{$response->{block}->{block}->{a}} ) {
786             $a{$_} = $response->{block}->{block}->{a}->{$_}->{'content'};
787             }
788             push @history, \%a;
789             }
790             return @history;
791             }
792              
793             =head2 services_history
794              
795             $murphx->services_history( "start-date" => "2007-01-01", "stop-date" => "2007-02-01" );
796              
797             Returns an array each element of which is a hash continaing the following data:
798              
799             service-id order-id date name value
800              
801             =cut
802              
803             sub services_history { goto &service_eventlog_changes; }
804              
805             =head2 service_eventlog_changes
806              
807             $murphx->service_eventlog_changes( "start-date" => "2007-01-01", "stop-date" => "2007-02-01" );
808              
809             Returns an array each element of which is a hash continaing the following data:
810              
811             service-id order-id date name value
812              
813             =cut
814              
815             sub service_eventlog_changes {
816             my ($self, %args) = @_;
817             for ( qw/ start-date stop-date /) {
818             if (!$args{$_}) { die "You must provide the $_ parameter"; }
819             }
820              
821             my $response = $self->_make_request("service_eventlog_changes", \%args);
822              
823             my @changes = ();
824             if ( ref $response->{block}->{block} eq 'ARRAY' ) {
825             while ( my $a = shift @{$response->{block}->{block}} ) {
826             my %u = ();
827             foreach (keys %{$a->{a}}) {
828             $u{$_} = $a->{'a'}->{$_}->{content};
829             }
830             push(@changes, \%u);
831             }
832             } else {
833             my %u = ();
834             foreach ( keys %{$response->{block}->{block}->{a}} ) {
835             $u{$_} = $response->{block}->{block}->{'a'}->{$_}->{content};
836             }
837             push(@changes, \%u);
838             }
839             return @changes;
840             }
841              
842              
843             =head2 order_status
844              
845             $murphx->order_status( '12345' );
846              
847             Gets status of an order. Input is the order-id from Murphx
848              
849             Returns a hash containing a hash order and a hash customer
850             The order hash contains:
851              
852             order-id, service-id, client-ref, order-type, cli, service-type, service,
853             username, status, start, finish, last-update
854              
855             The customer hash contains:
856              
857             forename, surname, address, city, county, postcode, telephone, building
858              
859             =cut
860              
861             sub order_status {
862             my ($self, $id) = @_;
863             die "You must provide the order-id parameter" unless $id;
864            
865             my $response = $self->_make_request("order_status", { "order-id" => $id });
866              
867             my %order = ();
868             foreach (keys %{$response->{block}->{order}->{a}} ) {
869             $order{order}{$_} = $response->{block}->{order}->{a}->{$_}->{content};
870             }
871             foreach (keys %{$response->{block}->{customer}->{a}} ) {
872             $order{customer}{$_} = $response->{block}->{customer}->{a}->{$_}->{content};
873             }
874             return %order;
875             }
876              
877             =head2 service_view
878              
879             $murphx->service_view ( "service-id" => '12345' );
880              
881             Combines the data from service_details, service_history and service_options
882              
883             Returns a hash as follows:
884              
885             %service = ( "service-details" => {
886             service-id => "", product-id => "",
887             ... },
888             "service-options" => {
889             "speed-limit" => "", "suspended" => "",
890             ... },
891             ""service-history" => {
892             [
893             { "event-date" => "", ... },
894             ...
895             ] },
896             "customer-details" => {
897             "title" => "", "forename", ... }
898             )
899              
900             See Murphx documentation for full details
901              
902             =cut
903              
904             sub service_view {
905             my ($self, %args) = @_;
906             die "You must provide the service-id parameter" unless $args{"service-id"};
907            
908             my $response = $self->_make_request("service_view", \%args);
909              
910             my %actions = $self->service_actions(%args);
911              
912             my %service = ();
913             foreach ( keys %{$response->{block}} ) {
914             my $b = $_;
915             if ( $response->{block}->{$b}->{block} ) {
916             my @history = ();
917             while ( my $h = pop @{$response->{block}->{$b}->{block}} ) {
918             my %a = ();
919             foreach ( keys %{$h->{a}} ) {
920             next if ( $_ =~ /(event_id|operator|operator_id)/ );
921             $a{$_} = $h->{a}->{$_}->{content};
922             }
923             push @history, \%a;
924             }
925             $service{$b} = \@history;
926             }
927             else {
928             foreach ( keys %{$response->{block}->{$b}->{a}} ) {
929             $service{$b}{$_} = $response->{block}->{$b}->{a}->{$_}->{content};
930             }
931             }
932             }
933             $service{"service_actions"} = \%actions;
934             return %service;
935             }
936              
937             =head2 service_details
938              
939             $murphx->service_details( '12345' );
940              
941             Obtains details of the service identified by "service-id" from Murphx
942              
943             Returns a hash with details including (but not limited to):
944             activation-date, cli, care-level, technology-type, service-id
945             username, password, live, product-name, ip-address, product-id
946             cidr
947              
948             =cut
949              
950             sub service_details {
951             my ($self, %args) = @_;
952             $self->_check_params(\%args, qw/service-id/);
953              
954             my $data = { detailed => 'Y', "service-id" => $args{"service-id"} };
955              
956             my $response = $self->_make_request("service_details", $data);
957              
958             my %details = ();
959             foreach (keys %{$response->{block}->{a}} ) {
960             $details{$_} = $response->{block}->{a}->{$_}->{content};
961             }
962             return %details;
963             }
964              
965             =head2 interleaving_status
966              
967             $murphx->interleaving_status( "service-id" => 12345 );
968              
969             Returns current interleaving status if available or undef;
970              
971             If not undef status can be one of:
972              
973             'opt-in', 'opt-out' or 'auto'
974              
975             =cut
976              
977             sub interleaving_status {
978             my ($self, %args) = @_;
979             $self->_check_params(\%args, qw/service-id/);
980              
981             my %d = $self->service_details( %args );
982             return $d{"max_interleaving"};
983             }
984              
985             =head2 order_history
986              
987             $murphx->order_history( 12345 );
988              
989             Alias to C
990              
991             =cut
992              
993              
994             sub order_history { goto &order_eventlog_history; }
995              
996             =head2 order_eventlog_history
997            
998             $murphx->order_eventlog_history( 12345 );
999              
1000             Gets order history
1001              
1002             Returns an array, each element of which is a hash showing the next
1003             update in date sorted order. The hash keys are date, name and value.
1004              
1005             =cut
1006              
1007             sub order_eventlog_history {
1008             my ($self, $order) = @_;
1009             return undef unless $order;
1010             my $response = $self->_make_request("order_eventlog_history", { "order-id" => $order });
1011              
1012             my @history = ();
1013              
1014             while ( my $a = shift @{$response->{block}{block}} ) {
1015             foreach (keys %{$a}) {
1016             my %u = ();
1017             $u{date} = $a->{'a'}->{'date'}->{'content'};
1018             $u{name} = $a->{'a'}->{'name'}->{'content'};
1019             $u{value} = $a->{'a'}->{'value'}->{'content'};
1020              
1021             push(@history, \%u);
1022             }
1023             }
1024             return @history;
1025             }
1026              
1027             =head2 services_overusage
1028              
1029             $murphx->services_overusage( "period" => "", "limit" => "100" );
1030              
1031             Returns an array each element of which is a hash detailing each service which has
1032             exceeded its usage cap. See the Murphx documentation for details.
1033              
1034             =cut
1035              
1036             sub services_overusage {
1037             my ($self, %args) = @_;
1038             die "You must provide the period parameter" unless $args{"period"};
1039              
1040             my $response = $self->_make_request("services_overusage", \%args);
1041              
1042             my @services = ();
1043             if ( ref $response->{block} eq "ARRAY" ) {
1044             while ( my $b = shift @{$response->{block}} ) {
1045             my %a = ();
1046             foreach (keys %{$b->{block}->{a}}) {
1047             $a{$_} = $b->{block}->{a}->{$_}->{content};
1048             }
1049             push @services, \%a;
1050             }
1051             } else {
1052             my %a = ();
1053             foreach ( keys %{$response->{block}->{block}->{a}} ) {
1054             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
1055             }
1056             push @services, \%a;
1057             }
1058             return @services;
1059             }
1060              
1061             =head2 speed_limit_status
1062              
1063             $murphx->speed_limit_status( 12345 );
1064              
1065             Returns either a hash reference or a description of the speed limit
1066             status.
1067              
1068             =cut
1069              
1070             sub speed_limit_status {
1071             my ($self, $id) = @_;
1072             die "You must provide the service-id parameter" unless $id;
1073              
1074             my $response = $self->_make_request("speed_limit_status",
1075             {"service-id" => $id});
1076              
1077             if ( $response->{a}->{content} ) { return $response->{a}->{content}; }
1078             else {
1079             my %status = ();
1080             foreach (keys %{$response->{a}} ) {
1081             $status{$_} = $response->{a}->{$_}->{content};
1082             }
1083             return \%status;
1084             }
1085             }
1086              
1087             =head2 speed_limit_enable
1088              
1089             $murphx->speed_limit_enable( "service-id" => 12345,
1090             "upstream-limit" => "768",
1091             "downstream-limit" => "768",
1092             );
1093              
1094             Set speed limits for the given service.
1095              
1096             =cut
1097              
1098             sub speed_limit_enable {
1099             my ($self, %args) = @_;
1100             for ( qw/service-id upstream-limit downstream-limit/ ) {
1101             die "You must provide the $_ parameter" unless $args{$_};
1102             }
1103              
1104             my $response = $self->_make_request("speed_limit_enable", \%args);
1105             return 1;
1106             }
1107              
1108             =head2 speed_limit_disable
1109              
1110             $murphx->speed_limit_disable( 12345 );
1111              
1112             Turn off speed limits for the given service.
1113              
1114             =cut
1115              
1116             sub speed_limit_disable {
1117             my ($self, %args) = @_;
1118             die "You must provide the service-id parameter" unless $args{"service-id"};
1119              
1120             my $response = $self->_make_request("speed_limit_disable", \%args);
1121             return 1;
1122             }
1123              
1124             =head2 service_unsuspend
1125              
1126             $murphx->service_unsuspend( 12345 );
1127              
1128             Unsuspend this broadband service.
1129              
1130             =cut
1131              
1132             sub service_unsuspend {
1133             my ($self, %args) = @_;
1134             die "You must provide the service-id parameter" unless $args{"service-id"};
1135              
1136             my $response = $self->_make_request("service_unsuspend", \%args);
1137             return 1;
1138             }
1139              
1140             =head2 service_suspend
1141              
1142             $murphx->service_suspend( "service-id" => 12345,
1143             reason => "I don't like them");
1144              
1145             Suspend this broadband service for the given reason.
1146              
1147             =cut
1148              
1149             sub service_suspend {
1150             my ($self, %args) = @_;
1151             for ( qw/service-id reason/) {
1152             die "You must provide the $_ parameter" unless $args{$_};
1153             }
1154              
1155             my $response = $self->_make_request("service_suspend", \%args);
1156             return 1;
1157             }
1158              
1159             =head2 walledgarden_status
1160              
1161             $murphx->walledgarden_status( "service-id" => 12345 );
1162              
1163             Returns true is the current service is subject to walled garden
1164             restrictions or undef if not.
1165              
1166             =cut
1167              
1168             sub walledgarden_status {
1169             my ($self, %args) = @_;
1170             die "You must provide the service-id parameter" unless $args{"service-id"};
1171              
1172             my $response = $self->_make_request("walledgarden_status", \%args);
1173              
1174             return 1 if $response->{a}->{walledgarden}->{content} eq 'enabled';
1175             return undef;
1176             }
1177              
1178             =head2 walledgarden_enable
1179              
1180             $murphx->walledgarden_enable( "service-id" => 12345, "ip-address" -> '192.168.1.1' );
1181              
1182             Redirects all (http and https) traffic to the specified IP address
1183              
1184             =cut
1185              
1186             sub walledgarden_enable {
1187             my ($self, %args) = @_;
1188             for ( qw/service-id ip-address/) {
1189             die "You must provide the $_ parameter" unless $args{$_};
1190             }
1191              
1192             my $response = $self->_make_request("walledgarden_enable", \%args);
1193             return 1;
1194             }
1195              
1196             =head2 walledgarden_disable
1197              
1198             $murphx->walledgarden_disable( "service-id" => 12345 );
1199              
1200             Disables the "walled garden" restriction on the service
1201              
1202             =cut
1203              
1204             sub walledgarden_disable {
1205             my ($self, %args) = @_;
1206             die "You must provide the service-id parameter" unless $args{"service-id"};
1207              
1208             my $response = $self->_make_request("walledgarden_disable", \%args);
1209             return 1;
1210             }
1211              
1212             =head2 change_carelevel
1213              
1214             $murphx->change_carelevel( "service-id" -> 12345, "care-level" => "enhanced" );
1215              
1216             Changes the care-level associated with a given service.
1217              
1218             care-level can be set to either standard or enhanced.
1219              
1220             Returns true is successful.
1221              
1222             =cut
1223              
1224             sub change_carelevel {
1225             my ($self, %args) = @_;
1226             $self->_check_params( \%args );
1227              
1228             my $response = $self->_make_request("change_carelevel", \%args);
1229             return 1;
1230             }
1231              
1232             =head2 care_level
1233              
1234             $murphx->carei_level( "service-id" -> 12345, "care-level" => "enhanced" );
1235              
1236             Changes the care-level associated with a given service.
1237              
1238             care-level can be set to either standard or enhanced.
1239              
1240             Returns true is successful.
1241              
1242             =cut
1243              
1244              
1245             sub care_level {
1246             my ($self, %args) = @_;
1247             $self->_check_params( \%args );
1248              
1249             $self->change_carelevel( %args );
1250             }
1251              
1252             =head2 service_actions
1253              
1254             $murphx->service_actions( "service-id" -> 12345 );
1255              
1256             Returns a hash detailing which actions can be taken on the given service.
1257              
1258             Each action has a corresponding function in this module.
1259              
1260             =cut
1261              
1262             sub service_actions {
1263             my ($self, %args) = @_;
1264              
1265             die "You must provide the service-id parameter" unless $args{"service-id"};
1266              
1267             my $response = $self->_make_request("service_actions", \%args);
1268              
1269             my %ret = ();
1270             foreach ( keys %{$response->{block}->{a}} ) {
1271             $ret{$_} = $response->{block}->{a}->{$_}->{content};
1272             }
1273             return %ret;
1274             }
1275              
1276             =head2 product_details
1277              
1278             $murphx->product_details( $product-id );
1279              
1280             Returns full product details for the given product id
1281              
1282             =cut
1283              
1284             sub product_details {
1285             my ($self, $id) = @_;
1286             die "You cannot must provide the product-id" unless $id;
1287              
1288             my $response = $self->_make_request("product_details",
1289             { "product-id" => $id, "detailed" => 'Y' });
1290              
1291             my %a = ();
1292             foreach ( keys %{$response->{block}->{a}} ) {
1293             $a{$_} = $response->{block}->{a}->{$_}->{content};
1294             }
1295             return %a
1296             }
1297              
1298             =head2 customer_details
1299              
1300             $murphx->customer_details($serviceId);
1301              
1302             Returns the customer details for a given service ID
1303              
1304             =cut
1305              
1306             sub customer_details {
1307             my ($self, $id) = @_;
1308              
1309             die "You cannot call _get_customer_id without the service-id" unless $id;
1310              
1311             my $response = $self->_make_request("customer_details",
1312             { "service-id"=> $id, "detailed" => 'Y' });
1313              
1314             my %a = ();
1315             foreach (keys %{$response->{block}->{a}}) {
1316             $a{$_} = $response->{block}->{a}->{$_}->{content};
1317             }
1318             return %a;
1319             }
1320              
1321             =head2 case_new
1322              
1323             $murphx->case_new( "service-id" => 12345, "service-type" => "adsl",
1324             "username" => "username@realm", "cli" => "02071112222",
1325             "os" => "Linux", "hardware-product" => "Other",
1326             "problem-type" => "Connection", "experienced" => "2010-01-01",
1327             "reported" => "User does not have sync", "priority" => "High" );
1328              
1329             =cut
1330              
1331             sub case_new {
1332             my ($self, %args) = @_;
1333             $self->_check_params(\%args, qw/service-id problem-type
1334             experienced reported priority/);
1335              
1336             $args{"client-id"} = $self->clientid;
1337             $args{"appsource"} = "XPS";
1338             $args{"service-type"} = "adsl";
1339              
1340             my %service = $self->service_details( %args );
1341              
1342             $args{username} = $service{username};
1343             $args{cli} = $service{cli};
1344              
1345             my $response = $self->_make_request("case_new", \%args);
1346              
1347             # This is not finished. I need to determine the correct part of $response to return
1348              
1349             return $response;
1350             }
1351              
1352             =head2 case_view
1353              
1354             $murphx->case_view( "case-id" => "12345" );
1355              
1356             Returns a hash containing details of an existing case
1357              
1358             =cut
1359              
1360             sub case_view {
1361             my ($self, %args) = @_;
1362             $self->_check_params(\%args, qw/case-id/);
1363              
1364             my $response = $self->_make_request("case_view", \%args);
1365            
1366             my %case = ();
1367             foreach (keys %{$response->{block}->{a}}) {
1368             $case{$_} = $response->{block}->{a}->{$_}->{content};
1369             }
1370             return %case;
1371             }
1372              
1373             =head2 case_search
1374              
1375             $murphx->case_search( "service-id" => 12345 );
1376              
1377             Returns basic details of all cases matching a given search.
1378              
1379             Search parameters can include the following (and must include at least
1380             one of them):
1381              
1382             case-id, service-id, customer-id, service-type, username, partial-cli,
1383             engineer, problem-type, priority or status
1384              
1385             Returns an array, each element of which is a hash providing basic
1386             details of the case. Use case_view and case_history to get more details.
1387              
1388             =cut
1389              
1390             sub case_search {
1391             my ($self, %args) = @_;
1392             my $args = join('|', keys %{$formats{case_search}});
1393             $self->_check_params(\%args, ($args));
1394              
1395             my $response = $self->_make_request("case_search", \%args);
1396              
1397             my @cases = ();
1398              
1399             if ( ref $response->{block}->{block} eq "ARRAY" ) {
1400             while ( my $b = shift @{$response->{block}->{block}} ) {
1401             my %a = ();
1402             foreach (keys %{$b->{a}} ) {
1403             $a{$_} = $b->{a}->{$_}->{content};
1404             }
1405             push @cases, \%a;
1406             }
1407             }
1408             else {
1409             my %a = ();
1410             foreach (keys %{$response->{block}->{block}->{a}} ) {
1411             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
1412             }
1413             push @cases, \%a;
1414             }
1415              
1416             return @cases;
1417             }
1418              
1419             =head2 case_history
1420              
1421             $murphx->case_history( "case-id" => "12345" );
1422              
1423             Returns a full history for the given case-id.
1424              
1425             Return is an array, each element of which is a hash detailing a
1426             specific update to the case.
1427              
1428             =cut
1429              
1430             sub case_history {
1431             my ( $self, %args ) = @_;
1432             $self->_check_params( \%args, qw/case-id/ );
1433              
1434             my $response = $self->_make_request( "case_history", \%args );
1435              
1436             my @cases = ();
1437              
1438             if ( ref $response->{block}->{block} eq "ARRAY" ) {
1439             while ( my $b = shift @{$response->{block}->{block}} ) {
1440             my %a = ();
1441             foreach (keys %{$b->{a}} ) {
1442             $a{$_} = $b->{a}->{$_}->{content};
1443             }
1444             push @cases, \%a;
1445             }
1446             }
1447             else {
1448             my %a = ();
1449             foreach (keys %{$response->{block}->{block}->{a}} ) {
1450             $a{$_} = $response->{block}->{block}->{a}->{$_}->{content};
1451             }
1452             push @cases, \%a;
1453             }
1454              
1455             return @cases;
1456             }
1457              
1458             =head2 case_update
1459              
1460             $murphx->case_update( "case-id" => "12345", "priority" => "High",
1461             "reason" => "More information about problem" );
1462              
1463             Updates the given case with update given in "reason".
1464              
1465             Returns 1 if update completed.
1466              
1467             =cut
1468              
1469             sub case_update {
1470             my ( $self, %args ) = @_;
1471             $self->_check_params(\%args, qw/case-id priority reason/);
1472              
1473             my $response = $self->_make_request("case_update", \%args);
1474              
1475             return 1;
1476             }
1477              
1478             =head2 regrade_options
1479              
1480             $murphx->regrade_options( "service-id" => "12345" );
1481              
1482             Returns an array containing details of the regrade options avaiulable on the
1483             given service using the module. Each element of the array is a hash with
1484             the same specification as returned by services_available
1485              
1486             =cut
1487              
1488             sub regrade_options {
1489             my ($self, %args) = @_;
1490              
1491             my $response = $self->_make_request("modify_options", \%args);
1492              
1493             my %crd = ();
1494             my @options = ();
1495             while ( my $l = shift @{$response->{block}->{leadtimes}->{block}} ) {
1496             $crd{$l->{a}->{"product-id"}->{content}} = $l->{a}->{"first-date-text"}->{content};
1497             }
1498              
1499             while ( my $p = shift @{$response->{block}->{products}->{block}} ) {
1500             push @options, {
1501             product_id => $p->{a}->{"product_id"}->{content},
1502             "product_name" => $p->{a}->{"product_name"}->{content},
1503             "first_date" => $crd{$p->{a}->{"product_id"}->{content}},
1504             "max_speed" => $p->{a}->{"service_speed"}->{content}
1505             };
1506             }
1507             return @options;
1508             }
1509              
1510             =head2 regrade
1511              
1512             $murphx->regrade( "service-id" => "12345",
1513             "prod-id" => 1595,
1514             "crd" => "2010-02-01" );
1515              
1516             Places an order to regrade the specified service to the defined prod-id
1517             on the crd specified. Use regrade_options first to determine which
1518             products are available and the earliest crd available.
1519              
1520             The parameters you may pass to this function are the same as for the
1521             modify function. See Murphx documentation for details.
1522              
1523             =cut
1524              
1525             sub regrade {
1526             my ($self, %args) = @_;
1527             $args{'client-ref'} = $args{'service-id'}."-regrade" unless $args{'client-ref'};
1528             $args{'care-level'} = "standard" unless $args{'care-level'};
1529              
1530             return $self->modify(%args);
1531             }
1532              
1533             =head2 order
1534              
1535             $murphx->order(
1536             # Customer details
1537             forename => "Clara", surname => "Trucker",
1538             building => "123", street => "Pigeon Street", city => "Manchester",
1539             county => "Greater Manchester", postcode => "M1 2JX",
1540             telephone => "01614960213",
1541             # Order details
1542             clid => "01614960213", "client-ref" => "claradsl",
1543             "prod-id" => $product, crd => $leadtime, username => "claraandhugo",
1544             password => "skyr153", "care-level" => "standard",
1545             realm => "surfdsl.net"
1546             );
1547              
1548             Submits an order for DSL to be provided to the specified phone line.
1549             Note that all the parameters above must be supplied. CRD is the
1550             requested delivery date in YYYY-mm-dd format; you are responsible for
1551             computing dates after the minimum lead time. The product ID should have
1552             been supplied to you by Murphx.
1553              
1554             Additional parameters are listed below and described in the integration
1555             guide:
1556              
1557             title street company mobile email fax sub-premise fixed-ip routed-ip
1558             allocation-size hardware-product max-interleaving test-mode
1559             inclusive-transfer
1560              
1561             If a C and C is passed, then the order is understood as a
1562             migration rather than a provision.
1563              
1564             Returns a hash describing the order.
1565              
1566             =cut
1567              
1568             sub order {
1569             my ($self, %data_in) = @_;
1570             # We expect it "flat" and arrange it into the right blocks as we check it
1571             my $data = {};
1572             for (qw/forename surname building city county postcode telephone/) {
1573             if (!$data_in{$_}) { die "You must provide the $_ parameter"; }
1574             $data->{customer}{$_} = $data_in{$_};
1575             }
1576             defined $data_in{$_} and $data->{customer}{$_} = $data_in{$_}
1577             for qw/title street company mobile email fax sub-premise/;
1578              
1579             for (qw/cli client-ref prod-id crd username/) {
1580             if (!$data_in{$_}) { die "You must provide the $_ parameter"; }
1581             $data->{order}{$_} = $data_in{$_};
1582             }
1583              
1584             for (qw/password realm care-level/) {
1585             if (!$data_in{$_}) { die "You must provide the $_ parameter"; }
1586             $data->{order}{attributes}{$_} = $data_in{$_};
1587             }
1588             defined $data_in{$_} and $data->{order}{attributes}{$_} = $data_in{$_}
1589             for qw/fixed-ip routed-ip allocation-size hardware-product pstn-order-id
1590             max-interleaving test-mode inclusive-transfer mac losing-isp/;
1591              
1592             my $response = undef;
1593             if ( defined $data_in{"mac"} && defined $data_in{"losing-isp"} ) {
1594             $response = $self->_make_request("migrate", $data);
1595             } else {
1596             $response = $self->_make_request("provide", $data);
1597             }
1598              
1599             my %order = ();
1600             foreach ( keys %{$response->{a}} ) {
1601             $order{$_} = $response->{a}->{$_}->{content};
1602             }
1603             return %order;
1604             }
1605              
1606             =head2 terms_and_conditions
1607              
1608             Returns the terms-and-conditions to be presented to the user for signup
1609             of a broadband product.
1610              
1611             =cut
1612              
1613             sub terms_and_conditions {
1614             return "XXX Get terms and conditions dynamically, or just put them here";
1615             }
1616              
1617             =head2 first_crd
1618              
1619             $murphx->first_crd( "order-type" => "provide", "product-id" => "1595" );
1620              
1621             Returns the first possible date in ISO format an order of the specified
1622             may be placed for.
1623              
1624             Required Parameters:
1625              
1626             order-type : provide, migrate in, modify or cease
1627             product-id : the Murphx product ID
1628              
1629             =cut
1630              
1631             sub first_crd {
1632             my ($self, %args) = @_;
1633              
1634             my %leadtime = $self->leadtime(%args);
1635              
1636             return $leadtime{"first_date_text"};
1637             }
1638              
1639             =head2 leadtime
1640              
1641             $murphx->leadtime( "order-type" => "provide", "product-id" => "1595" );
1642              
1643             Returns a hash detailing the leadtime and first date for an order of the
1644             given type and for the given product.
1645              
1646             Required Parameters:
1647              
1648             order-type : provide, migrate in, modify or cease
1649             product-id : the Murphx product ID
1650              
1651             Returns:
1652              
1653             leadtime : number of leadtime days
1654             first-date-int : first date as seconds since unix epoch
1655             first-date-text : first date in ISO format
1656              
1657             =cut
1658              
1659             sub leadtime {
1660             my ($self, %args) = @_;
1661              
1662             my $response = $self->_make_request("leadtime", \%args);
1663              
1664             my %lead = ();
1665              
1666             foreach (keys %{$response->{a}}) {
1667             $lead{$_} = $response->{a}->{$_}->{content};
1668             }
1669              
1670             return %lead;
1671             }
1672              
1673             1;