class Ernest::UpdatePostId
Attributes
post[R]
response[R]
Public Class Methods
after_saving_post(response, post)
click to toggle source
# File lib/ernest/update_post_id.rb, line 3 def self.after_saving_post(response, post) new(response, post) end
new(response, post)
click to toggle source
# File lib/ernest/update_post_id.rb, line 7 def initialize(response, post) @response = response @post = post end
Public Instance Methods
call()
click to toggle source
# File lib/ernest/update_post_id.rb, line 12 def call if everything_ok? update_post_id else puts response end end
Private Instance Methods
did_not_receive_id_error_message()
click to toggle source
# File lib/ernest/update_post_id.rb, line 40 def did_not_receive_id_error_message <<-ERR_MSG.gsub(/^ {8}/, '').gsub("\n", '') The server did not respond with an id, therefore I will not be able to update this post in the next run, unless you add it manually. ERR_MSG end
everything_ok?()
click to toggle source
# File lib/ernest/update_post_id.rb, line 36 def everything_ok? response.code == 200 end
new_post_id()
click to toggle source
# File lib/ernest/update_post_id.rb, line 32 def new_post_id response.parsed_response["id"] end
update_post_id()
click to toggle source
# File lib/ernest/update_post_id.rb, line 24 def update_post_id if new_post_id post.update_id(new_post_id) else puts did_not_receive_id_error_message end end