Sha256: d47fb62cf8039e46241e1641e5ed460960602cc3e74b2d2f03f32a298a4b101e

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

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_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
      #   - The const `VERSION` determineds the api version that client will query against.
      #   - This means that each subclass of `V2` should define their own `VERSION` constant.
      # @param api_key [String] the key version to stablish the api connection.
      # @param host [String] api server domain.
      # @param logger [Logger] an object with `Logger` interface to generate logs.
      # @return [V2] an object with the api version suit.
      def initialize(api_key, version: VERSION, host: "live.ecoportal.com", logger: default_logger)
        @logger = logger
        @client = Common::Client.new(
          api_key: api_key,
          host:    host,
          version: self.class::VERSION,
          logger:  @logger
        )
      end

      # Obtain specific object for register api requests.
      # @return [Register] an instance object ready to make register api requests.
      def registers
        registers_class.new(client)
      end

      def pages
        pages_class.new(client)
      end
    end
  end
end

require 'ecoportal/api/v2/registers'
require 'ecoportal/api/v2/pages'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecoportal-api-0.7.5 lib/ecoportal/api/v2.rb
ecoportal-api-0.7.4 lib/ecoportal/api/v2.rb