diff --git a/lib/gitlab/client/snippets.rb b/lib/gitlab/client/snippets.rb index e11127926..6cce53877 100644 --- a/lib/gitlab/client/snippets.rb +++ b/lib/gitlab/client/snippets.rb @@ -1,6 +1,21 @@ class Gitlab::Client # Defines methods related to snippets. module Snippets + # Gets a list of project's snippets. + # + # @example + # Gitlab.snippets(42) + # Gitlab.snippets('gitlab') + # + # @param [Integer, String] project The ID or code name of a project. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. + # @return [Gitlab::ObjectifiedHash] + def snippets(project, options={}) + get("/projects/#{project}/snippets", :query => options) + end + # Gets information about a snippet. # # @example diff --git a/spec/fixtures/snippets.json b/spec/fixtures/snippets.json new file mode 100644 index 000000000..26457995c --- /dev/null +++ b/spec/fixtures/snippets.json @@ -0,0 +1 @@ +[{"id":1,"title":"Rails Console ActionMailer","file_name":"mailer_test.rb","author":{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-09-17T09:41:56Z"},"expires_at":"2012-09-24T00:00:00Z","updated_at":"2012-09-17T09:51:42Z","created_at":"2012-09-17T09:51:42Z"}] diff --git a/spec/gitlab/client/snippets_spec.rb b/spec/gitlab/client/snippets_spec.rb index 01ef01cb1..c1db6b0f4 100644 --- a/spec/gitlab/client/snippets_spec.rb +++ b/spec/gitlab/client/snippets_spec.rb @@ -1,6 +1,22 @@ require 'spec_helper' describe Gitlab::Client do + describe ".snippets" do + before do + stub_get("/projects/3/snippets", "snippets") + @snippets = Gitlab.snippets(3) + end + + it "should get the correct resource" do + a_get("/projects/3/snippets").should have_been_made + end + + it "should return an array of project's snippets" do + @snippets.should be_an Array + @snippets.first.file_name.should == "mailer_test.rb" + end + end + describe ".snippet" do before do stub_get("/projects/3/snippets/1", "snippet")