module Ecoportal module API class V2 # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. class Pages extend Common::BaseClass include Enumerable include Common::DocHelpers attr_reader :client class_resolver :page_class, "Ecoportal::API::V2::Page" # @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. # @return [People] an instance object ready to make people api requests. def initialize(client) @client = client end def get(id, stage_id: nil) if stage_id response = get_with_stage_id(id, stage_id) return page_class.new(response.body["data"]) end response = client.get("/pages/#{id}") # we get a 302 back when there's stages for the page # let's follow it if response.status == 302 stage_id = response.body["data"].match(/stages\/(.*)/)[1] response = get_with_stage_id(id, stage_id) end page_class.new(response.body["data"]) end private def get_with_stage_id(id, stage_id) client.get("/pages/#{id}/stages/#{stage_id}") end end end end end require 'ecoportal/api/v2/page'