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
# 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[:debug] || ENV['UCLAPI_DEBUG']) ? true : false 
  @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



35
36
37
38
39
# File 'lib/uclapi/client.rb', line 35

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

#roombookingsObject



27
28
29
# File 'lib/uclapi/client.rb', line 27

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

#searchObject



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

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