Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use "boolean_from_response" for truthy response checking

  • Loading branch information...
commit ff35fb28f39bc857db78e02c610f707a113d3ba6 1 parent 12d3ff3
@x3ro x3ro authored
View
2  lib/octokit/client/authorizations.rb
@@ -93,7 +93,7 @@ def update_authorization(number, options={})
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
# client.delete_authorization(999999)
def delete_authorization(number, option={})
- request(:delete, "authorizations/#{number}").status == 204
+ boolean_from_response(:delete, "authorizations/#{number}")
end
# Check scopes for a token
View
2  lib/octokit/client/commits.rb
@@ -136,7 +136,7 @@ def update_commit_comment(repo, id, body, options={})
# @return [nil] nil
# @see http://developer.github.com/v3/repos/comments/
def delete_commit_comment(repo, id, options={})
- request(:delete, "repos/#{Repository.new(repo)}/comments/#{id}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/comments/#{id}", options)
end
# Compare two commits
View
2  lib/octokit/client/downloads.rb
@@ -72,7 +72,7 @@ def create_download(repo, name, options={})
# @example Get the "Robawt" download from Github/Hubot
# Octokit.delete_download("github/hubot", 1234)
def delete_download(repo, id)
- request(:delete, "repos/#{Repository.new(repo)}/downloads/#{id}").status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/downloads/#{id}")
end
private
View
16 lib/octokit/client/gists.rb
@@ -86,7 +86,7 @@ def edit_gist(gist, options={})
# @return [Boolean] Indicates if gist is starred successfully
# @see http://developer.github.com/v3/gists/#star-a-gist
def star_gist(gist, options={})
- request(:put, "gists/#{Gist.new gist}/star", options).status == 204
+ boolean_from_response(:put, "gists/#{Gist.new gist}/star", options)
end
# Unstar a gist
@@ -95,7 +95,7 @@ def star_gist(gist, options={})
# @return [Boolean] Indicates if gist is unstarred successfully
# @see http://developer.github.com/v3/gists/#unstar-a-gist
def unstar_gist(gist, options={})
- request(:delete, "gists/#{Gist.new gist}/star", options).status == 204
+ boolean_from_response(:delete, "gists/#{Gist.new gist}/star", options)
end
# Check if a gist is starred
@@ -104,12 +104,7 @@ def unstar_gist(gist, options={})
# @return [Boolean] Indicates if gist is starred
# @see http://developer.github.com/v3/gists/#check-if-a-gist-is-starred
def gist_starred?(gist, options={})
- begin
- get("gists/#{Gist.new gist}/star", options)
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:get, "gists/#{Gist.new gist}/star", options)
end
# Fork a gist
@@ -127,8 +122,7 @@ def fork_gist(gist, options={})
# @return [Boolean] Indicating success of deletion
# @see http://developer.github.com/v3/gists/#delete-a-gist
def delete_gist(gist, options={})
- response = request(:delete, "gists/#{Gist.new gist}", options)
- response.status == 204
+ boolean_from_response(:delete, "gists/#{Gist.new gist}", options)
end
# List gist comments
@@ -199,7 +193,7 @@ def update_gist_comment(gist_id, gist_comment_id, comment, options={})
# @example
# @client.delete_gist_comment('208sdaz3', '586399')
def delete_gist_comment(gist_id, gist_comment_id, options={})
- request(:delete, "gists/#{gist_id}/comments/#{gist_comment_id}", options).status == 204
+ boolean_from_response(:delete, "gists/#{gist_id}/comments/#{gist_comment_id}", options)
end
end
View
2  lib/octokit/client/issues.rb
@@ -201,7 +201,7 @@ def update_comment(repo, number, comment, options={})
# @example Delete the comment "I've started this on my 25-issue-comments-v3 fork" on Issue #25 on pengwynn/octokit
# Octokit.delete_comment("pengwynn/octokit", 1194549)
def delete_comment(repo, number, options={})
- request(:delete, "repos/#{Repository.new(repo)}/issues/comments/#{number}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/issues/comments/#{number}", options)
end
View
4 lib/octokit/client/labels.rb
@@ -67,7 +67,7 @@ def update_label(repo, label, options={})
# @example Delete the label "Version 1.0" from the repository.
# Octokit.delete_label!("pengwynn/octokit", "Version 1.0")
def delete_label!(repo, label, options={})
- request(:delete, "repos/#{Repository.new(repo)}/labels/#{CGI.escape(label)}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/labels/#{CGI.escape(label)}", options)
end
# Remove a label from an Issue
@@ -97,7 +97,7 @@ def remove_label(repo, number, label, options={})
# @example Remove all labels from Issue #23
# Octokit.remove_all_labels("pengwynn/octokit", 23)
def remove_all_labels(repo, number, options={})
- request(:delete, "repos/#{Repository.new(repo)}/issues/#{number}/labels", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/issues/#{number}/labels", options)
end
# List labels for a given issue
View
2  lib/octokit/client/milestones.rb
@@ -79,7 +79,7 @@ def update_milestone(repository, number, options={})
# @example Delete a single milestone from a repository
# Octokit.delete_milestone("pengwynn/octokit", 1)
def delete_milestone(repository, number, options={})
- request(:delete, "repos/#{Repository.new(repository)}/milestones/#{number}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repository)}/milestones/#{number}", options)
end
end
View
2  lib/octokit/client/notifications.rb
@@ -211,7 +211,7 @@ def update_thread_subscription(thread_id, options={})
# @client.delete_thread_subscription(1)
def delete_thread_subscription(thread_id, options={})
begin
- request(:delete, "notifications/threads/#{thread_id}", options).status == 204
+ boolean_from_response(:delete, "notifications/threads/#{thread_id}", options)
rescue
false
end
View
24 lib/octokit/client/organizations.rb
@@ -146,9 +146,7 @@ def organization_members(org, options={})
# @client.organization_member?('your_organization', 'pengwynn')
# => false
def organization_member?(org, user, options={})
- request(:get, "orgs/#{org}/members/#{user}", options).status == 204
- rescue Octokit::NotFound
- false
+ boolean_from_response(:get, "orgs/#{org}/members/#{user}", options)
end
alias :org_member? :organization_member?
@@ -168,9 +166,7 @@ def organization_member?(org, user, options={})
# @client.organization_public_member?('github', 'pengwynn')
# => true
def organization_public_member?(org, user, options={})
- request(:get, "orgs/#{org}/public_members/#{user}", options).status == 204
- rescue Octokit::NotFound
- false
+ boolean_from_response(:get, "orgs/#{org}/public_members/#{user}", options)
end
alias :org_public_member? :organization_public_member?
@@ -265,7 +261,7 @@ def update_team(team_id, options={})
# @example
# @client.delete_team(100000)
def delete_team(team_id, options={})
- request(:delete, "teams/#{team_id}", options).status == 204
+ boolean_from_response(:delete, "teams/#{team_id}", options)
end
# List team members
@@ -298,7 +294,7 @@ def add_team_member(team_id, user, options={})
# There's a bug in this API call. The docs say to leave the body blank,
# but it fails if the body is both blank and the content-length header
# is not 0.
- request(:put, "teams/#{team_id}/members/#{user}", options.merge({:name => user})).status == 204
+ boolean_from_response(:put, "teams/#{team_id}/members/#{user}", options.merge({:name => user}))
end
# Remove team member
@@ -314,7 +310,7 @@ def add_team_member(team_id, user, options={})
# @example
# @client.remove_team_member(100000, 'pengwynn')
def remove_team_member(team_id, user, options={})
- request(:delete, "teams/#{team_id}/members/#{user}", options).status == 204
+ boolean_from_response(:delete, "teams/#{team_id}/members/#{user}", options)
end
# List team repositories
@@ -351,7 +347,7 @@ def team_repositories(team_id, options={})
# @example
# @client.add_team_repo(100000, 'github/developer.github.com')
def add_team_repository(team_id, repo, options={})
- request(:put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo))).status == 204
+ boolean_from_response(:put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo)))
end
alias :add_team_repo :add_team_repository
@@ -372,7 +368,7 @@ def add_team_repository(team_id, repo, options={})
# @example
# @client.remove_team_repo(100000, 'github/developer.github.com')
def remove_team_repository(team_id, repo, options={})
- request(:delete, "teams/#{team_id}/repos/#{Repository.new(repo)}").status == 204
+ boolean_from_response(:delete, "teams/#{team_id}/repos/#{Repository.new(repo)}")
end
alias :remove_team_repo :remove_team_repository
@@ -392,7 +388,7 @@ def remove_team_repository(team_id, repo, options={})
def remove_organization_member(org, user, options={})
# this is a synonym for: for team in org.teams: remove_team_member(team.id, user)
# provided in the GH API v3
- request(:delete, "orgs/#{org}/members/#{user}", options).status == 204
+ boolean_from_response(:delete, "orgs/#{org}/members/#{user}", options)
end
alias :remove_org_member :remove_organization_member
@@ -408,7 +404,7 @@ def remove_organization_member(org, user, options={})
# @example
# @client.publicize_membership('github', 'pengwynn')
def publicize_membership(org, user, options={})
- request(:put, "orgs/#{org}/public_members/#{user}", options).status == 204
+ boolean_from_response(:put, "orgs/#{org}/public_members/#{user}", options)
end
# Conceal a user's membership of an organization.
@@ -425,7 +421,7 @@ def publicize_membership(org, user, options={})
# @example
# @client.conceal_membership('github', 'pengwynn')
def unpublicize_membership(org, user, options={})
- request(:delete, "orgs/#{org}/public_members/#{user}", options).status == 204
+ boolean_from_response(:delete, "orgs/#{org}/public_members/#{user}", options)
end
alias :conceal_membership :unpublicize_membership
View
9 lib/octokit/client/pulls.rb
@@ -232,7 +232,7 @@ def update_pull_request_comment(repo, comment_id, body, options={})
# @example
# @client.delete_pull_request_comment("pengwynn/octokit", 1902707)
def delete_pull_request_comment(repo, comment_id, options={})
- request(:delete, "repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options)
end
alias :delete_pull_comment :delete_pull_request_comment
alias :delete_review_comment :delete_pull_request_comment
@@ -266,12 +266,7 @@ def merge_pull_request(repo, number, commit_message='', options={})
# @param number [Integer] Number of pull request
# @return [Boolean] True if the pull request has been merged
def pull_merged?(repo, number, options={})
- begin
- get("repos/#{Repository.new(repo)}/pulls/#{number}/merge", options)
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:get, "repos/#{Repository.new(repo)}/pulls/#{number}/merge", options)
end
alias :pull_request_merged? :pull_merged?
View
2  lib/octokit/client/refs.rb
@@ -76,7 +76,7 @@ def update_ref(repo, ref, sha, force=true, options={})
# @example Delete tags/v0.0.3 for sferik/rails_admin
# Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")
def delete_ref(repo, ref, options={})
- request(:delete, "repos/#{Repository.new(repo)}/git/refs/#{ref}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new(repo)}/git/refs/#{ref}", options)
end
alias :delete_reference :delete_ref
View
47 lib/octokit/client/repositories.rb
@@ -83,12 +83,7 @@ def all_repositories(options={})
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully starred
def star(repo, options={})
- begin
- put "user/starred/#{Repository.new repo}", options
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:put, "user/starred/#{Repository.new repo}", options)
end
# Unstar a repository
@@ -96,12 +91,7 @@ def star(repo, options={})
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully unstarred
def unstar(repo, options={})
- begin
- request :delete, "user/starred/#{Repository.new repo}", options
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:delete, "user/starred/#{Repository.new repo}", options)
end
# Watch a repository
@@ -110,12 +100,7 @@ def unstar(repo, options={})
# @return [Boolean] `true` if successfully watched
# @deprecated Use #star instead
def watch(repo, options={})
- begin
- put "user/watched/#{Repository.new repo}", options
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:put, "user/watched/#{Repository.new repo}", options)
end
# Unwatch a repository
@@ -124,12 +109,7 @@ def watch(repo, options={})
# @return [Boolean] `true` if successfully unwatched
# @deprecated Use #unstar instead
def unwatch(repo, options={})
- begin
- request :delete, "user/watched/#{Repository.new repo}", options
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:delete, "user/watched/#{Repository.new repo}", options)
end
# Fork a repository
@@ -176,12 +156,7 @@ def create_repository(name, options={})
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if repository was deleted
def delete_repository(repo, options={})
- begin
- request :delete, "repos/#{Repository.new repo}", options
- return true
- rescue Octokit::NotFound
- return false
- end
+ boolean_from_response(:delete, "repos/#{Repository.new repo}", options)
end
alias :delete_repo :delete_repository
@@ -248,7 +223,7 @@ def add_deploy_key(repo, title, key, options={})
# @example
# @client.remove_deploy_key('pengwynn/octokit', 100000)
def remove_deploy_key(repo, id, options={})
- request(:delete, "repos/#{Repository.new repo}/keys/#{id}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new repo}/keys/#{id}", options)
end
# List collaborators
@@ -284,7 +259,7 @@ def collaborators(repo, options={})
# @example
# @client.add_collab('pengwynn/octokit', 'holman')
def add_collaborator(repo, collaborator, options={})
- request(:put, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options).status == 204
+ boolean_from_response(:put, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options)
end
alias :add_collab :add_collaborator
@@ -302,7 +277,7 @@ def add_collaborator(repo, collaborator, options={})
# @example
# @client.remove_collab('pengwynn/octokit', 'holman')
def remove_collaborator(repo, collaborator, options={})
- request(:delete, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options)
end
alias :remove_collab :remove_collaborator
@@ -580,7 +555,7 @@ def edit_hook(repo, id, name, config, options={})
# @example
# @client.remove_hook('pengwynn/octokit', 1000000)
def remove_hook(repo, id, options={})
- request(:delete, "repos/#{Repository.new repo}/hooks/#{id}", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new repo}/hooks/#{id}", options)
end
# Test hook
@@ -595,7 +570,7 @@ def remove_hook(repo, id, options={})
# @example
# @client.test_hook('pengwynn/octokit', 1000000)
def test_hook(repo, id, options={})
- request(:post, "repos/#{Repository.new repo}/hooks/#{id}/tests", options).status == 204
+ boolean_from_response(:post, "repos/#{Repository.new repo}/hooks/#{id}/tests", options)
end
# Get all Issue Events for a given Repository
@@ -691,7 +666,7 @@ def update_subscription(repo, options={})
# @client.delete_subscription("pengwynn/octokit")
def delete_subscription(repo, options={})
begin
- request(:delete, "repos/#{Repository.new repo}/subscription", options).status == 204
+ boolean_from_response(:delete, "repos/#{Repository.new repo}/subscription", options)
rescue
false
end
View
16 lib/octokit/client/users.rb
@@ -112,9 +112,7 @@ def follows?(*args)
user = args.first
user ||= login
return if user.nil?
- request(:get, "user/following/#{target}").status == 204
- rescue Octokit::NotFound
- false
+ boolean_from_response(:get, "user/following/#{target}")
end
# Follow a user.
@@ -128,7 +126,7 @@ def follows?(*args)
# @example
# @client.follow('holman')
def follow(user, options={})
- request(:put, "user/following/#{user}", options).status == 204
+ boolean_from_response(:put, "user/following/#{user}", options)
end
# Unfollow a user.
@@ -142,7 +140,7 @@ def follow(user, options={})
# @example
# @client.unfollow('holman')
def unfollow(user, options={})
- request(:delete, "user/following/#{user}", options).status == 204
+ boolean_from_response(:delete, "user/following/#{user}", options)
end
# Get list of repos starred by a user.
@@ -168,9 +166,7 @@ def starred(user=login, options={})
# @example
# @client.starred?('pengwynn', 'octokit')
def starred?(user, repo, options={})
- request(:get, "user/starred/#{user}/#{repo}", options).status == 204
- rescue Octokit::NotFound
- false
+ boolean_from_response(:get, "user/starred/#{user}/#{repo}", options)
end
# Get list of repos watched by a user.
@@ -269,7 +265,7 @@ def update_key(key_id, options={})
# @example
# @client.remove_key(1)
def remove_key(id, options={})
- request(:delete, "user/keys/#{id}", options).status == 204
+ boolean_from_response(:delete, "user/keys/#{id}", options)
end
# List email addresses for a user.
@@ -310,7 +306,7 @@ def add_email(email, options={})
# @example
# @client.remove_email('old_email@user.com')
def remove_email(email, options={})
- request(:delete, "user/emails", options.merge({:email => email})).status == 204
+ boolean_from_response(:delete, "user/emails", options.merge({:email => email}))
end
# List repositories being watched by a user.
Please sign in to comment.
Something went wrong with that request. Please try again.