Sha256: 2e6ce05e4c738c790b32a7819442bac09f4ecf085e3e4b694387f0c0f3833fd1
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
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'
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ecoportal-api-0.7.5 | lib/ecoportal/api/v2/pages.rb |
ecoportal-api-0.7.4 | lib/ecoportal/api/v2/pages.rb |