Class: D2L::Valence::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/d2l/valence/host.rb

Overview

Host

Class for the creation of URIs for communication with the D2L Valence API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme:, host:, port: nil) ⇒ Host

Returns a new instance of Host.

Parameters:

  • scheme (Symbol)

    URI scheme to be used (either :http or :https)

  • host (String)

    host name for D2L server (e.g. d2l.myinstitution.com)

  • port (Integer) (defaults to: nil)

    specific port for transmission (optional)



11
12
13
14
15
# File 'lib/d2l/valence/host.rb', line 11

def initialize(scheme:, host:, port: nil)
  self.scheme = scheme
  self.host = host
  self.port = port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/d2l/valence/host.rb', line 6

def host
  @host
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/d2l/valence/host.rb', line 6

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



6
7
8
# File 'lib/d2l/valence/host.rb', line 6

def scheme
  @scheme
end

Instance Method Details

#to_uri(path: nil, query: nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/d2l/valence/host.rb', line 29

def to_uri(path: nil, query: nil)
  {
    http: URI::HTTP.build(host: host, port: port, path: path, query: query),
    https: URI::HTTPS.build(host: host, port: port, path: path, query: query)
  }[scheme]
end