github.com/schmorrison/Zoho@v1.1.4/bookings/staff.go (about)

     1  package bookings
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  func (c *API) FetchStaff(
    10  	serviceID zoho.Parameter,
    11  	staffID zoho.Parameter,
    12  ) (data StaffResponse, err error) {
    13  	endpoint := zoho.Endpoint{
    14  		Name: FetchStaffModule,
    15  		URL: fmt.Sprintf(
    16  			"https://www.zohoapis.%s/bookings/v1/json/%s",
    17  			c.ZohoTLD,
    18  			FetchStaffModule,
    19  		),
    20  		Method:       zoho.HTTPGet,
    21  		ResponseData: &StaffResponse{},
    22  		URLParameters: map[string]zoho.Parameter{
    23  			"filter_by": "",
    24  		},
    25  	}
    26  	if serviceID != "" {
    27  		endpoint.URLParameters["service_id"] = serviceID
    28  	}
    29  	if staffID != "" {
    30  		endpoint.URLParameters["staff_id"] = staffID
    31  	}
    32  
    33  	err = c.Zoho.HTTPRequest(&endpoint)
    34  	if err != nil {
    35  		return StaffResponse{}, fmt.Errorf("Failed to retrieve staffs: %s", err)
    36  	}
    37  
    38  	if v, ok := endpoint.ResponseData.(*StaffResponse); ok {
    39  		return *v, nil
    40  	}
    41  	return StaffResponse{}, fmt.Errorf("Data retrieved was not 'Staff Response'")
    42  }
    43  
    44  type StaffResponse struct {
    45  	Response struct {
    46  		ReturnValue struct {
    47  			Data []struct {
    48  				Name string `json:"name"`
    49  				Id   string `json:"id"`
    50  			} `json:"data"`
    51  		} `json:"returnvalue"`
    52  		Status string `json:"status"`
    53  	} `json:"response"`
    54  }