email.go 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package packngo
  2. const emailBasePath = "/emails"
  3. // EmailService interface defines available email methods
  4. type EmailService interface {
  5. Get(string) (*Email, *Response, error)
  6. }
  7. // Email represents a user's email address
  8. type Email struct {
  9. ID string `json:"id"`
  10. Address string `json:"address"`
  11. Default bool `json:"default,omitempty"`
  12. URL string `json:"href,omitempty"`
  13. }
  14. func (e Email) String() string {
  15. return Stringify(e)
  16. }
  17. // EmailServiceOp implements EmailService
  18. type EmailServiceOp struct {
  19. client *Client
  20. }
  21. // Get retrieves an email by id
  22. func (s *EmailServiceOp) Get(emailID string) (*Email, *Response, error) {
  23. req, err := s.client.NewRequest("GET", emailBasePath, nil)
  24. if err != nil {
  25. return nil, nil, err
  26. }
  27. email := new(Email)
  28. resp, err := s.client.Do(req, email)
  29. if err != nil {
  30. return nil, resp, err
  31. }
  32. return email, resp, err
  33. }