Skip to content

Instantly share code, notes, and snippets.

@soumyaray
Created March 22, 2017 03:04
Show Gist options
  • Save soumyaray/3de09827ed543bb8ab12224eb3fc0030 to your computer and use it in GitHub Desktop.
Save soumyaray/3de09827ed543bb8ab12224eb3fc0030 to your computer and use it in GitHub Desktop.
some refactoring ideas for repominer api library code
base_url = "http://api.githbub.com/v1"
def commits_history
repo_username = "leoli0320"
repo_name = "my_fav_repo"
api_endpoint = [base_url, repo_username, repo_name, 'commits'].join('/')
req_params = {}
req_params[:access_token] = "kasdkjncs823"
req_params[:since] = @update_time if @update_time
req_params[:state] = 'all'
# TODO: pagination loop
call_api_pages(api_endpoint, req_params)
end
def call_api_pages(api_endpoint, req_params)
fetch_hist = {}
req_params[:page] = 1
until false
api_call_url = generate_api_url(api_endpoint, req_params)
fetch = get_call(api_call_url)
break if no_more_pages(fetch)
fetch_hist << fetch
req_params[:page] += 1
end
end
private
def generate_api_url(url, req_params)
req_params.map { |key, value| "#{key}=#{value}" }.join('&')
[url, api_params].join('?')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment