Created
March 22, 2017 03:04
-
-
Save soumyaray/3de09827ed543bb8ab12224eb3fc0030 to your computer and use it in GitHub Desktop.
some refactoring ideas for repominer api library code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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