entities.rb
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module API
module Entities
class Article < Grape::Entity
root 'articles', 'article'
expose :id, :name, :body, :created_at
expose :author do |article, options|
{
:id => article.author_id,
:name => article.author_name,
:icon_url => article.author_custom_image(:icon),
:minor_url => article.author_custom_image(:minor),
:portrait_url => article.author_custom_image(:portrait),
:thumb_url => article.author_custom_image(:thumb),
}
end
end
class Comment < Grape::Entity
root 'comments', 'comment'
expose :body, :title, :created_at, :id
expose :author do |comment, options|
{
:id => comment.author_id,
:name => comment.author_name,
:icon_url => comment.author_custom_image(:icon),
:minor_url => comment.author_custom_image(:minor),
:portrait_url => comment.author_custom_image(:portrait),
:thumb_url => comment.author_custom_image(:thumb),
}
end
end
class User < Grape::Entity
root 'users', 'user'
expose :login
end
class UserLogin < User
expose :private_token
end
end
end