summaryrefslogtreecommitdiff
path: root/plugins/github/src/org/jetbrains/plugins/github/api/GithubUserRaw.java
blob: 0bc673299847e3162db17017b7003cad52e6ef0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.plugins.github.api;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Date;

/**
 * Information about a user on GitHub.
 *
 * @author Kirill Likhodedov
 */
@SuppressWarnings("UnusedDeclaration")
class GithubUserRaw implements DataConstructor {

  @Nullable public String login;
  @Nullable public Long id;

  @Nullable public String url;
  @Nullable public String htmlUrl;

  @Nullable public String name;
  @Nullable public String email;
  @Nullable public String company;
  @Nullable public String location;
  @Nullable public String type;

  @Nullable public Integer publicRepos;
  @Nullable public Integer publicGists;
  @Nullable public Integer totalPrivateRepos;
  @Nullable public Integer ownedPrivateRepos;
  @Nullable public Integer privateGists;
  @Nullable public Long diskUsage;

  @Nullable public Integer followers;
  @Nullable public Integer following;
  @Nullable public String avatarUrl;
  @Nullable public String gravatarId;
  @Nullable public Integer collaborators;
  @Nullable public String blog;

  @Nullable public UserPlanRaw plan;

  @Nullable public Date createdAt;

  public static class UserPlanRaw {
    @Nullable public String name;
    @Nullable public Long space;
    @Nullable public Long collaborators;
    @Nullable public Long privateRepos;

    @SuppressWarnings("ConstantConditions")
    @NotNull
    public GithubUserDetailed.UserPlan create() {
      return new GithubUserDetailed.UserPlan(name, privateRepos);
    }
  }

  @SuppressWarnings("ConstantConditions")
  @NotNull
  public GithubUser createUser() {
    return new GithubUser(login, htmlUrl, avatarUrl);
  }

  @SuppressWarnings("ConstantConditions")
  @NotNull
  public GithubUserDetailed createUserDetailed() {
    GithubUserDetailed.UserPlan plan = this.plan == null ? null : this.plan.create();
    return new GithubUserDetailed(login, htmlUrl, avatarUrl, name, email, ownedPrivateRepos, type, plan);
  }

  @SuppressWarnings("unchecked")
  @NotNull
  @Override
  public <T> T create(@NotNull Class<T> resultClass) {
    if (resultClass == GithubUser.class) {
      return (T)createUser();
    }
    if (resultClass == GithubUserDetailed.class) {
      return (T)createUserDetailed();
    }

    throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName());
  }
}