github.com/schmorrison/Zoho@v1.1.4/crm/types.go (about)

     1  package crm
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  type Error struct {
    10  	Code    string `json:"code,omitempty"`
    11  	Details struct {
    12  	} `json:"details,omitempty"`
    13  	Message string `json:"message,omitempty"`
    14  	Status  string `json:"status,omitempty"`
    15  }
    16  
    17  type PageInfo struct {
    18  	PerPage     int  `json:"per_page,omitempty"`
    19  	Count       int  `json:"count,omitempty"`
    20  	Page        int  `json:"page,omitempty"`
    21  	MoreRecords bool `json:"more_records,omitempty"`
    22  }
    23  
    24  type MultiSelect []string
    25  type Date = zoho.Date
    26  type Time = zoho.Time
    27  type Number int
    28  type Currency float64
    29  type Decimal float64
    30  type Percent float64
    31  type Long int64
    32  type Checkbox bool
    33  type URL string
    34  type Lookup struct {
    35  	Name string `json:"name,omitempty"`
    36  	ID   string `json:"id,omitempty"`
    37  }
    38  type Owner struct {
    39  	Name string `json:"name,omitempty"`
    40  	ID   string `json:"id,omitempty"`
    41  }
    42  type Layout struct {
    43  	Name string `json:"name,omitempty"`
    44  	ID   string `json:"id,omitempty"`
    45  }
    46  type AutoNumber string
    47  
    48  // SingleLine is the field type in Zoho that defines a single line input field
    49  type SingleLine string
    50  
    51  func (s *SingleLine) UnmarshalJSON(data []byte) error {
    52  	if string(data) == "null" {
    53  		t := SingleLine("")
    54  		s = &t
    55  		return nil
    56  	}
    57  
    58  	var t string
    59  	if err := json.Unmarshal(data, &t); err != nil {
    60  		return err
    61  	}
    62  
    63  	tp := SingleLine(t)
    64  	s = &tp
    65  	return nil
    66  }
    67  
    68  func (s SingleLine) MarshalJSON() ([]byte, error) {
    69  	if string(s) == "" {
    70  		return []byte{}, nil
    71  	}
    72  	return []byte(s), nil
    73  }
    74  
    75  // MultiLine is the field type in Zoho that defines a multiline input field, like text area in HTML
    76  type MultiLine string
    77  
    78  func (s *MultiLine) UnmarshalJSON(data []byte) error {
    79  	if string(data) == "null" {
    80  		t := MultiLine("")
    81  		s = &t
    82  		return nil
    83  	}
    84  
    85  	var t string
    86  	if err := json.Unmarshal(data, &t); err != nil {
    87  		return err
    88  	}
    89  
    90  	tp := MultiLine(t)
    91  	s = &tp
    92  	return nil
    93  }
    94  
    95  func (s MultiLine) MarshalJSON() ([]byte, error) {
    96  	if string(s) == "" {
    97  		return []byte{}, nil
    98  	}
    99  	return []byte(s), nil
   100  }
   101  
   102  // Email is the field type in Zoho that defines an email address field
   103  type Email string
   104  
   105  func (s *Email) UnmarshalJSON(data []byte) error {
   106  	if string(data) == "null" {
   107  		t := Email("")
   108  		s = &t
   109  		return nil
   110  	}
   111  
   112  	var t string
   113  	if err := json.Unmarshal(data, &t); err != nil {
   114  		return err
   115  	}
   116  
   117  	tp := Email(t)
   118  	s = &tp
   119  	return nil
   120  }
   121  
   122  func (s Email) MarshalJSON() ([]byte, error) {
   123  	if string(s) == "" {
   124  		return []byte{}, nil
   125  	}
   126  	return []byte(s), nil
   127  }
   128  
   129  // Phone is the field type in Zoho that defines a phone number field
   130  type Phone string
   131  
   132  func (s *Phone) UnmarshalJSON(data []byte) error {
   133  	if string(data) == "null" {
   134  		t := Phone("")
   135  		s = &t
   136  		return nil
   137  	}
   138  
   139  	var t string
   140  	if err := json.Unmarshal(data, &t); err != nil {
   141  		return err
   142  	}
   143  
   144  	tp := Phone(t)
   145  	s = &tp
   146  	return nil
   147  }
   148  
   149  func (s Phone) MarshalJSON() ([]byte, error) {
   150  	if string(s) == "" {
   151  		return []byte{}, nil
   152  	}
   153  	return []byte(s), nil
   154  }
   155  
   156  // PickList is the field type in Zoho that defines a dropdown that has been selected
   157  type PickList string
   158  
   159  func (s *PickList) UnmarshalJSON(data []byte) error {
   160  	if string(data) == "null" {
   161  		t := PickList("")
   162  		s = &t
   163  		return nil
   164  	}
   165  
   166  	var t string
   167  	if err := json.Unmarshal(data, &t); err != nil {
   168  		return err
   169  	}
   170  
   171  	tp := PickList(t)
   172  	s = &tp
   173  	return nil
   174  }
   175  
   176  func (s PickList) MarshalJSON() ([]byte, error) {
   177  	if string(s) == "" {
   178  		return []byte{}, nil
   179  	}
   180  	return []byte(s), nil
   181  }