| 1 | package WWW::DNSMadeEasy; | ||||||||||||
| 2 | BEGIN { | ||||||||||||
| 3 | 3 | ▶ | $WWW::DNSMadeEasy::AUTHORITY = 'cpan:GETTY'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | } | ||||||||||||
| 5 | { | ||||||||||||
| 6 | 3 | $WWW::DNSMadeEasy::VERSION = '0.001'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | # ABSTRACT: Accessing DNSMadeEasy API | ||||||||||||
| 9 | |||||||||||||
| 10 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 3 | ▶ | use DateTime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 3 | ▶ | use DateTime::Format::HTTP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 3 | ▶ | use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 3 | ▶ | use HTTP::Request; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 3 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 3 | ▶ | use WWW::DNSMadeEasy::Domain; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 3 | ▶ | our $VERSION ||= '0.0development'; | ||||||||||
|
Condition50%1/2
our $VERSION ||= "0.0development"
MC/DC0%0/1
our $VERSION ||= "0.0development"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
| |||||||||||||
| 21 | |||||||||||||
| 22 | 3 | has api_key => ( | |||||||||||
| 23 | is => 'ro', | ||||||||||||
| 24 | required => 1, | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | 3 | has secret => ( | |||||||||||
| 28 | is => 'ro', | ||||||||||||
| 29 | required => 1, | ||||||||||||
| 30 | ); | ||||||||||||
| 31 | |||||||||||||
| 32 | has sandbox => ( | ||||||||||||
| 33 | is => 'ro', | ||||||||||||
| 34 | 1 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | 3 | ); | |||||||||||
| 36 | |||||||||||||
| 37 | has _http_agent => ( | ||||||||||||
| 38 | is => 'ro', | ||||||||||||
| 39 | lazy => 1, | ||||||||||||
| 40 | default => sub { | ||||||||||||
| 41 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 42 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||
| 43 | 0 | $ua->agent($self->http_agent_name); | |||||||||||
| 44 | 0 | return $ua; | |||||||||||
| 45 | }, | ||||||||||||
| 46 | 3 | ); | |||||||||||
| 47 | |||||||||||||
| 48 | has http_agent_name => ( | ||||||||||||
| 49 | is => 'ro', | ||||||||||||
| 50 | lazy => 1, | ||||||||||||
| 51 | 0 | ▶ | default => sub { __PACKAGE__.'/'.$VERSION }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 52 | 3 | ); | |||||||||||
| 53 | |||||||||||||
| 54 | sub api_endpoint { | ||||||||||||
| 55 | 0 | ▶ | my ( $self ) = @_; | ||||||||||
|
Subroutine
api_endpoint: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 56 | 0 | ▶ | if ($self->sandbox) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | return 'http://api.sandbox.dnsmadeeasy.com/V1.2/'; | |||||||||||
| 58 | } else { | ||||||||||||
| 59 | 0 | return 'http://api.dnsmadeeasy.com/V1.2/'; | |||||||||||
| 60 | } | ||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | sub get_request_headers { | ||||||||||||
| 64 | 1 | ▶ | my ( $self, $dt ) = @_; | ||||||||||
|
Subroutine
get_request_headers: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 65 | 1 | ▶ | $dt = DateTime->now->set_time_zone( 'GMT' ) if !$dt; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 1 | my $date_string = DateTime::Format::HTTP->format_datetime($dt); | |||||||||||
| 67 | return { | ||||||||||||
| 68 | 1 | 'x-dnsme-requestDate' => $date_string, | |||||||||||
| 69 | 'x-dnsme-apiKey' => $self->api_key, | ||||||||||||
| 70 | 'x-dnsme-hmac' => hmac_sha1_hex($date_string, $self->secret), | ||||||||||||
| 71 | }; | ||||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | sub request { | ||||||||||||
| 75 | 0 | ▶ | my ( $self, $method, $path, $data ) = @_; | ||||||||||
|
Subroutine
request: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 76 | 0 | my $url = $self->api_endpoint.$path; | |||||||||||
| 77 | 0 | my $request = HTTP::Request->new( $method => $url ); | |||||||||||
| 78 | 0 | my $headers = $self->get_request_headers; | |||||||||||
| 79 | 0 | $request->header($_ => $headers->{$_}) for (keys %{$headers}); | |||||||||||
| 80 | 0 | $request->header('Accept' => 'application/json'); | |||||||||||
| 81 | 0 | ▶ | if (defined $data) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | $request->header('Content-Type' => 'application/json'); | |||||||||||
| 83 | 0 | $request->content(encode_json($data)); | |||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | my $res = $self->_http_agent->request($request); | |||||||||||
| 86 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 0 | return decode_json($res->content); | |||||||||||
| 88 | } else { | ||||||||||||
| 89 | 0 | die __PACKAGE__.' HTTP request failed: '.$res->status_line, "\n"; | |||||||||||
| 90 | } | ||||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | # | ||||||||||||
| 94 | # DOMAINS | ||||||||||||
| 95 | # | ||||||||||||
| 96 | |||||||||||||
| 97 | 0 | ▶ | sub path_domains { 'domains' } | ||||||||||
|
Subroutine
path_domains: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 98 | |||||||||||||
| 99 | sub create_domain { | ||||||||||||
| 100 | 0 | ▶ | my ( $self, $domain_name ) = @_; | ||||||||||
|
Subroutine
create_domain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 101 | 0 | return WWW::DNSMadeEasy::Domain->create({ | |||||||||||
| 102 | name => $domain_name, | ||||||||||||
| 103 | dme => $self, | ||||||||||||
| 104 | }); | ||||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | sub domain { | ||||||||||||
| 108 | 0 | ▶ | my ( $self, $domain_name ) = @_; | ||||||||||
|
Subroutine
domain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 109 | 0 | return WWW::DNSMadeEasy::Domain->new({ | |||||||||||
| 110 | name => $domain_name, | ||||||||||||
| 111 | dme => $self, | ||||||||||||
| 112 | }); | ||||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | sub all_domains { | ||||||||||||
| 116 | 0 | ▶ | my ( $self ) = @_; | ||||||||||
|
Subroutine
all_domains: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 117 | 0 | my $data = $self->request('GET',$self->path_domains); | |||||||||||
| 118 | 0 | ▶ | return if !$data->{list}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 119 | 0 | my @domains; | |||||||||||
| 120 | 0 | for (@{$data->{list}}) { | |||||||||||
| 121 | 0 | push @domains, WWW::DNSMadeEasy::Domain->new({ | |||||||||||
| 122 | dme => $self, | ||||||||||||
| 123 | name => $_, | ||||||||||||
| 124 | }); | ||||||||||||
| 125 | } | ||||||||||||
| 126 | 0 | return @domains; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | 3 | 1; | |||||||||||
| 130 | |||||||||||||
| 131 | |||||||||||||
| 132 | |||||||||||||
| 133 | __END__ | ||||||||||||
| 134 | =pod | ||||||||||||
| 135 | |||||||||||||
| 136 | =head1 NAME | ||||||||||||
| 137 | |||||||||||||
| 138 | WWW::DNSMadeEasy - Accessing DNSMadeEasy API | ||||||||||||
| 139 | |||||||||||||
| 140 | =head1 VERSION | ||||||||||||
| 141 | |||||||||||||
| 142 | version 0.001 | ||||||||||||
| 143 | |||||||||||||
| 144 | =head1 SYNOPSIS | ||||||||||||
| 145 | |||||||||||||
| 146 | use WWW::DNSMadeEasy; # or WWW::DME as shortname | ||||||||||||
| 147 | |||||||||||||
| 148 | my $dme = WWW::DNSMadeEasy->new({ | ||||||||||||
| 149 | api_key => '1c1a3c91-4770-4ce7-96f4-54c0eb0e457a', | ||||||||||||
| 150 | secret => 'c9b5625f-9834-4ff8-baba-4ed5f32cae55', | ||||||||||||
| 151 | }); | ||||||||||||
| 152 | |||||||||||||
| 153 | my $sandbox = WWW::DNSMadeEasy->new({ | ||||||||||||
| 154 | api_key => '1c1a3c91-4770-4ce7-96f4-54c0eb0e457a', | ||||||||||||
| 155 | secret => 'c9b5625f-9834-4ff8-baba-4ed5f32cae55', | ||||||||||||
| 156 | sandbox => 1, | ||||||||||||
| 157 | }); | ||||||||||||
| 158 | |||||||||||||
| 159 | my @domains = $dme->all_domains; | ||||||||||||
| 160 | |||||||||||||
| 161 | my $domain = $dme->create_domain('universe.org'); | ||||||||||||
| 162 | |||||||||||||
| 163 | my $other_domain = $dme->domain('existingdomain.com'); | ||||||||||||
| 164 | |||||||||||||
| 165 | my @records = $other_domain->all_records; | ||||||||||||
| 166 | |||||||||||||
| 167 | my $record = $domain->create_record({ | ||||||||||||
| 168 | ttl => 120, | ||||||||||||
| 169 | gtdLocation => 'DEFAULT', | ||||||||||||
| 170 | name => 'www', | ||||||||||||
| 171 | data => '1.2.3.4', | ||||||||||||
| 172 | type => 'A', | ||||||||||||
| 173 | }); | ||||||||||||
| 174 | |||||||||||||
| 175 | $record->delete; | ||||||||||||
| 176 | |||||||||||||
| 177 | $domain->delete; | ||||||||||||
| 178 | |||||||||||||
| 179 | =head1 DESCRIPTION | ||||||||||||
| 180 | |||||||||||||
| 181 | This distribution gives you an easy access to the DNSMadeEasy API. You require a business or corporate account to use this. You can't use it with the free test account neither with the small business account. This module doesnt check any input values, I suggest so far that you know what you do. | ||||||||||||
| 182 | |||||||||||||
| 183 | =head1 ATTRIBUTES | ||||||||||||
| 184 | |||||||||||||
| 185 | =head2 api_key | ||||||||||||
| 186 | |||||||||||||
| 187 | Here you must give the API key which you can obtain from this page L<https://cp.dnsmadeeasy.com/account/info>. | ||||||||||||
| 188 | |||||||||||||
| 189 | =head2 secret | ||||||||||||
| 190 | |||||||||||||
| 191 | You get the secret from the same page where you get the API key. | ||||||||||||
| 192 | |||||||||||||
| 193 | =head2 sandbox | ||||||||||||
| 194 | |||||||||||||
| 195 | If set to true, this will activate the usage of the sandbox, instead of the live system. | ||||||||||||
| 196 | |||||||||||||
| 197 | =head2 http_agent_name | ||||||||||||
| 198 | |||||||||||||
| 199 | Here you can set a different http useragent for the requests, it defaults to the package name including the distribution version. | ||||||||||||
| 200 | |||||||||||||
| 201 | =head1 METHODS | ||||||||||||
| 202 | |||||||||||||
| 203 | =head2 $obj->create_domain | ||||||||||||
| 204 | |||||||||||||
| 205 | Arguments: $name | ||||||||||||
| 206 | |||||||||||||
| 207 | Return value: L<WWW::DNSMadeEasy::Domain> | ||||||||||||
| 208 | |||||||||||||
| 209 | Will be creating the domain $name on your account and returns the L<WWW::DNSMadeEasy::Domain> for this domain. | ||||||||||||
| 210 | |||||||||||||
| 211 | =head2 $obj->domain | ||||||||||||
| 212 | |||||||||||||
| 213 | Arguments: $name | ||||||||||||
| 214 | |||||||||||||
| 215 | Return value: L<WWW::DNSMadeEasy::Domain> | ||||||||||||
| 216 | |||||||||||||
| 217 | Returns the L<WWW::DNSMadeEasy::Domain> of the domain with name $name. | ||||||||||||
| 218 | |||||||||||||
| 219 | =head2 $obj->domain | ||||||||||||
| 220 | |||||||||||||
| 221 | Arguments: $name | ||||||||||||
| 222 | |||||||||||||
| 223 | Return value: L<WWW::DNSMadeEasy::Domain> | ||||||||||||
| 224 | |||||||||||||
| 225 | Returns the L<WWW::DNSMadeEasy::Domain> of the domain with name $name. | ||||||||||||
| 226 | |||||||||||||
| 227 | =head2 $obj->all_domains | ||||||||||||
| 228 | |||||||||||||
| 229 | Arguments: None | ||||||||||||
| 230 | |||||||||||||
| 231 | Return value: Array of L<WWW::DNSMadeEasy::Domain> | ||||||||||||
| 232 | |||||||||||||
| 233 | Returns an array of L<WWW::DNSMadeEasy::Domain> objects of all domains listed on this account. | ||||||||||||
| 234 | |||||||||||||
| 235 | =encoding utf8 | ||||||||||||
| 236 | |||||||||||||
| 237 | =head1 ATTRIBUTES | ||||||||||||
| 238 | |||||||||||||
| 239 | =head1 METHODS | ||||||||||||
| 240 | |||||||||||||
| 241 | =head1 SUPPORT | ||||||||||||
| 242 | |||||||||||||
| 243 | IRC | ||||||||||||
| 244 | |||||||||||||
| 245 | Join #duckduckgo on irc.freenode.net and highlight Getty or /msg me. | ||||||||||||
| 246 | |||||||||||||
| 247 | Repository | ||||||||||||
| 248 | |||||||||||||
| 249 | http://github.com/Getty/p5-www-dnsmadeeasy | ||||||||||||
| 250 | Pull request and additional contributors are welcome | ||||||||||||
| 251 | |||||||||||||
| 252 | Issue Tracker | ||||||||||||
| 253 | |||||||||||||
| 254 | http://github.com/Getty/p5-www-dnsmadeeasy/issues | ||||||||||||
| 255 | |||||||||||||
| 256 | =head1 AUTHOR | ||||||||||||
| 257 | |||||||||||||
| 258 | Torsten Raudssus <torsten@raudssus.de> | ||||||||||||
| 259 | |||||||||||||
| 260 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 261 | |||||||||||||
| 262 | This software is copyright (c) 2012 by L<Raudssus Social Software|http://www.raudssus.de/>. | ||||||||||||
| 263 | |||||||||||||
| 264 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 265 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 266 | |||||||||||||
| 267 | =cut | ||||||||||||
| 268 | |||||||||||||