Commit 9ee6c58accfd51036d7242dc51fbfec2c9abeb06

Authored by Sebastian Ziebell
1 parent ce9e35c2

API documentation updated for project snippets.

The API Documentation for project snippets got infos to return codes. Tests are added
to check status codes when handling project snippets.
doc/api/snippets.md
@@ -10,9 +10,15 @@ Parameters: @@ -10,9 +10,15 @@ Parameters:
10 10
11 + `id` (required) - The ID of a project 11 + `id` (required) - The ID of a project
12 12
  13 +Return values:
  14 +
  15 ++ `200 Ok` on success and a list of project snippets
  16 ++ `401 Unauthorized` if user is not authenticated
  17 +
  18 +
13 ## Single snippet 19 ## Single snippet
14 20
15 -Get a project snippet. 21 +Get a single project snippet.
16 22
17 ``` 23 ```
18 GET /projects/:id/snippets/:snippet_id 24 GET /projects/:id/snippets/:snippet_id
@@ -42,22 +48,16 @@ Parameters: @@ -42,22 +48,16 @@ Parameters:
42 } 48 }
43 ``` 49 ```
44 50
45 -## Snippet content 51 +Return values:
46 52
47 -Get a raw project snippet. 53 ++ `200 Ok` on success and the project snippet
  54 ++ `401 Unauthorized` if user is not authenticated
  55 ++ `404 Not Found` if snippet ID not found
48 56
49 -```  
50 -GET /projects/:id/snippets/:snippet_id/raw  
51 -```  
52 57
53 -Parameters: 58 +## Create new snippet
54 59
55 -+ `id` (required) - The ID of a project  
56 -+ `snippet_id` (required) - The ID of a project's snippet  
57 -  
58 -## New snippet  
59 -  
60 -Create a new project snippet. 60 +Creates a new project snippet.
61 61
62 ``` 62 ```
63 POST /projects/:id/snippets 63 POST /projects/:id/snippets
@@ -71,11 +71,17 @@ Parameters: @@ -71,11 +71,17 @@ Parameters:
71 + `lifetime` (optional) - The expiration date of a snippet 71 + `lifetime` (optional) - The expiration date of a snippet
72 + `code` (required) - The content of a snippet 72 + `code` (required) - The content of a snippet
73 73
74 -Will return created snippet with status `201 Created` on success, or `404 Not found` on fail. 74 +Return values:
  75 +
  76 ++ `201 Created` if snippet was successfully created and the snippet as JSON payload
  77 ++ `400 Bad Request` if one of the required attributes is not given
  78 ++ `401 Unauthorized` if user is not authenticated
  79 ++ `404 Not Found` if project ID not found
  80 +
75 81
76 ## Edit snippet 82 ## Edit snippet
77 83
78 -Update an existing project snippet. 84 +Updates an existing project snippet.
79 85
80 ``` 86 ```
81 PUT /projects/:id/snippets/:snippet_id 87 PUT /projects/:id/snippets/:snippet_id
@@ -90,11 +96,17 @@ Parameters: @@ -90,11 +96,17 @@ Parameters:
90 + `lifetime` (optional) - The expiration date of a snippet 96 + `lifetime` (optional) - The expiration date of a snippet
91 + `code` (optional) - The content of a snippet 97 + `code` (optional) - The content of a snippet
92 98
93 -Will return updated snippet with status `200 OK` on success, or `404 Not found` on fail. 99 +Return values:
  100 +
  101 ++ `200 Ok` on success and the updated project snippet
  102 ++ `401 Unauthorized` if user is not authenticated
  103 ++ `404 Not Found` if project ID not found
  104 +
94 105
95 ## Delete snippet 106 ## Delete snippet
96 107
97 -Delete existing project snippet. 108 +Deletes an existing project snippet. This is an idempotent function and deleting a non-existent
  109 +snippet still returns a `200 Ok` status code.
98 110
99 ``` 111 ```
100 DELETE /projects/:id/snippets/:snippet_id 112 DELETE /projects/:id/snippets/:snippet_id
@@ -105,5 +117,28 @@ Parameters: @@ -105,5 +117,28 @@ Parameters:
105 + `id` (required) - The ID of a project 117 + `id` (required) - The ID of a project
106 + `snippet_id` (required) - The ID of a project's snippet 118 + `snippet_id` (required) - The ID of a project's snippet
107 119
108 -Status code `200` will be returned on success. 120 +Return values:
  121 +
  122 ++ `200 Ok` on success and if the snippet was deleted its content
  123 ++ `401 Unauthorized` if user is not authenticated
  124 ++ `404 Not Found` if project ID not found
  125 +
  126 +
  127 +## Snippet content
  128 +
  129 +Get a raw project snippet.
  130 +
  131 +```
  132 +GET /projects/:id/snippets/:snippet_id/raw
  133 +```
  134 +
  135 +Parameters:
  136 +
  137 ++ `id` (required) - The ID of a project
  138 ++ `snippet_id` (required) - The ID of a project's snippet
  139 +
  140 +Return values:
109 141
  142 ++ `200 Ok` on success and the raw snippet
  143 ++ `401 Unauthorized` if user is not authenticated
  144 ++ `404 Not Found` if project ID or snippet ID is not found
110 \ No newline at end of file 145 \ No newline at end of file
spec/requests/api/projects_spec.rb
@@ -480,6 +480,11 @@ describe Gitlab::API do @@ -480,6 +480,11 @@ describe Gitlab::API do
480 json_response.should be_an Array 480 json_response.should be_an Array
481 json_response.first['title'].should == snippet.title 481 json_response.first['title'].should == snippet.title
482 end 482 end
  483 +
  484 + it "should return 401 error if user not authenticated" do
  485 + get api("/projects/#{project.id}/snippets")
  486 + response.status.should == 401
  487 + end
483 end 488 end
484 489
485 describe "GET /projects/:id/snippets/:snippet_id" do 490 describe "GET /projects/:id/snippets/:snippet_id" do
@@ -520,6 +525,12 @@ describe Gitlab::API do @@ -520,6 +525,12 @@ describe Gitlab::API do
520 title: 'api test', file_name: 'sample.rb' 525 title: 'api test', file_name: 'sample.rb'
521 response.status.should == 400 526 response.status.should == 400
522 end 527 end
  528 +
  529 + it "should return a 401 error if user not authenticated" do
  530 + post api("/projects/#{project.id}/snippets"),
  531 + title: 'api test', file_name: 'sample.rb', code: 'i=0'
  532 + response.status.should == 401
  533 + end
523 end 534 end
524 535
525 describe "PUT /projects/:id/snippets/:shippet_id" do 536 describe "PUT /projects/:id/snippets/:shippet_id" do