Class: GithubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/w-stdlib/github_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(username = '', base_url = 'https://api.github.com') ⇒ GithubClient

Returns a new instance of GithubClient.



10
11
12
13
# File 'lib/w-stdlib/github_client.rb', line 10

def initialize(username='', base_url='https://api.github.com')
  @url = URI.parse base_url
  @username = username
end

Instance Method Details

#reposObject



15
16
17
# File 'lib/w-stdlib/github_client.rb', line 15

def repos
  paginate('/repositories')
end

#repos_for_org(org) ⇒ Object



19
20
21
# File 'lib/w-stdlib/github_client.rb', line 19

def repos_for_org(org)
  paginate("/orgs/#{org}/repos")
end

#user_perms(owner, repo, username) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/w-stdlib/github_client.rb', line 27

def user_perms(owner, repo, username)
  url = @url.clone
  url.path = "/repos/#{owner}/#{repo}/collaborators/#{username}/permission"
  auth = {user: @username, pass: token}
  puts url.to_s
  HTTP.basic_auth(auth)
      .headers({"Accept" => "application/vnd.github.v3+json"})
      .get(url.to_s)
      .to_s
end

#usersObject



23
24
25
# File 'lib/w-stdlib/github_client.rb', line 23

def users
  paginate('/users')
end