class DataScope::Session

Attributes

context[R]
logger[R]
token[R]

Public Class Methods

new() click to toggle source
# File lib/data_scope_api.rb, line 23
def initialize
  @logger = ::Logger.new(STDOUT)
  @logger.level = Config::LOG_LEVEL
  login_path = "/RestApi/v1/Authentication/RequestToken"
  options = {
    headers: {
      "Prefer" => "respond-async",
      "Content-Type" => "application/json; odata=minimalmetadata"
    },
    body: {
      "Credentials" =>{
        "Username" => Config::DATA_SCOPE_USERNAME,
        "Password" => Config::DATA_SCOPE_PASSWORD
      }
    }.to_json
  }
  if configured?
    resp = self.class.post login_path, options
    @token = resp["value"]
    @context = resp["@odata.context"]
    @logger.debug resp
  else
    not_configured_error
  end
end

Public Instance Methods

configured?() click to toggle source
# File lib/data_scope_api.rb, line 15
def configured?
  !Config::DATA_SCOPE_USERNAME.nil? and !Config::DATA_SCOPE_PASSWORD.nil?
end
not_configured_error() click to toggle source
# File lib/data_scope_api.rb, line 19
def not_configured_error
  @logger.error "dss_reuters gem not configured. you will not be able to fetch data from data scope API"
end