github.com/schmorrison/Zoho@v1.1.4/recruit/clients.go (about)

     1  package recruit
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  // GetClientsRecords returns a list of all records
    10  // https://www.zoho.com/recruit/developer-guide/apiv2/get-records.html
    11  // https://recruit.zoho.eu/recruit/v2/Clients
    12  func (c *API) GetClientsRecords(
    13  	params map[string]zoho.Parameter,
    14  ) (data ClientsRecordsResponse, err error) {
    15  	endpoint := zoho.Endpoint{
    16  		Name: "GetClientsRecords",
    17  		URL: fmt.Sprintf(
    18  			"https://recruit.zoho.%s/recruit/v2/%s",
    19  			c.ZohoTLD,
    20  			ClientsModule,
    21  		),
    22  		Method:       zoho.HTTPGet,
    23  		ResponseData: &ClientsRecordsResponse{},
    24  		URLParameters: map[string]zoho.Parameter{
    25  			"fields":        "",
    26  			"sort_order":    "",
    27  			"sort_by":       "",
    28  			"converted":     "false",
    29  			"approved":      "true",
    30  			"page":          "1",
    31  			"per_page":      "200",
    32  			"cvid":          "",
    33  			"territory_id":  "",
    34  			"include_child": "",
    35  		},
    36  	}
    37  
    38  	if len(params) > 0 {
    39  		for k, v := range params {
    40  			endpoint.URLParameters[k] = v
    41  		}
    42  	}
    43  
    44  	err = c.Zoho.HTTPRequest(&endpoint)
    45  	if err != nil {
    46  		return ClientsRecordsResponse{}, fmt.Errorf("failed to retrieve Clients: %s", err)
    47  	}
    48  
    49  	if v, ok := endpoint.ResponseData.(*ClientsRecordsResponse); ok {
    50  		return *v, nil
    51  	}
    52  
    53  	return ClientsRecordsResponse{}, fmt.Errorf("data returned was not 'ClientsRecordsResponse'")
    54  }
    55  
    56  // GetClientsRecord returns the record specified by ID
    57  // https://www.zoho.com/recruit/developer-guide/apiv2/get-records.html
    58  // https://recruit.zoho.eu/recruit/v2/Clients/{id}
    59  func (c *API) GetClientsRecordById(id string) (data ClientsRecordsResponse, err error) {
    60  	endpoint := zoho.Endpoint{
    61  		Name: "GetClientsRecordById",
    62  		URL: fmt.Sprintf(
    63  			"https://recruit.zoho.%s/recruit/v2/%s/%s",
    64  			c.ZohoTLD,
    65  			ClientsModule,
    66  			id,
    67  		),
    68  		Method:       zoho.HTTPGet,
    69  		ResponseData: &ClientsRecordsResponse{},
    70  	}
    71  
    72  	err = c.Zoho.HTTPRequest(&endpoint)
    73  	if err != nil {
    74  		return ClientsRecordsResponse{}, fmt.Errorf(
    75  			"failed to retrieve JobOpening with id: %s",
    76  			err,
    77  		)
    78  	}
    79  
    80  	if v, ok := endpoint.ResponseData.(*ClientsRecordsResponse); ok {
    81  		return *v, nil
    82  	}
    83  
    84  	return ClientsRecordsResponse{}, fmt.Errorf("data returned was not 'ClientsRecordsResponse'")
    85  }
    86  
    87  // ClientsRecordsResponse is the data returned by GetClientsRecords & GetClientsRecordById
    88  type ClientsRecordsResponse struct {
    89  	Data []struct {
    90  		ClientName     string `json:"Client_Name,omitempty"`
    91  		CurrencySymbol string `json:"$currency_symbol,omitempty"`
    92  		ShippingState  string `json:"Shipping_State,omitempty"`
    93  		Website        string `json:"Website,omitempty"`
    94  		AccountManager struct {
    95  			Name string `json:"name,omitempty"`
    96  			ID   string `json:"id,omitempty"`
    97  		} `json:"Account_Manager,omitempty"`
    98  		Source           string `json:"Source,omitempty"`
    99  		LastActivityTime Time   `json:"Last_Activity_Time,omitempty"`
   100  		Industry         string `json:"Industry,omitempty"`
   101  		ModifiedBy       struct {
   102  			Name string `json:"name,omitempty"`
   103  			ID   string `json:"id,omitempty"`
   104  		} `json:"Modified_By,omitempty"`
   105  		ProcessFlow    bool   `json:"$process_flow,omitempty"`
   106  		BillingCountry string `json:"Billing_Country,omitempty"`
   107  		ContactNumber  string `json:"Contact_Number,omitempty"`
   108  		ID             string `json:"id,omitempty"`
   109  		Approved       bool   `json:"$approved,omitempty"`
   110  		Approval       struct {
   111  			Delegate bool `json:"delegate,omitempty"`
   112  			Approve  bool `json:"approve,omitempty"`
   113  			Reject   bool `json:"reject,omitempty"`
   114  			Resubmit bool `json:"resubmit,omitempty"`
   115  		} `json:"$approval,omitempty"`
   116  		IsStatusSplitDone bool       `json:"isStatusSplitDone,omitempty"`
   117  		ModifiedTime      Time       `json:"Modified_Time,omitempty"`
   118  		BillingStreet     string     `json:"Billing_Street,omitempty"`
   119  		LastMailedTime    string     `json:"Last_Mailed_Time,omitempty"`
   120  		CreatedTime       Time       `json:"Created_Time,omitempty"`
   121  		Followed          bool       `json:"$followed,omitempty"`
   122  		Editable          bool       `json:"$editable,omitempty"`
   123  		BillingCode       string     `json:"Billing_Code,omitempty"`
   124  		ParentAccount     string     `json:"Parent_Account,omitempty"`
   125  		About             string     `json:"About,omitempty"`
   126  		AssociatedTags    []struct{} `json:"Associated_Tags,omitempty"`
   127  		ShippingCity      string     `json:"Shipping_City,omitempty"`
   128  		ShippingCountry   string     `json:"Shipping_Country,omitempty"`
   129  		ShippingCode      string     `json:"Shipping_Code,omitempty"`
   130  		BillingCity       string     `json:"Billing_City,omitempty"`
   131  		BillingState      string     `json:"Billing_State,omitempty"`
   132  		CreatedBy         struct {
   133  			Name string `json:"name,omitempty"`
   134  			ID   string `json:"id,omitempty"`
   135  		} `json:"Created_By,omitempty"`
   136  		Fax                 string `json:"Fax,omitempty"`
   137  		IsAttachmentPresent bool   `json:"Is_Attachment_Present,omitempty"`
   138  		ShippingStreet      string `json:"Shipping_Street,omitempty"`
   139  	} `json:"data,omitempty"`
   140  	Info PageInfo `json:"info,omitempty"`
   141  }