require 'base64' module Ecoportal module API # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. # @attr_reader logger [Logger] the logger. class V2 extend Common::BaseClass include Common::Logging VERSION = "v2" class << self def v2key (ukey, gkey) Base64.urlsafe_encode64({ organization: gkey, user: ukey }.to_json) end end class_resolver :registers_class, "Ecoportal::API::V2::Registers" class_resolver :pages_class, "Ecoportal::API::V2::Pages" attr_reader :client, :logger # Creates an `V2` object to scope version specific api requests. # @note # - you should use either `api_key` or `user_key` and `org_key` # @param api_key [String] the key version to stablish the api connection. # @param user_key [String] the user key used for the api connection (requires `org_key`). # @param org_key [String] the org key used for the api connection (requires `user_key`). # @param host [String] api server domain. # @param logger [Logger] an object with `Logger` interface to generate logs. def initialize(api_key = nil, user_key: nil, org_key: nil, host: "live.ecoportal.com", logger: default_logger) v2key = (user_key && org_key && self.class.v2key(user_key, org_key)) || api_key #|| ENV['X_ECOPORTAL_API_KEY'] @logger = logger @client = Common::Content::Client.new( api_key: v2key, host: host, version: self.class::VERSION, logger: @logger ) end # Obtain specific object for schema api requests. # @return [Registers] an instance object ready to make registers api requests. def registers registers_class.new(client) end # Obtain specific object for pages api requests. # @return [Pages] an instance object ready to make pages api requests. def pages pages_class.new(client) end end end end require 'ecoportal/api/v2/registers' require 'ecoportal/api/v2/pages'