Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More consistent formatting of requests in Client #219

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/octokit/client/authorizations.rb
Expand Up @@ -14,7 +14,7 @@ module Authorizations
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
# client.authorizations # client.authorizations
def authorizations(options={}) def authorizations(options={})
get 'authorizations', options get('authorizations', options)
end end




Expand All @@ -29,7 +29,7 @@ def authorizations(options={})
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
# client.authorization(999999) # client.authorization(999999)
def authorization(number, options={}) def authorization(number, options={})
get "authorizations/#{number}", options get("authorizations/#{number}", options)
end end


# Create an authorization for the authenticated user. # Create an authorization for the authenticated user.
Expand Down
50 changes: 26 additions & 24 deletions lib/octokit/client/commits.rb
Expand Up @@ -14,8 +14,7 @@ module Commits
# @return [Array] An array of hashes representing commits # @return [Array] An array of hashes representing commits
# @see http://developer.github.com/v3/repos/commits/ # @see http://developer.github.com/v3/repos/commits/
def commits(repo, sha_or_branch="master", options={}) def commits(repo, sha_or_branch="master", options={})
params = { :sha => sha_or_branch, :per_page => 35 } get("repos/#{Repository.new(repo)}/commits", options.merge({ :sha => sha_or_branch, :per_page => 35 }))
get("repos/#{Repository.new(repo)}/commits", params.merge(options))
end end
alias :list_commits :commits alias :list_commits :commits


Expand Down Expand Up @@ -49,9 +48,12 @@ def commit(repo, sha, options={})
# commit.message # => "My commit message" # commit.message # => "My commit message"
# commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... } # commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... }
def create_commit(repo, message, tree, parents=nil, options={}) def create_commit(repo, message, tree, parents=nil, options={})
params = { :message => message, :tree => tree } options.merge!({
params[:parents] = [parents].flatten if parents :message => message,
post("repos/#{Repository.new(repo)}/git/commits", options.merge(params)) :tree => tree
})
options[:parents] = [parents].flatten if parents
post("repos/#{Repository.new(repo)}/git/commits", options)
end end


# List all commit comments # List all commit comments
Expand Down Expand Up @@ -101,14 +103,14 @@ def commit_comment(repo, id, options={})
# commit.line # => 10 # commit.line # => 10
# commit.position # => 1 # commit.position # => 1
def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options={}) def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options={})
params = { options.merge!({
:body => body, :body => body,
:commit_id => sha, :commit_id => sha,
:path => path, :path => path,
:line => line, :line => line,
:position => position :position => position
} })
post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params)) post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options)
end end


# Update a commit comment # Update a commit comment
Expand All @@ -123,10 +125,7 @@ def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, opt
# commit.id # => 860296 # commit.id # => 860296
# commit.body # => "Updated commit comment" # commit.body # => "Updated commit comment"
def update_commit_comment(repo, id, body, options={}) def update_commit_comment(repo, id, body, options={})
params = { patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge({:body => body}))
:body => body
}
patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params))
end end


# Delete a commit comment # Delete a commit comment
Expand Down Expand Up @@ -159,11 +158,11 @@ def compare(repo, start, endd, options={})
# @return [Hashie::Mash] A hash representing the comparison # @return [Hashie::Mash] A hash representing the comparison
# @see http://developer.github.com/v3/repos/merging/ # @see http://developer.github.com/v3/repos/merging/
def merge(repo, base, head, options={}) def merge(repo, base, head, options={})
params = { options.merge!({
:base => base, :base => base,
:head => head :head => head
}.merge(options) })
post("repos/#{Repository.new(repo)}/merges", params) post("repos/#{Repository.new(repo)}/merges", options)
end end


# Get commits based on time windows # Get commits based on time windows
Expand All @@ -178,8 +177,7 @@ def merge(repo, base, head, options={})
# @example # @example
# Octokit.commits_since('pengwynn/octokit', '2012-10-01') # Octokit.commits_since('pengwynn/octokit', '2012-10-01')
def commits_since(repo, date, sha_or_branch="master", options={}) def commits_since(repo, date, sha_or_branch="master", options={})
params = {:since => iso8601(parse_date(date))} commits(repo, sha_or_branch, options.merge({:since => iso8601(parse_date(date))}))
commits(repo, sha_or_branch, params.merge(options))
end end


