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

     1  package recruit
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  // GetAllMetadata returns the metadata for fields, layouts, and related lists for the specified module.
    10  // It lists the entire fields available and related list for that module.
    11  // https://www.zoho.com/recruit/developer-guide/apiv2/module-meta.html
    12  // https://recruit.zoho.%s/v2/settings/modules
    13  func (c *API) GetAllMetadata() (data AllMetadataResponse, err error) {
    14  	endpoint := zoho.Endpoint{
    15  		Name:         "GetAllMetadata",
    16  		URL:          fmt.Sprintf("https://recruit.zoho.%s/v2/settings/modules", c.ZohoTLD),
    17  		Method:       zoho.HTTPGet,
    18  		ResponseData: &AllMetadataResponse{},
    19  	}
    20  
    21  	err = c.Zoho.HTTPRequest(&endpoint)
    22  	if err != nil {
    23  		return AllMetadataResponse{}, fmt.Errorf("failed to retrieve modules: %s", err)
    24  	}
    25  
    26  	if v, ok := endpoint.ResponseData.(*AllMetadataResponse); ok {
    27  		return *v, nil
    28  	}
    29  
    30  	return AllMetadataResponse{}, fmt.Errorf("data retrieved was not 'ModuleResponse'")
    31  }
    32  
    33  // AllMetadataResponse is the data returned by GetAllMetadata
    34  
    35  type AllMetadataResponse struct {
    36  	Modules []struct {
    37  		Convertable   bool   `json:"convertable,omitempty"`
    38  		Editable      bool   `json:"editable,omitempty"`
    39  		Deletable     bool   `json:"deletable,omitempty"`
    40  		WebLink       string `json:"web_link,omitempty"`
    41  		SingularLabel string `json:"singular_label,omitempty"`
    42  		ModifiedTime  Time   `json:"modified_time,omitempty"`
    43  		Viewable      bool   `json:"viewable,omitempty"`
    44  		APISupported  bool   `json:"api_supported,omitempty"`
    45  		Createable    bool   `json:"createable,omitempty"`
    46  		PluralLabel   string `json:"plural_label,omitempty"`
    47  		APIName       string `json:"api_name,omitempty"`
    48  		ModifiedBy    string `json:"modified_by,omitempty"`
    49  		GeneratedType string `json:"generated_type,omitempty"`
    50  		ID            string `json:"id,omitempty"`
    51  		ModuleName    string `json:"module_name,omitempty"`
    52  	} `json:"modules,omitempty"`
    53  }
    54  
    55  // GetModuleMetadata returns the metadata for a specific module.
    56  // https://www.zoho.com/recruit/developer-guide/apiv2/module-meta.html
    57  // https://recruit.zoho.eu/recruit/v2/settings/modules/{module}
    58  func (c *API) GetModuleMetadata(module string) (data ModuleMetadataResponse, err error) {
    59  	endpoint := zoho.Endpoint{
    60  		Name: "GetModuleMetadata",
    61  		URL: fmt.Sprintf(
    62  			"https://recruit.zoho.%s/recruit/v2/settings/modules/%s",
    63  			c.ZohoTLD,
    64  			module,
    65  		),
    66  		Method:       zoho.HTTPGet,
    67  		ResponseData: &ModuleMetadataResponse{},
    68  	}
    69  
    70  	err = c.Zoho.HTTPRequest(&endpoint)
    71  	if err != nil {
    72  		return ModuleMetadataResponse{}, fmt.Errorf("failed to retrieve metadata module: %s", err)
    73  	}
    74  
    75  	if v, ok := endpoint.ResponseData.(*ModuleMetadataResponse); ok {
    76  		return *v, nil
    77  	}
    78  
    79  	return ModuleMetadataResponse{}, fmt.Errorf("data retrieved was not 'ModuleResponse'")
    80  }
    81  
    82  // ModuleMetadataResponse is the data returned by GetModuleMetadata
    83  type ModuleMetadataResponse struct {
    84  	Modules []struct {
    85  		ImportMy              bool        `json:"Import_My"`
    86  		GlobalSearchSupported bool        `json:"global_search_supported"`
    87  		Deletable             bool        `json:"deletable"`
    88  		Creatable             bool        `json:"creatable"`
    89  		ModifiedTime          interface{} `json:"modified_time"`
    90  		PluralLabel           string      `json:"plural_label"`
    91  		PresenceSubMenu       bool        `json:"presence_sub_menu"`
    92  		Export                bool        `json:"Export"`
    93  		ID                    string      `json:"id"`
    94  		RelatedListProperties struct {
    95  			SortBy    interface{} `json:"sort_by"`
    96  			Fields    []string    `json:"fields"`
    97  			SortOrder interface{} `json:"sort_order"`
    98  		} `json:"related_list_properties"`
    99  		Properties           []string `json:"$properties"`
   100  		PerPage              int      `json:"per_page"`
   101  		Convertable          bool     `json:"convertable"`
   102  		Editable             bool     `json:"editable"`
   103  		EmailTemplateSupport bool     `json:"emailTemplate_support"`
   104  		Profiles             []struct {
   105  			Name string `json:"name"`
   106  			ID   string `json:"id"`
   107  		} `json:"profiles"`
   108  		FilterSupported bool `json:"filter_supported"`
   109  		DisplayField    struct {
   110  			APIName string `json:"api_name"`
   111  			ID      string `json:"id"`
   112  		} `json:"display_field"`
   113  		WebLink          interface{} `json:"web_link"`
   114  		SequenceNumber   int         `json:"sequence_number"`
   115  		SingularLabel    string      `json:"singular_label"`
   116  		Viewable         bool        `json:"viewable"`
   117  		APISupported     bool        `json:"api_supported"`
   118  		APIName          string      `json:"api_name"`
   119  		QuickCreate      bool        `json:"quick_create"`
   120  		ModifiedBy       interface{} `json:"modified_by"`
   121  		GeneratedType    string      `json:"generated_type"`
   122  		ScoringSupported bool        `json:"scoring_supported"`
   123  		ModuleName       string      `json:"module_name"`
   124  		Attachmenttypes  []struct {
   125  			SequenceNumber int    `json:"sequence_number"`
   126  			CustomField    bool   `json:"custom_field"`
   127  			APIName        string `json:"api_name"`
   128  			Isauto         bool   `json:"isauto"`
   129  			FieldLabel     string `json:"field_label"`
   130  			Publish        bool   `json:"publish"`
   131  			ViewType       struct {
   132  				View     bool `json:"view"`
   133  				Download bool `json:"download"`
   134  				Edit     bool `json:"edit"`
   135  				Create   bool `json:"create"`
   136  				Delete   bool `json:"delete"`
   137  			} `json:"view_type"`
   138  			SePresence bool   `json:"se_presence"`
   139  			ID         string `json:"id"`
   140  			Isdefault  bool   `json:"isdefault"`
   141  			Bulk       bool   `json:"bulk"`
   142  			Required   bool   `json:"required"`
   143  		} `json:"attachmenttypes"`
   144  		ImportMyOrg bool `json:"Import_MyOrg"`
   145  		CustomView  struct {
   146  			DisplayValue  string      `json:"display_value"`
   147  			SharedType    interface{} `json:"shared_type"`
   148  			Criteria      interface{} `json:"criteria"`
   149  			SystemName    string      `json:"system_name"`
   150  			SharedDetails interface{} `json:"shared_details"`
   151  			SortBy        interface{} `json:"sort_by"`
   152  			Offline       bool        `json:"offline"`
   153  			Default       bool        `json:"default"`
   154  			SystemDefined bool        `json:"system_defined"`
   155  			Name          string      `json:"name"`
   156  			ID            string      `json:"id"`
   157  			Category      string      `json:"category"`
   158  			Fields        []string    `json:"fields"`
   159  			Favorite      interface{} `json:"favorite"`
   160  			SortOrder     interface{} `json:"sort_order"`
   161  			IsSearch      bool        `json:"is_search"`
   162  		} `json:"custom_view"`
   163  		ParentModule struct {
   164  		} `json:"parent_module"`
   165  	} `json:"modules"`
   166  }
   167  
   168  // GetFieldsMetadata returns field metadata for the specified module.
   169  // https://www.zoho.com/recruit/developer-guide/apiv2/field-meta.html
   170  // https://recruit.zoho.eu/recruit/v2/settings/fields
   171  func (c *API) GetFieldsMetadata(
   172  	params map[string]zoho.Parameter,
   173  ) (data FieldsMetadataResponse, err error) {
   174  	endpoint := zoho.Endpoint{
   175  		Name:         "GetFieldsMetadata",
   176  		URL:          fmt.Sprintf("https://recruit.zoho.%s/recruit/v2/settings/fields", c.ZohoTLD),
   177  		Method:       zoho.HTTPGet,
   178  		ResponseData: &FieldsMetadataResponse{},
   179  		URLParameters: map[string]zoho.Parameter{
   180  			"module": "",
   181  		},
   182  	}
   183  
   184  	if len(params) > 0 {
   185  		for k, v := range params {
   186  			endpoint.URLParameters[k] = v
   187  		}
   188  	}
   189  
   190  	err = c.Zoho.HTTPRequest(&endpoint)
   191  	if err != nil {
   192  		return FieldsMetadataResponse{}, fmt.Errorf("failed to retrieve fields: %s", err)
   193  	}
   194  
   195  	if v, ok := endpoint.ResponseData.(*FieldsMetadataResponse); ok {
   196  		return *v, nil
   197  	}
   198  
   199  	return FieldsMetadataResponse{}, fmt.Errorf("data retrieved was not 'ModuleResponse'")
   200  }
   201  
   202  type FieldsMetadataResponse struct {
   203  	Fields []struct {
   204  		SystemMandatory       bool        `json:"system_mandatory"`
   205  		Webhook               bool        `json:"webhook"`
   206  		JSONType              string      `json:"json_type"`
   207  		FieldLabel            string      `json:"field_label"`
   208  		Tooltip               interface{} `json:"tooltip"`
   209  		CreatedSource         string      `json:"created_source"`
   210  		FieldReadOnly         bool        `json:"field_read_only"`
   211  		DisplayLabel          string      `json:"display_label"`
   212  		ReadOnly              bool        `json:"read_only"`
   213  		BusinesscardSupported bool        `json:"businesscard_supported"`
   214  		Currency              struct {
   215  		} `json:"currency"`
   216  		ID          string `json:"id"`
   217  		CustomField bool   `json:"custom_field"`
   218  		Lookup      struct {
   219  		} `json:"lookup"`
   220  		ConvertMapping struct {
   221  			Potentials interface{} `json:"Potentials"`
   222  			Contacts   interface{} `json:"Contacts"`
   223  			Accounts   interface{} `json:"Accounts"`
   224  		} `json:"convert_mapping"`
   225  		Visible  bool `json:"visible"`
   226  		Length   int  `json:"length"`
   227  		ViewType struct {
   228  			View        bool `json:"view"`
   229  			Edit        bool `json:"edit"`
   230  			QuickCreate bool `json:"quick_create"`
   231  			Create      bool `json:"create"`
   232  		} `json:"view_type"`
   233  		APIName string `json:"api_name"`
   234  		Unique  struct {
   235  		} `json:"unique"`
   236  		DataType string `json:"data_type"`
   237  		Formula  struct {
   238  		} `json:"formula"`
   239  		DecimalPlace       interface{}   `json:"decimal_place"`
   240  		MassUpdate         bool          `json:"mass_update"`
   241  		BlueprintSupported bool          `json:"blueprint_supported"`
   242  		PickListValues     []interface{} `json:"pick_list_values"`
   243  		AutoNumber         struct {
   244  		} `json:"auto_number"`
   245  	} `json:"fields"`
   246  }
   247  
   248  // GetCustomViewsMetadata returns the custom views data of a particular module.
   249  // https://www.zoho.com/recruit/developer-guide/apiv2/custom-view-meta.html
   250  // https://recruit.zoho.eu/recruit/v2/settings/custom_views/{module_id}?module={module}
   251  func (c *API) GetCustomViewsMetadata(
   252  	moduleId string,
   253  	params map[string]zoho.Parameter,
   254  ) (data CustomViewsMetadataResponse, err error) {
   255  	endpoint := zoho.Endpoint{
   256  		Name: "GetCustomViewsMetadata",
   257  		URL: fmt.Sprintf(
   258  			"https://recruit.zoho.%s/recruit/v2/settings/custom_views/%s",
   259  			c.ZohoTLD,
   260  			moduleId,
   261  		),
   262  		Method:       zoho.HTTPGet,
   263  		ResponseData: &CustomViewsMetadataResponse{},
   264  		URLParameters: map[string]zoho.Parameter{
   265  			"module": "",
   266  		},
   267  	}
   268  
   269  	if len(params) > 0 {
   270  		for k, v := range params {
   271  			endpoint.URLParameters[k] = v
   272  		}
   273  	}
   274  
   275  	err = c.Zoho.HTTPRequest(&endpoint)
   276  	if err != nil {
   277  		return CustomViewsMetadataResponse{}, fmt.Errorf("failed to retrieve custom views: %s", err)
   278  	}
   279  
   280  	if v, ok := endpoint.ResponseData.(*CustomViewsMetadataResponse); ok {
   281  		return *v, nil
   282  	}
   283  
   284  	return CustomViewsMetadataResponse{}, fmt.Errorf("data retrieved was not 'ModuleResponse'")
   285  }
   286  
   287  type CustomViewsMetadataResponse struct {
   288  	CustomViews []struct {
   289  		DisplayValue  string      `json:"display_value"`
   290  		SharedType    interface{} `json:"shared_type"`
   291  		Criteria      interface{} `json:"criteria"`
   292  		SystemName    string      `json:"system_name"`
   293  		SharedDetails interface{} `json:"shared_details"`
   294  		SortBy        string      `json:"sort_by"`
   295  		Offline       bool        `json:"offline"`
   296  		Default       bool        `json:"default"`
   297  		SystemDefined bool        `json:"system_defined"`
   298  		Name          string      `json:"name"`
   299  		ID            string      `json:"id"`
   300  		Category      string      `json:"category"`
   301  		Fields        []string    `json:"fields"`
   302  		Favorite      interface{} `json:"favorite"`
   303  		SortOrder     string      `json:"sort_order"`
   304  		IsSearch      bool        `json:"is_search"`
   305  	} `json:"custom_views"`
   306  }