session.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // Copyright 2017, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package gitlab
  17. import "time"
  18. // SessionService handles communication with the session related methods of
  19. // the GitLab API.
  20. //
  21. // GitLab API docs: https://docs.gitlab.com/ce/api/session.html
  22. type SessionService struct {
  23. client *Client
  24. }
  25. // Session represents a GitLab session.
  26. //
  27. // GitLab API docs: https://docs.gitlab.com/ce/api/session.html#session
  28. type Session struct {
  29. ID int `json:"id"`
  30. Username string `json:"username"`
  31. Email string `json:"email"`
  32. Name string `json:"name"`
  33. PrivateToken string `json:"private_token"`
  34. Blocked bool `json:"blocked"`
  35. CreatedAt *time.Time `json:"created_at"`
  36. Bio interface{} `json:"bio"`
  37. Skype string `json:"skype"`
  38. Linkedin string `json:"linkedin"`
  39. Twitter string `json:"twitter"`
  40. WebsiteURL string `json:"website_url"`
  41. DarkScheme bool `json:"dark_scheme"`
  42. ThemeID int `json:"theme_id"`
  43. IsAdmin bool `json:"is_admin"`
  44. CanCreateGroup bool `json:"can_create_group"`
  45. CanCreateTeam bool `json:"can_create_team"`
  46. CanCreateProject bool `json:"can_create_project"`
  47. }
  48. // GetSessionOptions represents the available Session() options.
  49. //
  50. // GitLab API docs: https://docs.gitlab.com/ce/api/session.html#session
  51. type GetSessionOptions struct {
  52. Login *string `url:"login,omitempty" json:"login,omitempty"`
  53. Email *string `url:"email,omitempty" json:"email,omitempty"`
  54. Password *string `url:"password,omitempty" json:"password,omitempty"`
  55. }
  56. // GetSession logs in to get private token.
  57. //
  58. // GitLab API docs: https://docs.gitlab.com/ce/api/session.html#session
  59. func (s *SessionService) GetSession(opt *GetSessionOptions, options ...OptionFunc) (*Session, *Response, error) {
  60. req, err := s.client.NewRequest("POST", "session", opt, options)
  61. if err != nil {
  62. return nil, nil, err
  63. }
  64. session := new(Session)
  65. resp, err := s.client.Do(req, session)
  66. if err != nil {
  67. return nil, resp, err
  68. }
  69. return session, resp, err
  70. }