Class: DssReuters::Session

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dss_reuters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dss_reuters.rb', line 28

def initialize
  @logger = ::Logger.new(STDOUT)
  @logger.level = Config::LOG_LEVEL
   = "/RestApi/v1/Authentication/RequestToken"
  options = {
    headers: {
      "Prefer" => "respond-async",
      "Content-Type" => "application/json; odata=minimalmetadata"
    },
    body: {
      "Credentials" =>{
        "Username" => Config::DSS_USERNAME,
        "Password" => Config::DSS_PASSWORD
      }
    }.to_json
  }
  if configured?
    resp = self.class.post , options
    @token = resp["value"]
    @context = resp["@odata.context"]
    @logger.debug resp
  else
    not_configured_error
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



18
19
20
# File 'lib/dss_reuters.rb', line 18

def context
  @context
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/dss_reuters.rb', line 18

def logger
  @logger
end

#tokenObject (readonly)

Returns the value of attribute token.



18
19
20
# File 'lib/dss_reuters.rb', line 18

def token
  @token
end

Instance Method Details

#configured?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dss_reuters.rb', line 20

def configured?
  !Config::DSS_USERNAME.nil? and !Config::DSS_PASSWORD.nil?
end

#not_configured_errorObject



24
25
26
# File 'lib/dss_reuters.rb', line 24

def not_configured_error
  @logger.error "dss_reuters gem not configured. you will not be able to fetch data from dss reuters API"
end