# Get commits before a specified date # Get commits before a specified date
Expand All @@ -192,8 +190,7 @@ def commits_since(repo, date, sha_or_branch="master", options={})
# @example # @example
# Octokit.commits_before('pengwynn/octokit', '2012-10-01') # Octokit.commits_before('pengwynn/octokit', '2012-10-01')
def commits_before(repo, date, sha_or_branch="master", options={}) def commits_before(repo, date, sha_or_branch="master", options={})
params = {:until => iso8601(parse_date(date))} commits(repo, sha_or_branch, options.merge({:until => iso8601(parse_date(date))}))
commits(repo, sha_or_branch, params.merge(options))
end end


# Get commits on a specified date # Get commits on a specified date
Expand All @@ -214,8 +211,11 @@ def commits_on(repo, date, sha_or_branch="master", options={})
rescue ArgumentError rescue ArgumentError
raise ArgumentError, "#{date} is not a valid date" raise ArgumentError, "#{date} is not a valid date"
end end
params = { :since => iso8601(start_date), :until => iso8601(end_date) } options.merge!({
commits(repo, sha_or_branch, params.merge(options)) :since => iso8601(start_date),
:until => iso8601(end_date)
})
commits(repo, sha_or_branch, options)
end end


# Get commits made between two nominated dates # Get commits made between two nominated dates
Expand Down Expand Up @@ -246,9 +246,11 @@ def commits_between(repo, start_date, end_date, sha_or_branch="master", options=
if _end_date < _start_date if _end_date < _start_date
raise ArgumentError, "Start date #{start_date} does not precede #{end_date}" raise ArgumentError, "Start date #{start_date} does not precede #{end_date}"
end end
params = {:since => iso8601(_start_date), options.merge!({
:until => iso8601(_end_date) } :since => iso8601(_start_date),
commits(repo, sha_or_branch, params.merge(options)) :until => iso8601(_end_date)
})
commits(repo, sha_or_branch, options)
end end


protected protected
Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/client/emojis.rb
Expand Up @@ -7,7 +7,7 @@ module Emojis
# @example List all emojis # @example List all emojis
# Octokit.emojis # Octokit.emojis
def emojis def emojis
get "emojis" get("emojis")
end end
end end
end end
Expand Down
26 changes: 12 additions & 14 deletions lib/octokit/client/gists.rb
Expand Up @@ -13,9 +13,9 @@ module Gists
# @see http://developer.github.com/v3/gists/#list-gists # @see http://developer.github.com/v3/gists/#list-gists
def gists(username=nil, options={}) def gists(username=nil, options={})
if username.nil? if username.nil?
get 'gists', options get('gists', options)
else else
get "users/#{username}/gists", options get("users/#{username}/gists", options)
end end
end end
alias :list_gists :gists alias :list_gists :gists
Expand All @@ -27,14 +27,14 @@ def gists(username=nil, options={})
# Octokit.public_gists # Octokit.public_gists
# @see http://developer.github.com/v3/gists/#list-gists # @see http://developer.github.com/v3/gists/#list-gists
def public_gists(options={}) def public_gists(options={})
get 'gists/public', options get('gists/public', options)
end end


# List the authenticated user’s starred gists # List the authenticated user’s starred gists
# #
# @return [Array<Hashie::Mash>] A list of gists # @return [Array<Hashie::Mash>] A list of gists
def starred_gists(options={}) def starred_gists(options={})
get 'gists/starred', options get('gists/starred', options)
end end


# Get a single gist # Get a single gist
Expand All @@ -43,7 +43,7 @@ def starred_gists(options={})
# @return [Hash::Mash] Gist information # @return [Hash::Mash] Gist information
# @see http://developer.github.com/v3/gists/#get-a-single-gist # @see http://developer.github.com/v3/gists/#get-a-single-gist
def gist(gist, options={}) def gist(gist, options={})
get "gists/#{Gist.new gist}", options get("gists/#{Gist.new gist}", options)
end end


# Create a gist # Create a gist
Expand All @@ -57,7 +57,7 @@ def gist(gist, options={})
# @return [Hashie::Mash] Newly created gist info # @return [Hashie::Mash] Newly created gist info
# @see http://developer.github.com/v3/gists/#create-a-gist # @see http://developer.github.com/v3/gists/#create-a-gist
def create_gist(options={}) def create_gist(options={})
post 'gists', options post('gists', options)
end end


# Edit a gist # Edit a gist
Expand All @@ -76,7 +76,7 @@ def create_gist(options={})
# [Hashie::Mash] Newly created gist info # [Hashie::Mash] Newly created gist info
# @see http://developer.github.com/v3/gists/#edit-a-gist # @see http://developer.github.com/v3/gists/#edit-a-gist
def edit_gist(gist, options={}) def edit_gist(gist, options={})
patch "gists/#{Gist.new gist}", options patch("gists/#{Gist.new gist}", options)
end end


# #
Expand Down Expand Up @@ -113,7 +113,7 @@ def gist_starred?(gist, options={})
# @return [Hashie::Mash] Data for the new gist # @return [Hashie::Mash] Data for the new gist
# @see http://developer.github.com/v3/gists/#fork-a-gist # @see http://developer.github.com/v3/gists/#fork-a-gist
def fork_gist(gist, options={}) def fork_gist(gist, options={})
post "gists/#{Gist.new gist}/forks", options post("gists/#{Gist.new gist}/forks", options)
end end


# Delete a gist # Delete a gist
Expand All @@ -133,7 +133,7 @@ def delete_gist(gist, options={})
# @example # @example
# Octokit.gist_comments('3528ae645') # Octokit.gist_comments('3528ae645')
def gist_comments(gist_id, options={}) def gist_comments(gist_id, options={})
get "gists/#{gist_id}/comments", options get("gists/#{gist_id}/comments", options)
end end


# Get gist comment # Get gist comment
Expand All @@ -145,7 +145,7 @@ def gist_comments(gist_id, options={})
# @example # @example
# Octokit.gist_comment('208sdaz3', 1451398) # Octokit.gist_comment('208sdaz3', 1451398)
def gist_comment(gist_id, gist_comment_id, options={}) def gist_comment(gist_id, gist_comment_id, options={})
get "gists/#{gist_id}/comments/#{gist_comment_id}", options get("gists/#{gist_id}/comments/#{gist_comment_id}", options)
end end


# Create gist comment # Create gist comment
Expand All @@ -160,8 +160,7 @@ def gist_comment(gist_id, gist_comment_id, options={})
# @example # @example
# @client.create_gist_comment('3528645', 'This is very helpful.') # @client.create_gist_comment('3528645', 'This is very helpful.')
def create_gist_comment(gist_id, comment, options={}) def create_gist_comment(gist_id, comment, options={})
options.merge!({:body => comment}) post("gists/#{gist_id}/comments", options.merge({:body => comment}))
post "gists/#{gist_id}/comments", options
end end


# Update gist comment # Update gist comment
Expand All @@ -177,8 +176,7 @@ def create_gist_comment(gist_id, comment, options={})
# @example # @example
# @client.update_gist_comment('208sdaz3', '3528645', ':heart:') # @client.update_gist_comment('208sdaz3', '3528645', ':heart:')
def update_gist_comment(gist_id, gist_comment_id, comment, options={}) def update_gist_comment(gist_id, gist_comment_id, comment, options={})
options.merge!({:body => comment}) patch("gists/#{gist_id}/comments/#{gist_comment_id}", options.merge({:body => comment}))
patch "gists/#{gist_id}/comments/#{gist_comment_id}", options
end end


# Delete gist comment # Delete gist comment
Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/client/github.rb
Expand Up @@ -11,7 +11,7 @@ module GitHub
# @example Get GitHub meta information # @example Get GitHub meta information
# @client.github_meta # @client.github_meta
def github_meta(options={}) def github_meta(options={})
get "/meta", options get("/meta", options)
end end


end end
Expand Down
4 changes: 2 additions & 2 deletions lib/octokit/client/gitignore.rb
Expand Up @@ -14,7 +14,7 @@ module Gitignore
# @example Git all the gitignore templates # @example Git all the gitignore templates
# @client.gitignore_templates # @client.gitignore_templates
def gitignore_templates(options={}) def gitignore_templates(options={})
get "/gitignore/templates", options get("/gitignore/templates", options)
end end


# Get a gitignore template. # Get a gitignore template.
Expand All @@ -33,7 +33,7 @@ def gitignore_templates(options={})
# @example Get the Ruby gitignore template # @example Get the Ruby gitignore template
# @client.gitignore_template('Ruby') # @client.gitignore_template('Ruby')
def gitignore_template(template_name, options={}) def gitignore_template(template_name, options={})
get "/gitignore/templates/#{template_name}", options get("/gitignore/templates/#{template_name}", options)
end end


end end
Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/client/issues.rb
Expand Up @@ -139,7 +139,7 @@ def update_issue(repo, number, title, body, options={})
# :since => '2010-05-04T23:45:02Z' # :since => '2010-05-04T23:45:02Z'
# }) # })
def issues_comments(repo, options={}) def issues_comments(repo, options={})
get "/repos/#{Repository.new repo}/issues/comments", options get("/repos/#{Repository.new repo}/issues/comments", options)
end end


# Get all comments attached to an issue # Get all comments attached to an issue
Expand Down
9 changes: 4 additions & 5 deletions lib/octokit/client/objects.rb
Expand Up @@ -32,8 +32,7 @@ def tree(repo, tree_sha, options={})
# tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7" # tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7"
# tree.tree.first.path # => "file.rb" # tree.tree.first.path # => "file.rb"
def create_tree(repo, tree, options={}) def create_tree(repo, tree, options={})
parameters = { :tree => tree } post("repos/#{Repository.new(repo)}/git/trees", options.merge({:tree => tree}))
post("repos/#{Repository.new(repo)}/git/trees", options.merge(parameters))
end end


# Get a single blob, fetching its content and encoding # Get a single blob, fetching its content and encoding
Expand Down Expand Up @@ -69,11 +68,11 @@ def blob(repo, blob_sha, options={})
# require "base64" # require "base64"
# Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64") # Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64")
def create_blob(repo, content, encoding="utf-8", options={}) def create_blob(repo, content, encoding="utf-8", options={})
parameters = { options.merge!({
:content => content, :content => content,
:encoding => encoding :encoding => encoding
} })
post("repos/#{Repository.new(repo)}/git/blobs", options.merge(parameters)).sha post("repos/#{Repository.new(repo)}/git/blobs", options).sha
end end


# Get a tag # Get a tag
Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/client/organizations.rb
Expand Up @@ -366,7 +366,7 @@ def team_repositories(team_id, options={})
# @example # @example
# @client.add_team_repo(100000, 'github/developer.github.com') # @client.add_team_repo(100000, 'github/developer.github.com')
def add_team_repository(team_id, repo, options={}) def add_team_repository(team_id, repo, options={})
boolean_from_response(:put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo))) boolean_from_response(:put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge({:name => Repository.new(repo)}))
end end
alias :add_team_repo :add_team_repository alias :add_team_repo :add_team_repository


