account.go raw

   1  package goinwx
   2  
   3  import "github.com/go-viper/mapstructure/v2"
   4  
   5  const (
   6  	methodAccountLogin  = "account.login"
   7  	methodAccountLogout = "account.logout"
   8  	methodAccountLock   = "account.lock"
   9  	methodAccountUnlock = "account.unlock"
  10  )
  11  
  12  // AccountService API access to Account.
  13  type AccountService service
  14  
  15  // Login Account login.
  16  func (s *AccountService) Login() (*LoginResponse, error) {
  17  	req := s.client.NewRequest(methodAccountLogin, map[string]any{
  18  		"user": s.client.username,
  19  		"pass": s.client.password,
  20  	})
  21  
  22  	resp, err := s.client.Do(req)
  23  	if err != nil {
  24  		return nil, err
  25  	}
  26  
  27  	var result LoginResponse
  28  
  29  	err = mapstructure.Decode(resp, &result)
  30  	if err != nil {
  31  		return nil, err
  32  	}
  33  
  34  	return &result, nil
  35  }
  36  
  37  // Logout Account logout.
  38  func (s *AccountService) Logout() error {
  39  	req := s.client.NewRequest(methodAccountLogout, nil)
  40  
  41  	_, err := s.client.Do(req)
  42  
  43  	return err
  44  }
  45  
  46  // Lock Account lock.
  47  func (s *AccountService) Lock() error {
  48  	req := s.client.NewRequest(methodAccountLock, nil)
  49  
  50  	_, err := s.client.Do(req)
  51  
  52  	return err
  53  }
  54  
  55  // Unlock Account unlock.
  56  func (s *AccountService) Unlock(tan string) error {
  57  	req := s.client.NewRequest(methodAccountUnlock, map[string]any{
  58  		"tan": tan,
  59  	})
  60  
  61  	_, err := s.client.Do(req)
  62  
  63  	return err
  64  }
  65  
  66  // LoginResponse API model.
  67  type LoginResponse struct {
  68  	CustomerID int64  `mapstructure:"customerId"`
  69  	AccountID  int64  `mapstructure:"accountId"`
  70  	TFA        string `mapstructure:"tfa"`
  71  	BuildDate  string `mapstructure:"builddate"`
  72  	Version    string `mapstructure:"version"`
  73  }
  74