class Ecoportal::API::V2
@attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. @attr_reader logger [Logger] the logger.
Constants
- VERSION
Attributes
Public Class Methods
Creates an `V2` object to scope version specific api requests. @note
- You should use either `api_key` or `user_key` and `org_key` - 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 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.
# File lib/ecoportal/api/v2.rb, line 38 def initialize(api_key = nil, user_key: nil, org_key: nil, host: "live.ecoportal.com", logger: default_logger) v2key = get_key(api_key: api_key, user_key: user_key, org_key: org_key) @logger = logger @client = Common::Content::Client.new( api_key: v2key, host: host, version: self.class::VERSION, logger: @logger ) end
# File lib/ecoportal/api/v2.rb, line 14 def v2key (ukey, gkey) Base64.urlsafe_encode64({ organization: gkey, user: ukey }.to_json) end
Public Instance Methods
Obtain specific object for pages api requests. @return [Pages] an instance object ready to make pages api requests.
# File lib/ecoportal/api/v2.rb, line 63 def pages pages_class.new(client) end
Obtain specific object for people api requests. @return [People] an instance object ready to make people api requests.
# File lib/ecoportal/api/v2.rb, line 51 def people people_class.new(client) end
Obtain specific object for schema api requests. @return [Registers] an instance object ready to make registers api requests.
# File lib/ecoportal/api/v2.rb, line 57 def registers registers_class.new(client) end
Private Instance Methods
# File lib/ecoportal/api/v2.rb, line 69 def get_key(api_key: nil, user_key: nil, org_key: nil) return self.class.v2key(user_key, org_key) if user_key && org_key return api_key if api_key #|| ENV['X_ECOPORTAL_API_KEY'] raise "You need to provide either an api_key or user_key" unless user_key raise "You need to provide an org_key as well (not just a user_key)" unless org_key end