class UriBuilder

Constants

BASE_URL

base api string required for all calls

REPOS

string add-on to find repo related information

string add-on to search for relevant information

USERS

string add-on to find user related information

Attributes

base_url[RW]

Public Class Methods

new() click to toggle source
# File lib/github_api_ruby_lib/http/uri_builder.rb, line 40
def initialize
  @@token=''
end
set_personal_access_token(token) click to toggle source

sets the token to make authenticated requests

Attributes

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

# File lib/github_api_ruby_lib/http/uri_builder.rb, line 28
def self.set_personal_access_token(token)
  @@token=token
end

Public Instance Methods

get_repo_content(type, username, repo_name) { |String| ... } click to toggle source

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

# 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) { |String| ... } click to toggle source

Build API string for user related queries

Attributes

  • type -> Options to build API string

  • params -> Additional parameters to narrow search criteria

# 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_token() { |String| ... } click to toggle source

gets personal access token

# 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) { |String| ... } click to toggle source

Base API string to get all repos of user

Attributes

  • username -> username of account

# 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