class D2L::Valence::Host
Host
¶ ↑
Class for the creation of URIs for communication with the D2L
Valence
API
Attributes
host[RW]
port[RW]
scheme[RW]
Public Class Methods
new(scheme:, host:, port: nil)
click to toggle source
@param [Symbol] scheme URI scheme to be used (either :http or :https) @param [String] host host name for D2L
server (e.g. d2l.myinstitution.com) @param [Integer] port specific port for transmission (optional)
# File lib/d2l/valence/host.rb, line 11 def initialize(scheme:, host:, port: nil) self.scheme = scheme self.host = host self.port = port end
Public Instance Methods
host=(value)
click to toggle source
# File lib/d2l/valence/host.rb, line 17 def host=(value) raise 'Host cannot be nil' if value.nil? @host = value end
scheme=(value)
click to toggle source
# File lib/d2l/valence/host.rb, line 22 def scheme=(value) return if value.nil? value = value.downcase.to_sym if value.is_a? String raise "#{value} is an unsupported scheme. Please use either HTTP or HTTPS" unless supported_scheme? value @scheme = value end
to_uri(path: nil, query: nil)
click to toggle source
# 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
Private Instance Methods
supported_scheme?(value)
click to toggle source
# File lib/d2l/valence/host.rb, line 38 def supported_scheme?(value) [:http, :https].include? value end