lukesUbuntu/cloudflare-api

SRV record

javigines opened this issue · 1 comments

I dont know what is the correct syntax for create a SRV record with your API.
Can you please explain me that?

Thanks

EDIT: I think with your API you cant create a SRV record or update one.
Here I write a fix to the code to solve that:

     /**
    * update_dns_record
    * https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
    * @type : A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF
    */
    public function update_dns_record($identifier,$dns_record_id,$type,$name,$content,$ttl = 1){

         if (!in_array($type, self::$VALID_DNS_TYPES))
         return "incorrect dns type";

        if($type === 'SRV'){
            //$content = "$weight, $priority, $target, $service, $proto, $port"
            //Example: $content = "3, 5, examplewebpage.com, _web, _tcp, 8765"
            $contentData = explode(", ", $content);

            $data = [
                "type"  =>  $type,
                "data"  =>  array(
                    "name"  =>  $name,
                    "weight" => $contentData[0],
                    "priority" => $contentData[1],
                    "target" => $contentData[2],
                    "service" => $contentData[3],
                    "proto" => $contentData[4],
                    "port" => $contentData[5],
                    "ttl"  => $ttl
                    )
        ];
        }else{
            $data = [
                'type'      =>  $type,
                'name'      =>  $name,
                'content'   =>  $content,
                'ttl'       =>  $ttl
            ];
        }
        return $this->put('zones/'.$identifier.'/dns_records/'.$dns_record_id,$data);
    }
    /**
    * create_dns_record
    * https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
    * @type : A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF
    */
    public function create_dns_record($identifier,$type,$name,$content,$ttl = 1){

         if (!in_array($type, self::$VALID_DNS_TYPES))
         return "incorrect dns type";

        if($type === 'SRV'){
            //$content = "$weight, $priority, $target, $service, $proto, $port"
            //Example: $content = "3, 5, examplewebpage.com, _web, _tcp, 8765"
            $contentData = explode(", ", $content);

            $data = [
                "type"  =>  $type,
                "data"  =>  array(
                    "name"  =>  $name,
                    "weight" => $contentData[0],
                    "priority" => $contentData[1],
                    "target" => $contentData[2],
                    "service" => $contentData[3],
                    "proto" => $contentData[4],
                    "port" => $contentData[5],
                    "ttl"  => $ttl
                    )
        ];
        }else{
            $data = [
                'type'      =>  $type,
                'name'      =>  $name,
                'content'   =>  $content,
                'ttl'       =>  $ttl
            ];
        }
        return $this->post('zones/'.$identifier.'/dns_records',$data);
    }

Thanks and good job with the API.

nice i will check it out, and do a pull request from @7d8214f40c831ac283ced8e586b79f4b26a150c7 thanks for that!