Birdie0/qna_maker

View on GitHub
lib/qna_maker/endpoints/publish_kb.rb

Summary

Maintainability
A
1 hr
Test Coverage
module QnAMaker
  class Client
    #
    # Publish all unpublished in the knowledgebase to the prod endpoint
    #
    # @return [nil] on success
    #
    def publish_kb
      response = @http.put(
        "#{BASE_URL}/#{@knowledgebase_id}"
      )

      case response.code
      when 204
        nil
      when 400
        raise BadArgumentError, response.parse['error']['message'].join(' ')
      when 401
        raise UnauthorizedError, response.parse['error']['message']
      when 403
        raise ForbiddenError, response.parse['error']['message']
      when 404
        raise NotFoundError, response.parse['error']['message']
      when 409
        raise ConflictError, response.parse['error']['message']
      else
        raise UnknownError, "Oh no! (#{response.code})"
      end
    end
  end
end