Class: RepoHttpHandler

Inherits:
Object
  • Object
show all
Includes:
HttpHandler
Defined in:
lib/github_api_ruby_lib/http/repo_http_handler.rb

Constant Summary collapse

@@app_token =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HttpHandler

create_http, get_response, initiate_http

Constructor Details

#initializeRepoHttpHandler

Returns a new instance of RepoHttpHandler.



13
14
15
16
17
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 13

def initialize
  @@responseStatus=false
  @@uri_builder=UriBuilder.new

end

Class Method Details

.set_auth_token(token) ⇒ Object



20
21
22
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 20

def self.set_auth_token (token)
  @@app_token=token
end

Instance Method Details

#get_contributors_of_a_repository(username, repo_name) ⇒ Object

Get all contributors of a given repository

Attributes

  • username -> username of the account

  • repo_name -> name of repository



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 69

def get_contributors_of_a_repository(username,repo_name) # :yields: JSON
  uri=URI.parse(@@uri_builder.get_repo_content(Api_options::REPO::CONTRIBUTORS,username,repo_name))
  http= HttpHandler.initiate_http(uri)
  begin
    response=HttpHandler.get_response(http,uri)
  rescue ArgumentError
    puts "Request failed with code: #{response.code}"
  else
    @@responseStatus=true
    return response
  end
end

#get_languages_of_a_repository(username, repo_name) ⇒ Object

Retrieves all the major languages used in a repository

Attributes

  • username -> username of github repo

  • repo_name -> name of repository to get languages



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 29

def get_languages_of_a_repository(username, repo_name) # :yields: JSON
  uri=URI.parse(@@uri_builder.get_repo_content(Api_options::REPO::LANGUAGES,username,repo_name))
  http=HttpHandler.initiate_http(uri)

  begin
    response=HttpHandler.get_response(http,uri)
  rescue ArgumentError
    puts "Request failed with code: #{response.code}"
  else
    @@responseStatus=true
    return response
  end
end

#get_readme_of_a_repository(username, repo_name) ⇒ Object

Get README of given repository

Attributes

  • username -> username of the account

  • repo_name -> name of repository



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 87

def get_readme_of_a_repository(username,repo_name) # :yields: JSON
  uri=URI.parse(@@uri_builder.get_repo_content(Api_options::REPO::README,username,repo_name))
  http=HttpHandler.initiate_http(uri)
  begin
    response=HttpHandler.get_response(http,uri)
  rescue ArgumentError
    puts "Request failed with code: #{response.code}"
  else
    @@responseStatus=true
    return response
  end
end

#get_response_statusObject



44
45
46
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 44

def get_response_status
  @@responseStatus
end

#get_user_repos(username) ⇒ Object

Get a list of repositories for the given user

Attributes

  • username -> username of the account



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/github_api_ruby_lib/http/repo_http_handler.rb', line 51

def get_user_repos(username) # :yields: JSON
  uri=URI.parse(@@uri_builder.user_repos_url(username,@@app_token))
  http=HttpHandler.initiate_http(uri)
  begin
    response=HttpHandler.get_response(http,uri)
  rescue ArgumentError
    puts "Request failed with code: #{response.code}"
  else
    @@responseStatus=true
    return response
  end
end