byalextran / DnsMadeEasy

PHP wrapper for the Dns Made Easy API.
19 stars 10 forks source link

Sample code #1

Closed sid2089 closed 13 years ago

sid2089 commented 13 years ago

Hi

Can you please provide sample code for all add methods? I've not been able to get some of them to work. Just one line codes will do.

Thanks Sid

byalextran commented 13 years ago

hi sid,

yeah, here are some examples for you. sorry for the lack of documentation. that's on my todo list.

also, i realized i forgot to include something, so i just pushed a new change to the repo you should pull down.

hope this helps.

// the last parameter specifies whether to make production (FALSE) or test (TRUE) API calls.
// you obtain the api/secret key's from your Dns Made Easy account.
$dme = new DnsMadeEasy('apiKey', 'secretKey', TRUE);

// adding a domain.
$response = $dme->domains->add('alextran.com');

// adding a record
$record = array(
    'name' => 'foobar',
    'type' => 'A',
    'data' => '1.2.3.4',
    'ttl' => 1800,
);

$response = $dme->records->add('foobar.com', $record);

all successful API calls return a JSON object (or TRUE/FALSE). in cases an error happens, a DnsMadeEasy_Response object is returned so you can check the errors (among other things).

if (is_class($response) == 'DnsMadeEasy_Response') {
    // output the errors.
    print_r($response->errors());
}