Class: Roart::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/roart/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Connection

Returns a new instance of Connection.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/roart/connection.rb', line 16

def initialize(conf)
  if conf.is_a?(String)
    raise RoartError, "Loading Config File not yet implemented"
  elsif conf.class.name == Hash.name #TODO: Figure out why conf.is_a?(Hash) doesn't work
    @conf = conf
  end
  if Roart::check_keys(conf, Roart::Connections::RequiredConfig)
    @agent = @conf[:login]
    add_methods!
    @connection = ConnectionAdapter.new(@conf)
  else
    raise RoartError, "Configuration Error"
  end
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



13
14
15
# File 'lib/roart/connection.rb', line 13

def agent
  @agent
end

#confObject (readonly)

Returns the value of attribute conf.



14
15
16
# File 'lib/roart/connection.rb', line 14

def conf
  @conf
end

Instance Method Details

#authenticate(conf) ⇒ Object



31
32
33
34
35
36
# File 'lib/roart/connection.rb', line 31

def authenticate(conf)
  if Roart::check_keys(conf, Roart::Connections::RequiredToLogin)
    @connection.authenticate(conf)
    self
  end
end

#get(uri) ⇒ Object



42
43
44
# File 'lib/roart/connection.rb', line 42

def get(uri)
  @connection.get(uri)
end

#post(uri, payload) ⇒ Object



46
47
48
# File 'lib/roart/connection.rb', line 46

def post(uri, payload)
  @connection.post(uri, payload)
end

#rest_pathObject



38
39
40
# File 'lib/roart/connection.rb', line 38

def rest_path
  self.server + '/REST/1.0/'
end