user.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package packngo
  2. const userBasePath = "/users"
  3. // UserService interface defines available user methods
  4. type UserService interface {
  5. Get(string) (*User, *Response, error)
  6. }
  7. // User represents a Packet user
  8. type User struct {
  9. ID string `json:"id"`
  10. FirstName string `json:"first_name,omitempty"`
  11. LastName string `json:"last_name,omitempty"`
  12. FullName string `json:"full_name,omitempty"`
  13. Email string `json:"email,omitempty"`
  14. TwoFactor string `json:"two_factor_auth,omitempty"`
  15. AvatarURL string `json:"avatar_url,omitempty"`
  16. Facebook string `json:"twitter,omitempty"`
  17. Twitter string `json:"facebook,omitempty"`
  18. LinkedIn string `json:"linkedin,omitempty"`
  19. Created string `json:"created_at,omitempty"`
  20. Updated string `json:"updated_at,omitempty"`
  21. TimeZone string `json:"timezone,omitempty"`
  22. Emails []Email `json:"email,omitempty"`
  23. PhoneNumber string `json:"phone_number,omitempty"`
  24. URL string `json:"href,omitempty"`
  25. }
  26. func (u User) String() string {
  27. return Stringify(u)
  28. }
  29. // UserServiceOp implements UserService
  30. type UserServiceOp struct {
  31. client *Client
  32. }
  33. // Get method gets a user by userID
  34. func (s *UserServiceOp) Get(userID string) (*User, *Response, error) {
  35. req, err := s.client.NewRequest("GET", userBasePath, nil)
  36. if err != nil {
  37. return nil, nil, err
  38. }
  39. user := new(User)
  40. resp, err := s.client.Do(req, user)
  41. if err != nil {
  42. return nil, resp, err
  43. }
  44. return user, resp, err
  45. }