Class: UriBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/github_api_ruby_lib/http/uri_builder.rb

Constant Summary collapse

BASE_URL =

base api string required for all calls

"https://api.github.com/"
USERS =

string add-on to find user related information

"users/"
SEARCH =

string add-on to search for relevant information

"search/"
REPOS =

string add-on to find repo related information

"repos/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUriBuilder

Returns a new instance of UriBuilder.



40
41
42
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 40

def initialize
  @@token=''
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 5

def base_url
  @base_url
end

Class Method Details

.set_personal_access_token(token) ⇒ Object

sets the token to make authenticated requests

Attributes

  • token -> [String] app token needed to make authenticated requests



28
29
30
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 28

def self.set_personal_access_token(token)
  @@token=token
end

Instance Method Details

#get_repo_content(type, username, repo_name) ⇒ Object

Build API string for repository related queries

Attributes

  • type -> Options to build API string

  • username -> username of account to access repo content

  • repo_name -> name of repository



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 59

def get_repo_content(type, username, repo_name) # :yields: String
  case type

    when Api_options::REPO::LANGUAGES
      "#{BASE_URL}" +  "#{REPOS}" + "#{username}/" + "#{repo_name}/languages"
    when Api_options::REPO::CONTRIBUTORS
      BASE_URL + REPOS + "#{username}" + "/" + "#{repo_name}" + "/" + "contributors"
    when Api_options::REPO::README
      BASE_URL + REPOS + "#{username}" + "/" + "#{repo_name}" + "/" + "readme"
  end
end

#get_user_contents(type, params) ⇒ Object

Build API string for user related queries

Attributes

  • type -> Options to build API string

  • params -> Additional parameters to narrow search criteria



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 76

def get_user_contents(type, params) # :yields: String
  case type
    when Api_options::USER::EMAIL
      unless personal_access_token.nil?
        "#{BASE_URL}user/emails?access_token=#{params[:app_token]}"
      else
        raise "Authentication required"
      end
    when Api_options::USER::SEARCH
      unless params[:number_of_repos] == nil
        return BASE_URL + SEARCH + USERS + "q=#{params[:by_name]}+repos=#{params[:number_of_repos]}"
      else
        return BASE_URL + SEARCH + USERS + "q=#{params[:by_name]}"
      end
    when Api_options::USER::FOLLOWERS
       BASE_URL + USERS + "#{params[:username]}/followers?access_token=#{params[:token]}"
  end
end

#personal_access_tokenObject

gets personal access token



34
35
36
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 34

def personal_access_token # :yields: String
  @@token
end

#user_repos_url(username, token) ⇒ Object

Base API string to get all repos of user

Attributes

  • username -> username of account



48
49
50
# File 'lib/github_api_ruby_lib/http/uri_builder.rb', line 48

def user_repos_url(username,token) # :yields:String
  BASE_URL + USERS + "#{username}/" + "repos?access_token=#{token}"
end