Commit e117414e44ea5747805b8ff0cba000cd10938cb9

Authored by Dmitriy Zaporozhets
2 parents 46bf3a09 270a4337

Merge pull request #2124 from NARKOZ/api

remove unnecessary API::VERSION constant
CHANGELOG
1 1 v 4.0.0
  2 + - [API] expose created date for hooks and SSH keys
2 3 - [API] list, create issue notes
3 4 - [API] list, create snippet notes
4 5 - [API] list, create wall notes
... ...
doc/api/README.md
... ... @@ -25,7 +25,7 @@ The API uses JSON to serialize data. You don't need to specify `.json` at the en
25 25 When listing resources you can pass the following parameters:
26 26  
27 27 + `page` (default: `1`) - page number
28   -+ `per_page` (default: `20`, max: `100`) - how many items to list per page
  28 ++ `per_page` (default: `20`, max: `100`) - number of items to list per page
29 29  
30 30 ## Contents
31 31  
... ... @@ -36,3 +36,4 @@ When listing resources you can pass the following parameters:
36 36 + [Repositories](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md)
37 37 + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md)
38 38 + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md)
  39 ++ [Notes](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/notes.md)
... ...
doc/api/notes.md
... ... @@ -57,6 +57,19 @@ Parameters:
57 57  
58 58 ## Single note
59 59  
  60 +### Single wall note
  61 +
  62 +Get a wall note.
  63 +
  64 +```
  65 +GET /projects/:id/notes/:note_id
  66 +```
  67 +
  68 +Parameters:
  69 +
  70 ++ `id` (required) - The ID or code name of a project
  71 ++ `note_id` (required) - The ID of a wall note
  72 +
60 73 ### Single issue note
61 74  
62 75 Get an issue note.
... ...
lib/api.rb
... ... @@ -2,8 +2,7 @@ Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file}
2 2  
3 3 module Gitlab
4 4 class API < Grape::API
5   - VERSION = 'v2'
6   - version VERSION, using: :path
  5 + version 'v2', using: :path
7 6  
8 7 rescue_from ActiveRecord::RecordNotFound do
9 8 rack_response({'message' => '404 Not found'}.to_json, 404)
... ...
lib/api/entities.rb
... ... @@ -14,7 +14,7 @@ module Gitlab
14 14 end
15 15  
16 16 class Hook < Grape::Entity
17   - expose :id, :url
  17 + expose :id, :url, :created_at
18 18 end
19 19  
20 20 class Project < Grape::Entity
... ... @@ -61,7 +61,7 @@ module Gitlab
61 61 end
62 62  
63 63 class SSHKey < Grape::Entity
64   - expose :id, :title, :key
  64 + expose :id, :title, :key, :created_at
65 65 end
66 66  
67 67 class MergeRequest < Grape::Entity
... ...
lib/api/notes.rb
... ... @@ -17,6 +17,18 @@ module Gitlab
17 17 present paginate(@notes), with: Entities::Note
18 18 end
19 19  
  20 + # Get a single project wall note
  21 + #
  22 + # Parameters:
  23 + # id (required) - The ID or code name of a project
  24 + # note_id (required) - The ID of a note
  25 + # Example Request:
  26 + # GET /projects/:id/notes/:note_id
  27 + get ":id/notes/:note_id" do
  28 + @note = user_project.common_notes.find(params[:note_id])
  29 + present @note, with: Entities::Note
  30 + end
  31 +
20 32 # Create a new project wall note
21 33 #
22 34 # Parameters:
... ...
spec/requests/api/notes_spec.rb
... ... @@ -30,6 +30,14 @@ describe Gitlab::API do
30 30 end
31 31 end
32 32  
  33 + describe "GET /projects/:id/notes/:note_id" do
  34 + it "should return a wall note by id" do
  35 + get api("/projects/#{project.id}/notes/#{wall_note.id}", user)
  36 + response.status.should == 200
  37 + json_response['body'].should == wall_note.note
  38 + end
  39 + end
  40 +
33 41 describe "POST /projects/:id/notes" do
34 42 it "should create a new wall note" do
35 43 post api("/projects/#{project.id}/notes", user), body: 'hi!'
... ...
spec/support/api_helpers.rb
... ... @@ -18,7 +18,7 @@ module ApiHelpers
18 18 #
19 19 # Returns the relative path to the requested API resource
20 20 def api(path, user = nil)
21   - "/api/#{Gitlab::API::VERSION}#{path}" +
  21 + "/api/#{Gitlab::API.version}#{path}" +
22 22  
23 23 # Normalize query string
24 24 (path.index('?') ? '' : '?') +
... ...