lib/ecoportal/api/v2/pages.rb in ecoportal-api-oozes-0.7.4 vs lib/ecoportal/api/v2/pages.rb in ecoportal-api-oozes-0.7.5
- old
+ new
@@ -26,26 +26,37 @@
# Gets a page via api.
# @note
# - if the request has `success?` the returned `object.result` gives an object with that `Page`.
# - if it failed to obtain the full page, it returns a `PageStage` with the active stage data.
- # @param doc [String, Hash, Page] data containing an `id` of the target page.
+ # @param id [String, Hash, Stage] the `id` of the target **page**.
+ # @param stage_id [String] the `id` of the target **stage**.
# @return [Ecoportal::API::V2::Page, Ecoportal::API::V2::Pages::PageStage] the target page.
- def get(doc)
- pid = get_id(doc)
- response = client.get("/pages/#{CGI.escape(pid)}")
+ def get(id, stage_id: nil)
+ return stages.get(pid: id, sid: stage_id) if stage_id
+ id = get_id(id)
+ response = client.get("/pages/#{CGI.escape(id)}")
wrapped = Common::Content::WrappedResponse.new(response, page_class)
return wrapped.result if wrapped.success?
if (response.status == 302) && (url = response.body["data"])
- if sid = url_to_stage_id(url)
- return stages.get(pid: pid, sid: sid)
+ if stage_id = url_to_stage_id(url)
+ return stages.get(pid: id, sid: stage_id)
end
end
raise "Could not get page #{pid} - Error #{response.status}: #{response.body}"
end
+ # Requests to update an existing page via api.
+ # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
+ # @return [Response] an object with the api response.
+ def update(doc)
+ body = get_body(doc) # , level: "page"
+ id = get_id(doc)
+ client.patch("/pages/#{CGI.escape(id)}", data: body)
+ end
+
# Gets a `new` non-existing page via api with all the ids initialized.
# @param from [String, Hash, Page] template or `id` of the template
# @return [Ecoportal::API::V2::Page] the new page object.
def get_new(from)
id = get_id(from)
@@ -62,18 +73,9 @@
# @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})
- end
-
- # Requests to update an existing page via api.
- # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
- # @return [Response] an object with the api response.
- def update(doc)
- body = get_body(doc) # , level: "page"
- id = get_id(doc)
- client.patch("/pages/#{CGI.escape(id)}", data: body)
end
private
def url_to_stage_id(url)