account_setting.go raw

   1  package rest
   2  
   3  import (
   4  	"net/http"
   5  
   6  	"gopkg.in/ns1/ns1-go.v2/rest/model/account"
   7  )
   8  
   9  // SettingsService handles 'account/settings' endpoint.
  10  type SettingsService service
  11  
  12  // Get returns the basic contact details associated with the account.
  13  //
  14  // NS1 API docs: https://ns1.com/api/#settings-get
  15  func (s *SettingsService) Get() (*account.Setting, *http.Response, error) {
  16  	req, err := s.client.NewRequest("GET", "account/settings", nil)
  17  	if err != nil {
  18  		return nil, nil, err
  19  	}
  20  
  21  	var us account.Setting
  22  	resp, err := s.client.Do(req, &us)
  23  	if err != nil {
  24  		return nil, resp, err
  25  	}
  26  
  27  	return &us, resp, nil
  28  }
  29  
  30  // Update changes most of the basic contact details, except customerid.
  31  //
  32  // NS1 API docs: https://ns1.com/api/#settings-post
  33  func (s *SettingsService) Update(us *account.Setting) (*http.Response, error) {
  34  	req, err := s.client.NewRequest("POST", "account/settings", &us)
  35  	if err != nil {
  36  		return nil, err
  37  	}
  38  
  39  	// Update usagewarnings fields with data from api(ensure consistent)
  40  	resp, err := s.client.Do(req, &us)
  41  	if err != nil {
  42  		return resp, err
  43  	}
  44  
  45  	return resp, nil
  46  }
  47