@@ -6,65 +6,15 @@ module Categories
6
6
# :permissions is a hash with the group name and permission_type which is
7
7
# an integer 1 = Full 2 = Create Post 3 = Read Only
8
8
def create_category ( args = { } )
9
- args =
10
- API
11
- . params ( args )
12
- . required ( :name , :color , :text_color )
13
- . optional (
14
- :slug ,
15
- :permissions ,
16
- :auto_close_hours ,
17
- :auto_close_based_on_last_post ,
18
- :position ,
19
- :email_in ,
20
- :email_in_allow_strangers ,
21
- :logo_url ,
22
- :background_url ,
23
- :allow_badges ,
24
- :topic_template ,
25
- :custom_fields ,
26
- :description ,
27
- :reviewable_by_group_name ,
28
- :show_subcategory_list ,
29
- :subcategory_list_style ,
30
- :allowed_tags ,
31
- :allowed_tag_groups ,
32
- :required_tag_group_name ,
33
- )
34
- . default ( parent_category_id : nil )
35
- response = post ( "/categories" , args )
9
+ params = common_category_params ( args )
10
+ response = post ( "/categories" , params . to_h )
36
11
response [ "category" ]
37
12
end
38
13
39
14
def update_category ( args = { } )
40
15
category_id = args [ :id ]
41
- args =
42
- API
43
- . params ( args )
44
- . required ( :id , :name , :color , :text_color )
45
- . optional (
46
- :slug ,
47
- :permissions ,
48
- :auto_close_hours ,
49
- :auto_close_based_on_last_post ,
50
- :position ,
51
- :email_in ,
52
- :email_in_allow_strangers ,
53
- :logo_url ,
54
- :background_url ,
55
- :allow_badges ,
56
- :topic_template ,
57
- :custom_fields ,
58
- :description ,
59
- :reviewable_by_group_name ,
60
- :show_subcategory_list ,
61
- :subcategory_list_style ,
62
- :allowed_tags ,
63
- :allowed_tag_groups ,
64
- :required_tag_group_name ,
65
- )
66
- . default ( parent_category_id : nil )
67
- response = put ( "/categories/#{ category_id } " , args )
16
+ params = common_category_params ( args , include_id : true )
17
+ response = put ( "/categories/#{ category_id } " , params . to_h )
68
18
response [ "body" ] [ "category" ] if response [ "body" ]
69
19
end
70
20
@@ -144,6 +94,42 @@ def category_set_user_notification_level(category_id, params)
144
94
params = API . params ( params ) . required ( :notification_level )
145
95
post ( "/category/#{ category_id } /notifications" , params )
146
96
end
97
+
98
+ private
99
+
100
+ def common_category_params ( args , include_id : false )
101
+ params = API . params ( args )
102
+ params = params . required ( :id ) if include_id
103
+ params
104
+ . required ( :name )
105
+ . optional (
106
+ :color ,
107
+ :text_color ,
108
+ :slug ,
109
+ :permissions ,
110
+ :auto_close_hours ,
111
+ :auto_close_based_on_last_post ,
112
+ :position ,
113
+ :email_in ,
114
+ :email_in_allow_strangers ,
115
+ :logo_url ,
116
+ :background_url ,
117
+ :allow_badges ,
118
+ :topic_template ,
119
+ :custom_fields ,
120
+ :description ,
121
+ :reviewable_by_group_name ,
122
+ :show_subcategory_list ,
123
+ :subcategory_list_style ,
124
+ :allowed_tags ,
125
+ :allowed_tag_groups ,
126
+ :required_tag_group_name ,
127
+ :topic_featured_links_allowed ,
128
+ :search_priority ,
129
+ :form_template_ids ,
130
+ )
131
+ . default ( parent_category_id : nil )
132
+ end
147
133
end
148
134
end
149
135
end
0 commit comments