module Ecoportal module API class V2 class Pages # This API Integration level has been added due to relative permissions # - a **user** with api access may have access to a specific `stage` but not to the full `page` # # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. class Stages extend Common::BaseClass include Common::Content::DocHelpers class_resolver :page_stage_class, "Ecoportal::API::V2::Pages::PageStage" 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. def initialize(client) @client = client end # Gets a stage via api. # @note if the request has `success?` the returned `object.result` gives an object with that `Stage`. # @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::Stage, Ecoportal::API::V2::Pages::PageStage] the target stage. def get(id:, stage_id:) id = get_id(id) response = client.get("/pages/#{CGI.escape(id)}/stages/#{CGI.escape(stage_id)}/") wrapped = Common::Content::WrappedResponse.new(response, page_stage_class) return wrapped.result if wrapped.success? raise "Could not get stage {#{stage_id}} of page #{id} - Error #{response.status}: #{response.body}" end # Requests to update an existing stage via api. # @param doc [Hash, Stage] data that at least contains an `id` (internal or external) of the target stage. # @param id [String, nil] the `id` of the target **page**. # @param stage_id [String] the `id` of the target **stage**. # @return [Response] an object with the api response. def update(doc, id: nil, stage_id:) body = get_body(doc) id ||= get_id(doc) path = "/pages/#{CGI.escape(id)}/stages/#{CGI.escape(stage_id)}/" client.patch(path, data: body) end end end end end end require 'ecoportal/api/v2/pages/page_stage'