Class: Geet::Github::User
Constant Summary
Shared::RepoPermissions::ALL_PERMISSIONS, Shared::RepoPermissions::PERMISSION_ADMIN, Shared::RepoPermissions::PERMISSION_NONE, Shared::RepoPermissions::PERMISSION_READ, Shared::RepoPermissions::PERMISSION_WRITE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#permission_greater_or_equal_to?
Constructor Details
#initialize(username, api_interface) ⇒ User
Returns a new instance of User.
19
20
21
22
|
# File 'lib/geet/github/user.rb', line 19
def initialize(username, api_interface)
@username = username
@api_interface = api_interface
end
|
Instance Attribute Details
#username ⇒ Object
Returns the value of attribute username.
11
12
13
|
# File 'lib/geet/github/user.rb', line 11
def username
@username
end
|
Class Method Details
.authenticated(api_interface) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/geet/github/user.rb', line 65
def self.authenticated(api_interface)
api_path = "/user"
response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped])
login = T.cast(response.fetch("login"), String)
new(login, api_interface)
end
|
.list_collaborators(api_interface) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/geet/github/user.rb', line 80
def self.list_collaborators(api_interface)
api_path = "collaborators"
response = T.cast(api_interface.send_request(api_path, multipage: true), T::Array[T::Hash[String, T.untyped]])
response.map do |user_entry|
login = T.cast(user_entry.fetch("login"), String)
new(login, api_interface)
end
end
|
.repo_permission(api_interface) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/geet/github/user.rb', line 97
def self.repo_permission(api_interface)
username = authenticated(api_interface).username
api_path = "collaborators/#{username}/permission"
response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped])
permission = T.cast(response.fetch("permission"), String)
check_permission!(permission)
permission
end
|
Instance Method Details
#has_permission?(permission) ⇒ Boolean
31
32
33
34
35
|
# File 'lib/geet/github/user.rb', line 31
def has_permission?(permission)
user_permission = self.class.repo_permission(@api_interface)
permission_greater_or_equal_to?(user_permission, permission)
end
|
#is_collaborator? ⇒ Boolean
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/geet/github/user.rb', line 40
def is_collaborator?
api_path = "collaborators/#{@username}"
begin
@api_interface.send_request(api_path)
true
rescue Geet::Shared::HttpError => error
(error.code == 404 || error.code == 403) ? false : raise
end
end
|