lib/ecoportal/api/v2/pages.rb in ecoportal-api-v2-0.8.31 vs lib/ecoportal/api/v2/pages.rb in ecoportal-api-v2-0.8.32
- old
+ new
@@ -7,10 +7,11 @@
extend Common::BaseClass
include Common::Content::DocHelpers
class_resolver :stages_class, "Ecoportal::API::V2::Pages::Stages"
class_resolver :page_class, "Ecoportal::API::V2::Page"
+ class_resolver :create_page_response_class, "Ecoportal::API::V2::Pages::PageCreateResponse"
attr_reader :client
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
# @return [Schemas] an instance object ready to make schema api requests.
@@ -73,13 +74,24 @@
# Requests a creation of a page via api.
# @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
# @param from [String, Hash, Page] template or `id` of the template
# @return [Response] an object with the api response.
def create(doc, from:)
- body = get_body(doc)
id = get_id(from)
- client.post("/pages", data: body, params: {template_id: id})
+ body = get_body(doc).tap do |hash|
+ unless hash["page"]
+ hash["page"] = {
+ "id" => "111111111111111111111111",
+ "operation" => "changed",
+ "data" => {"patch_ver" => 0}
+ }
+ end
+ end
+ response = client.post("/pages", data: body, params: {template_id: id})
+ wrapped = Common::Content::WrappedResponse.new(response, create_page_response_class)
+ return wrapped.result if wrapped.success?
+ raise "Could not create page from template #{id} - Error #{response.status}: #{response.body}"
end
private
def url_to_stage_id(url)
@@ -91,5 +103,6 @@
end
end
require 'ecoportal/api/v2/page'
require 'ecoportal/api/v2/pages/stages'
+require 'ecoportal/api/v2/pages/page_create_response'