Expand Down
12 changes: 6 additions & 6 deletions lib/octokit/client/refs.rb
Expand Up @@ -40,11 +40,11 @@ def ref(repo, ref, options={})
# @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132 # @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132
# Octokit.create_ref("octocat/Hello-World","heads/master", "827efc6d56897b048c772eb4087f854f46256132") # Octokit.create_ref("octocat/Hello-World","heads/master", "827efc6d56897b048c772eb4087f854f46256132")
def create_ref(repo, ref, sha, options={}) def create_ref(repo, ref, sha, options={})
parameters = { options.merge!({
:ref => "refs/#{ref}", :ref => "refs/#{ref}",
:sha => sha :sha => sha
} })
post("repos/#{Repository.new(repo)}/git/refs", options.merge(parameters)) post("repos/#{Repository.new(repo)}/git/refs", options)
end end
alias :create_reference :create_ref alias :create_reference :create_ref


Expand All @@ -59,11 +59,11 @@ def create_ref(repo, ref, sha, options={})
# @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
# Octokit.update_ref("octocat/Hello-World","heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd") # Octokit.update_ref("octocat/Hello-World","heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
def update_ref(repo, ref, sha, force=true, options={}) def update_ref(repo, ref, sha, force=true, options={})
parameters = { options.merge!({
:sha => sha, :sha => sha,
:force => force :force => force
} })
patch("repos/#{Repository.new(repo)}/git/refs/#{ref}", options.merge(parameters)) patch("repos/#{Repository.new(repo)}/git/refs/#{ref}", options)
end end
alias :update_reference :update_ref alias :update_reference :update_ref


Expand Down