lib/ecoportal/api/v2/pages.rb in ecoportal-api-v2-2.0.6 vs lib/ecoportal/api/v2/pages.rb in ecoportal-api-v2-2.0.7

- old
+ new

@@ -1,23 +1,24 @@ module Ecoportal module API class V2 - # @attr_reader client [Common::Client] a `Common::Client` object that - # holds the configuration of the api connection. + # @attr_reader client [Ecoportal::API::Common::Client] a `Ecoportal::API::Common::Client` + # object that holds the configuration of the api connection. class Pages STAGE_REX = /stages\/(?<sid>.*)/.freeze - extend Common::BaseClass - include Common::Content::DocHelpers + extend Ecoportal::API::Common::BaseClass + include Ecoportal::API::Common::Content::DocHelpers class_resolver :stages_class, "Ecoportal::API::V2::Pages::Stages" class_resolver :page_class, "Ecoportal::API::V2::Page" class_resolver :page_stage_class, "Ecoportal::API::V2::Pages::PageStage" 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. + # @param client [Ecoportal::API::Common::Client] a `Ecoportal::API::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 @@ -37,11 +38,11 @@ def get(id, stage_id: nil) return stages.get(id: id, stage_id: stage_id) if stage_id id = get_id(id) response = client.get("/pages/#{CGI.escape(id)}") - wrapped = Common::Content::WrappedResponse.new(response, page_class) + wrapped = Ecoportal::API::Common::Content::WrappedResponse.new(response, page_class) return wrapped.result if wrapped.success? url = nil url = response.body["data"] if response.status == 302 @@ -75,11 +76,14 @@ # @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) response = client.get("/pages/new", params: {template_id: id}) - wrapped = Common::Content::WrappedResponse.new(response, page_stage_class) + wrapped = Ecoportal::API::Common::Content::WrappedResponse.new( + response, + page_stage_class + ) return wrapped.result if wrapped.success? raise "Could not get new page from template #{id} - Error #{response.status}: #{response.body}" end @@ -97,12 +101,18 @@ "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) + wrapped = Ecoportal::API::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}" + + msg = "Could not create page from template #{id} " + msg << "- Error #{response.status}: #{response.body}" + raise msg end private def url_to_stage_id(url)