entities.rb
3 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Noosfero
  module API
    module Entities
  
      Entity.format_with :timestamp do |date|
        date.strftime('%Y/%m/%d %H:%M:%S') if date
      end
  
      class Image < Entity
        root 'images', 'image'
        expose  :url do |image, options|
          image.public_filename
        end
  
        expose  :icon_url do |image, options|
          image.public_filename(:icon)
        end
  
        expose  :minor_url do |image, options|
          image.public_filename(:minor)
        end
  
        expose  :portrait_url do |image, options|
          image.public_filename(:portrait)
        end
  
        expose  :thumb_url do |image, options|
          image.public_filename(:thumb)
        end
      end
  
      class Profile < Entity
        expose :identifier, :name, :id
        expose :created_at, :format_with => :timestamp
        expose :image, :using => Image
      end
  
      class Person < Profile
        root 'people', 'person'
      end
      class Enterprise < Profile
        root 'enterprises', 'enterprise'
      end
      class Community < Profile
        root 'communities', 'community'
        expose :description
      end
  
      class Category < Entity
        root 'categories', 'category'
        expose :name, :id, :slug
        expose :image, :using => Image
      end
  
      class ArticleBase < Entity
        root 'articles', 'article'
        expose :id
        expose :body
        expose :abstract
        expose :created_at, :format_with => :timestamp
        expose :title, :documentation => {:type => "String", :desc => "Title of the article"}
        expose :created_by, :as => :author, :using => Profile
        expose :profile, :using => Profile
        expose :categories, :using => Category
        expose :image, :using => Image
        #TODO Apply vote stuff in core and make this test
        expose :votes_for
        expose :votes_against
        expose :setting
        expose :position
        expose :hits
      end
      class Article < ArticleBase
        root 'articles', 'article'
        expose :parent, :using => ArticleBase
        expose :children, :using => ArticleBase
      end
      class Comment < Entity
        root 'comments', 'comment'
        expose :body, :title, :id
        expose :created_at, :format_with => :timestamp
        expose :author, :using => Profile
      end
  
  
      class User < Entity
        root 'users', 'user'
        expose :id
        expose :login
        expose :person, :using => Profile
        expose :permissions do |user, options|
          output = {}
          user.person.role_assignments.map do |role_assigment|
            if role_assigment.resource.respond_to?(:identifier)
              output[role_assigment.resource.identifier] = role_assigment.role.permissions 
            end
          end
          output
        end
      end
  
      class UserLogin < User
        expose :private_token
      end
      class Task < Entity
        root 'tasks', 'task'
        expose :id
        expose :type
      end
    end
  end
end