github.com/gophercloud/gophercloud@v1.11.0/openstack/dns/v2/transfer/accept/requests.go (about)

     1  package accept
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  // ListOptsBuilder allows extensions to add parameters to the List request.
    11  type ListOptsBuilder interface {
    12  	ToTransferAcceptListQuery() (string, error)
    13  }
    14  
    15  // ListOpts allows the filtering and sorting of paginated collections through
    16  // the API. Filtering is achieved by passing in struct field values that map to
    17  // the server attributes you want to see returned.
    18  // https://developer.openstack.org/api-ref/dns/
    19  type ListOpts struct {
    20  	Status string `q:"status"`
    21  }
    22  
    23  // ToTransferAcceptListQuery formats a ListOpts into a query string.
    24  func (opts ListOpts) ToTransferAcceptListQuery() (string, error) {
    25  	q, err := gophercloud.BuildQueryString(opts)
    26  	return q.String(), err
    27  }
    28  
    29  // List implements a transfer accept List request.
    30  func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    31  	url := baseURL(client)
    32  	if opts != nil {
    33  		query, err := opts.ToTransferAcceptListQuery()
    34  		if err != nil {
    35  			return pagination.Pager{Err: err}
    36  		}
    37  		url += query
    38  	}
    39  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    40  		return TransferAcceptPage{pagination.LinkedPageBase{PageResult: r}}
    41  	})
    42  }
    43  
    44  // Get returns information about a transfer accept, given its ID.
    45  func Get(client *gophercloud.ServiceClient, transferAcceptID string) (r GetResult) {
    46  	resp, err := client.Get(resourceURL(client, transferAcceptID), &r.Body, nil)
    47  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    48  	return
    49  }
    50  
    51  // CreateOptsBuilder allows extensions to add additional attributes to the
    52  // Create request.
    53  type CreateOptsBuilder interface {
    54  	ToTransferAcceptCreateMap() (map[string]interface{}, error)
    55  }
    56  
    57  // CreateOpts specifies the attributes used to create a transfer accept.
    58  type CreateOpts struct {
    59  	// Key is used as part of the zone transfer accept process.
    60  	// This is only shown to the creator, and must be communicated out of band.
    61  	Key string `json:"key" required:"true"`
    62  
    63  	// ZoneTransferRequestID is ID for this zone transfer request
    64  	ZoneTransferRequestID string `json:"zone_transfer_request_id" required:"true"`
    65  }
    66  
    67  // ToTransferAcceptCreateMap formats an CreateOpts structure into a request body.
    68  func (opts CreateOpts) ToTransferAcceptCreateMap() (map[string]interface{}, error) {
    69  	b, err := gophercloud.BuildRequestBody(opts, "")
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  	return b, nil
    74  }
    75  
    76  // Create implements a transfer accept create request.
    77  func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    78  	b, err := opts.ToTransferAcceptCreateMap()
    79  	if err != nil {
    80  		r.Err = err
    81  		return
    82  	}
    83  	resp, err := client.Post(baseURL(client), &b, &r.Body, &gophercloud.RequestOpts{
    84  		OkCodes: []int{http.StatusCreated, http.StatusAccepted},
    85  	})
    86  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    87  	return
    88  }