Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 159 lines (110 sloc) 3.793 kB
e982f97 @yko first public release
yko authored
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Monitis;
6
7 use Getopt::Long;
8 use Pod::Usage;
9
10 my $opts = {};
11
12 my $result = GetOptions(
13 "api-key=s" => \$opts->{api},
14 "secret-key=s" => \$opts->{secret},
15 );
16
17 # Check for parameters
18 unless ($opts->{api} && $opts->{secret}) {
19 warn "Please, provide API key and secret\n";
20 pod2usage;
21 }
22
23 # Create API instance
24 my $api = Monitis->new(
25 secret_key => $opts->{secret},
26 api_key => $opts->{api}
27 );
28
29 my $param = shift(@ARGV) || '';
30
31 # Have numeric ID
32 if ($param =~ /^\d+$/) {
33 delete_account_by_id($api, $param);
34 exit;
35 }
36
37 # Make sure we have at least empty string
154fc08 @yko tidy
yko authored
38 $param ||= '';
e982f97 @yko first public release
yko authored
39
40 # Get all subaccounts and find one matching our email
41 my $accounts = $api->sub_accounts->get;
42 my $found;
43
44 foreach my $account (@$accounts) {
45 if ($account->{account} eq $param) {
46 $found = $account->{id};
47 last;
48 }
49 }
50
51 if ($found) {
52 warn "Found account '$param': id $found\n";
53 warn "Try to delete it...\n\n";
54 delete_account_by_id($api, $found);
55 exit;
56 }
57
58 if ($param) {
59 warn "Account '$param' not found\n";
60 }
61
62 # List existing accounts
63 warn "Existing accounts:\n";
64 warn "[$_->{id}]\t$_->{account}\n" for @$accounts;
65 warn "\n";
66
67 sub delete_account_by_id {
68 my ($api, $id) = @_;
69 my $response = $api->sub_accounts->delete(userId => $id);
70
71 my $error = $response->{error};
72 $error ||= $response->{status} if $response->{status} ne 'ok';
73
74 die <<END if $error;
75 Error occured while deleting account '$id':
76
77 $error
78
79 END
80
81 print "Account $id successfully deleted\n";
82
83 }
84 __END__
85
86 =head1 NAME
87
88 delete_subaccount.pl - delete subbaccount using Monitis API
89
90 =head1 SYNOPSIS
91
92 delete_subaccount.pl <id | account email>
93
94 Options (mandatory):
95 --api-key brief help message
96 --secret-key full documentation
97
98 If no email or id provided, prints list of existing accounts.
99
100 =head1 OPTIONS
101
102 =over 4
103
104 =item B<--api-key>
105
106 Your API key.
107 You can get it at L<http://monitis.com/> under Tools -> API -> API key
108
109 =item B<--api-secret>
110
111 Your API secret.
112 You can get it at L<http://monitis.com/> under Tools -> API -> API key
113
114 =back
115
116 =head1 DESCRIPTION
117
118 Deletes subaccount by id or email.
119 If no email or id provided - prints list of existing accounts
120
121
122 =head1 AUTHOR
123
124 Yaroslav Korshak C<< <ykorshak@gmail.com> >>
125
126
127 =head1 LICENCE AND COPYRIGHT
128
129 Copyright (C) 2006-2011, Monitis Inc.
130
131 This module is free software; you can redistribute it and/or
132 modify it under the same terms as Perl itself. See L<perlartistic>.
133
134
135 =head1 DISCLAIMER OF WARRANTY
136
137 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
138 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
139 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
140 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
141 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
142 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
143 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
144 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
145 NECESSARY SERVICING, REPAIR, OR CORRECTION.
146
147 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
148 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
149 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
150 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
151 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
152 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
153 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
154 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
155 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
156 SUCH DAMAGES.
157
158 =cut
Something went wrong with that request. Please try again.