Class: Wikidotrb::Module::ForumPost
- Inherits:
-
Object
- Object
- Wikidotrb::Module::ForumPost
- Defined in:
- lib/wikidotrb/module/forum_post.rb
Instance Attribute Summary collapse
-
#created_at
Returns the value of attribute created_at.
-
#created_by
Returns the value of attribute created_by.
-
#edited_at
Returns the value of attribute edited_at.
-
#edited_by
Returns the value of attribute edited_by.
-
#forum
Returns the value of attribute forum.
-
#id
Returns the value of attribute id.
-
#parent
Parent post getter method.
-
#parent_id
Returns the value of attribute parent_id.
-
#site
Returns the value of attribute site.
-
#source
Source getter method.
-
#source_ele
Returns the value of attribute source_ele.
-
#source_text
Returns the value of attribute source_text.
-
#thread
Returns the value of attribute thread.
-
#title
Title getter method.
Instance Method Summary collapse
-
#destroy
Delete the post.
-
#edit(title: nil, source: nil)
Edit the post.
-
#get_url
Get the post URL.
-
#initialize(site:, id:, forum:, thread: nil, parent_id: nil, created_by: nil, created_at: nil, edited_by: nil, edited_at: nil, source_text: nil, source_ele: nil) ⇒ ForumPost
constructor
Initialization method.
-
#reply(title: "", source: "")
Reply to the post.
Constructor Details
#initialize(site:, id:, forum:, thread: nil, parent_id: nil, created_by: nil, created_at: nil, edited_by: nil, edited_at: nil, source_text: nil, source_ele: nil) ⇒ ForumPost
Initialization method
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/wikidotrb/module/forum_post.rb', line 82 def initialize(site:, id:, forum:, thread: nil, parent_id: nil, created_by: nil, created_at: nil, edited_by: nil, edited_at: nil, source_text: nil, source_ele: nil) @site = site @id = id @forum = forum @thread = thread @parent_id = parent_id @created_by = created_by @created_at = created_at @edited_by = edited_by @edited_at = edited_at @source_text = source_text @source_ele = source_ele @parent = nil @title = nil @source = nil end |
Instance Attribute Details
#created_at
Returns the value of attribute created_at.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def created_at @created_at end |
#created_by
Returns the value of attribute created_by.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def created_by @created_by end |
#edited_at
Returns the value of attribute edited_at.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def edited_at @edited_at end |
#edited_by
Returns the value of attribute edited_by.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def edited_by @edited_by end |
#forum
Returns the value of attribute forum.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def forum @forum end |
#id
Returns the value of attribute id.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def id @id end |
#parent
Parent post getter method
112 113 114 |
# File 'lib/wikidotrb/module/forum_post.rb', line 112 def parent @parent end |
#parent_id
Returns the value of attribute parent_id.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def parent_id @parent_id end |
#site
Returns the value of attribute site.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def site @site end |
#source
Source getter method
124 125 126 |
# File 'lib/wikidotrb/module/forum_post.rb', line 124 def source @source end |
#source_ele
Returns the value of attribute source_ele.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def source_ele @source_ele end |
#source_text
Returns the value of attribute source_text.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def source_text @source_text end |
#thread
Returns the value of attribute thread.
78 79 80 |
# File 'lib/wikidotrb/module/forum_post.rb', line 78 def thread @thread end |
#title
Title getter method
118 119 120 |
# File 'lib/wikidotrb/module/forum_post.rb', line 118 def title @title end |
Instance Method Details
#destroy
Delete the post
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/wikidotrb/module/forum_post.rb', line 208 def destroy @site.client.login_check @site.amc_request( bodies: [ { "postId" => @id, "action" => "ForumAction", "event" => "deletePost", "moduleName" => "Empty" } ] ) end |
#edit(title: nil, source: nil)
Edit the post
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/wikidotrb/module/forum_post.rb', line 162 def edit(title: nil, source: nil) client = @site.client client.login_check return self if title.nil? && source.nil? raise Wikidotrb::Common::UnexpectedException, "Post source can not be left empty." if source == "" begin response = @site.amc_request( bodies: [ { "postId" => @id, "threadId" => @thread.id, "moduleName" => "forum/sub/ForumEditPostFormModule" } ] ).first html = Nokogiri::HTML(response.body.to_s) current_id = html.at_css("form#edit-post-form>input")[1].get("value").to_i @site.amc_request( bodies: [ { "postId" => @id, "currentRevisionId" => current_id, "title" => title || @title, "source" => source || @source, "action" => "ForumAction", "event" => "saveEditPost", "moduleName" => "Empty" } ] ) rescue Wikidotrb::Common::WikidotStatusCodeException return self end @edited_by = client.user.get(client.username) @edited_at = DateTime.now @title = title || @title @source = source || @source self end |
#get_url
Get the post URL
107 108 109 |
# File 'lib/wikidotrb/module/forum_post.rb', line 107 def get_url "#{@thread.get_url}#post-#{@id}" end |
#reply(title: "", source: "")
Reply to the post
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/wikidotrb/module/forum_post.rb', line 130 def reply(title: "", source: "") client = @site.client client.login_check raise Wikidotrb::Common::UnexpectedException, "Post body can not be left empty." if source == "" response = @site.amc_request( bodies: [ { "parentId" => @id, "title" => title, "source" => source, "action" => "ForumAction", "event" => "savePost" } ] ).first body = JSON.parse(response.body.to_s) ForumPost.new( site: @site, id: body["postId"].to_i, forum: @forum, title: title, source: source, thread: @thread, parent_id: @id, created_by: client.user.get(client.username), created_at: DateTime.parse(body["CURRENT_TIMESTAMP"]) ) end |