Method: Octoplex::Client::Root#repos

Defined in:
lib/octoplex/client/root.rb

#repos(*user_and_repo) ⇒ Object Also known as: repo, repositories, repository

GET /repos/:user/:repo

Accepts either a user name and repo name as 2 arguments or one. Example:

Octoplex.repo('ivanvanderbyl/cloudist')
Octoplex.repo('ivanvanderbyl', 'cloudist')


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
# File 'lib/octoplex/client/root.rb', line 48

def repos(*user_and_repo)
  if user_and_repo.size == 2
    # We've been supplied two arguments
    user = user_and_repo[0]
    repo = user_and_repo[1]
  elsif user_and_repo.first.is_a?(String) && !user_and_repo.first.index('/').nil?
    # We've been supplied a string like "ivanvanderbyl/cloudist"
    user, repo = user_and_repo[0].split('/', 2)
  elsif user_and_repo.size == 1
    # We've been supplied one argument, probably a username
    user = user_and_repo[0]
    repo = nil
  else
    raise ArgumentError, "Unknown arguments: #{user_and_repo.split(', ')}"
  end
  if repo.nil?
    path = "/users/#{user}/repos"
  else
    path = "/repos/#{user}/#{repo}"
  end

  data = get(path)
  if data.is_a?(Array)
    data.map { |o| Octoplex::Client::Repository.new(self, o) }
  else
    Octoplex::Client::Repository.new(self, data)
  end
end