Module: Pod::GitHub

Defined in:
lib/cocoapods-core/github.rb

Overview

Allows to access information about the GitHub repos.

This class is stored in Core because it might be used by web services.

Private helpers collapse

Class Method Summary collapse

Class Method Details

.branches(url) ⇒ Array

Returns the branches of a repo.

Parameters:

  • url (String)

    @see #repo

Returns:

  • (Array)

    The list of the branches.



51
52
53
54
55
# File 'lib/cocoapods-core/github.rb', line 51

def self.branches(url)
  if repo_id = normalized_repo_id(url)
    peform_request("https://api.github.com/repos/#{repo_id}/branches")
  end
end

.normalized_repo_id(url_or_id) ⇒ String

Returns the repo ID as it is or converting a GitHub URL.

Parameters:

  • url_or_id (String)

    A repo ID or the URL of the repo.

Returns:

  • (String)

    the repo ID.



70
71
72
# File 'lib/cocoapods-core/github.rb', line 70

def self.normalized_repo_id(url_or_id)
  repo_id_from_url(url_or_id) || url_or_id
end

.peform_request(url) ⇒ Array, Hash

Performs a get request with the given URL.

Parameters:

  • url (String)

    The URL of the resource.

Returns:

  • (Array, Hash)

    The information of the resource as Ruby objects.



93
94
95
96
97
98
# File 'lib/cocoapods-core/github.rb', line 93

def self.peform_request(url)
  require 'rest'
  require 'json'
  response = REST.get(url)
  JSON.parse(response.body)
end

.repo(url) ⇒ Hash

Returns the information of a repo.

Parameters:

  • url (String)

    The URL of the repo.

Returns:

  • (Hash)

    The hash containing the data as reported by GitHub.



27
28
29
30
31
# File 'lib/cocoapods-core/github.rb', line 27

def self.repo(url)
  if repo_id = normalized_repo_id(url)
    peform_request("https://api.github.com/repos/#{repo_id}")
  end
end

.repo_id_from_url(url) ⇒ String, Nil

Returns the repo ID given it’s URL.

Parameters:

  • url (String)

    The URL of the repo.

Returns:

  • (String)

    the repo ID.

  • (Nil)

    if the given url is not a valid github repo url.



82
83
84
# File 'lib/cocoapods-core/github.rb', line 82

def self.repo_id_from_url(url)
  url[%r[github.com/([^/\.]*/[^/\.]*)\.*], 1]
end

.tags(url) ⇒ Array

Returns the tags of a repo.

Parameters:

  • url (String)

    @see #repo

Returns:

  • (Array)

    The list of the tags.



39
40
41
42
43
# File 'lib/cocoapods-core/github.rb', line 39

def self.tags(url)
  if repo_id = normalized_repo_id(url)
    peform_request("https://api.github.com/repos/#{repo_id}/tags")
  end
end

.user(login) ⇒ Hash

Returns the information of a user.

Parameters:

  • login (String)

    The name of the user.

Returns:

  • (Hash)

    The data of user.



16
17
18
# File 'lib/cocoapods-core/github.rb', line 16

def self.user()
  peform_request("https://api.github.com/users/#{login}")
end