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

     1  package bookings
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  func (c *API) FetchServices(
    10  	workspacesID zoho.Parameter,
    11  	serviceID zoho.Parameter,
    12  	staffID zoho.Parameter,
    13  ) (data ServiceResponse, err error) {
    14  	endpoint := zoho.Endpoint{
    15  		Name: FetchServicesModule,
    16  		URL: fmt.Sprintf(
    17  			"https://www.zohoapis.%s/bookings/v1/json/%s",
    18  			c.ZohoTLD,
    19  			FetchServicesModule,
    20  		),
    21  		Method:       zoho.HTTPGet,
    22  		ResponseData: &ServiceResponse{},
    23  		URLParameters: map[string]zoho.Parameter{
    24  			"filter_by": "",
    25  		},
    26  	}
    27  	if workspacesID == "" {
    28  		return ServiceResponse{}, fmt.Errorf(
    29  			"Failed to execute FetchServices due to non-availability of workspace_id",
    30  		)
    31  	}
    32  	endpoint.URLParameters["workspace_id"] = workspacesID
    33  	if serviceID != "" {
    34  		endpoint.URLParameters["service_id"] = serviceID
    35  	}
    36  	if staffID != "" {
    37  		endpoint.URLParameters["staff_id"] = staffID
    38  	}
    39  
    40  	err = c.Zoho.HTTPRequest(&endpoint)
    41  	if err != nil {
    42  		return ServiceResponse{}, fmt.Errorf("Failed to retrieve services: %s", err)
    43  	}
    44  
    45  	if v, ok := endpoint.ResponseData.(*ServiceResponse); ok {
    46  		return *v, nil
    47  	}
    48  	return ServiceResponse{}, fmt.Errorf("Data retrieved was not 'Service Response'")
    49  }
    50  
    51  type ServiceResponse struct {
    52  	Response struct {
    53  		ReturnValue struct {
    54  			Data []struct {
    55  				Duration   string `json:"duration"`
    56  				Buffertime string `json:"buffertime"`
    57  				Price      int    `json:"price"`
    58  				Name       string `json:"name"`
    59  				Currency   string `json:"currency"`
    60  				Id         string `json:"id"`
    61  			} `json:"data"`
    62  		} `json:"returnvalue"`
    63  		Status string `json:"status"`
    64  	} `json:"response"`
    65  }