Class: UCLAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/uclapi/client.rb

Defined Under Namespace

Classes: BadRequestError, NotFoundError, Roombookings, Search, ServerError, UnauthorizedError

Constant Summary collapse

ENDPOINT =
'uclapi.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/uclapi/client.rb', line 15

def initialize(options = {})
  @token = options.fetch(:token) do
    ENV['UCLAPI_TOKEN'] || raise(KeyError, "Missing required argument: token")
  end

  @debug = options.fetch(:debug) do
    ENV['UCLAPI_DEBUG']
  end

  @http = Net::HTTP.new(ENDPOINT, Net::HTTP.https_default_port)
  http.use_ssl = true

  http.set_debug_output $stderr if debug
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



13
14
15
# File 'lib/uclapi/client.rb', line 13

def debug
  @debug
end

#httpObject

Returns the value of attribute http.



13
14
15
# File 'lib/uclapi/client.rb', line 13

def http
  @http
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/uclapi/client.rb', line 13

def token
  @token
end

Instance Method Details

#get(path, params = {}) ⇒ Object



38
39
40
41
42
# File 'lib/uclapi/client.rb', line 38

def get(path, params = {})
  uri = uri_for(path, params)
  message = Net::HTTP::Get.new(uri.request_uri)
  transmit(message)
end

#roombookingsObject



30
31
32
# File 'lib/uclapi/client.rb', line 30

def roombookings
  UCLAPI::Client::Roombookings.new(self)
end

#searchObject



34
35
36
# File 'lib/uclapi/client.rb', line 34

def search
  UCLAPI::Client::Search.new(self)
end