lib/ahub/answer.rb in ahub-0.1.13 vs lib/ahub/answer.rb in ahub-0.1.14

- old
+ new

@@ -1,10 +1,18 @@ module Ahub class Answer extend Ahub::APIHelpers include Ahub::ClassHelpers + def self.create(question_id:, body:, username:, password:) + payload = {body: body} + + url = "#{Ahub::DOMAIN}/services/v2/question/#{question_id}/answer.json" + + make_post_call(url, payload.to_json, headers(username: username, password: password)) + end + attr_reader :body, :body_as_html, :author def initialize(attrs) @id = attrs[:id] @body = attrs[:body] @@ -12,18 +20,8 @@ @author = Ahub::User.new(attrs[:author]) end def user @author - end - - def self.create(question_id:, body:, username:, password:) - data = {body: body} - - url = "#{Ahub::DOMAIN}/services/v2/question/#{question_id}/answer.json" - - auth_headers = headers(username: username, password: password) - - new JSON.parse(RestClient.post(url, data.to_json, auth_headers), symbolize_names: true) end end end