lib/github_api/gists.rb in github_api-0.9.0 vs lib/github_api/gists.rb in github_api-0.9.1
- old
+ new
@@ -30,16 +30,14 @@
#
# = Examples
# github = Github.new :oauth_token => '...'
# github.gists.list
#
- def list(params={})
- normalize! params
+ def list(*args)
+ params = arguments(args).params
- user = params.delete('user')
-
- response = if user
+ response = if (user = params.delete('user'))
get_request("/users/#{user}/gists", params)
elsif oauth_token
get_request("/gists", params)
else
get_request("/gists/public", params)
@@ -53,29 +51,27 @@
#
# = Examples
# github = Github.new :oauth_token => '...'
# github.gists.starred
#
- def starred(params={})
- normalize! params
-
- response = get_request("/gists/starred", params)
+ def starred(*args)
+ arguments(args)
+ response = get_request("/gists/starred", arguments.params)
return response unless block_given?
response.each { |el| yield el }
end
# Get a single gist
#
# = Examples
# github = Github.new
# github.gists.get 'gist-id'
#
- def get(gist_id, params={})
- normalize! params
- assert_presence_of gist_id
+ def get(*args)
+ arguments(args, :required => [:gist_id])
- get_request("/gists/#{gist_id}", params)
+ get_request("/gists/#{gist_id}", arguments.params)
end
alias :find :get
# Create a gist
#
@@ -96,15 +92,16 @@
# 'file1.txt' => {
# 'content' => 'String file contents'
# }
# }
#
- def create(params={})
- normalize! params
- assert_required_keys(REQUIRED_GIST_INPUTS, params)
+ def create(*args)
+ arguments(args) do
+ assert_required REQUIRED_GIST_INPUTS
+ end
- post_request("/gists", params)
+ post_request("/gists", arguments.params)
end
# Edit a gist
#
# = Inputs
@@ -131,54 +128,49 @@
# 'content' => 'a new file contents'
# },
# 'delete_the_file.txt' => nil
# }
#
- def edit(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
+ def edit(*args)
+ arguments(args, :required => [:gist_id])
- patch_request("/gists/#{gist_id}", params)
+ patch_request("/gists/#{gist_id}", arguments.params)
end
# Star a gist
#
# = Examples
# github = Github.new
# github.gists.star 'gist-id'
#
- def star(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
+ def star(*args)
+ arguments(args, :required => [:gist_id])
- put_request("/gists/#{gist_id}/star", params)
+ put_request("/gists/#{gist_id}/star", arguments.params)
end
# Unstar a gist
#
# = Examples
# github = Github.new
# github.gists.unstar 'gist-id'
#
- def unstar(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
+ def unstar(*args)
+ arguments(args, :required => [:gist_id])
- delete_request("/gists/#{gist_id}/star", params)
+ delete_request("/gists/#{gist_id}/star", arguments.params)
end
# Check if a gist is starred
#
# = Examples
# github = Github.new
# github.gists.starred? 'gist-id'
#
- def starred?(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
-
- get_request("/gists/#{gist_id}/star", params)
+ def starred?(*args)
+ arguments(args, :required => [:gist_id])
+ get_request("/gists/#{gist_id}/star", arguments.params)
true
rescue Github::Error::NotFound
false
end
@@ -186,27 +178,25 @@
#
# = Examples
# github = Github.new
# github.gists.fork 'gist-id'
#
- def fork(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
+ def fork(*args)
+ arguments(args, :required => [:gist_id])
- post_request("/gists/#{gist_id}/fork", params)
+ post_request("/gists/#{gist_id}/fork", arguments.params)
end
# Delete a gist
#
# = Examples
# github = Github.new
# github.gists.delete 'gist-id'
#
- def delete(gist_id, params={})
- assert_presence_of gist_id
- normalize! params
+ def delete(*args)
+ arguments(args, :required => [:gist_id])
- delete_request("/gists/#{gist_id}", params)
+ delete_request("/gists/#{gist_id}", arguments.params)
end
end # Gists
end # Github