Class: Aladtec::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.


15
16
17
18
19
20
21
# File 'lib/aladtec/client.rb', line 15

def initialize(options={})
  merged_options = Aladtec.options.merge(options)

  Configuration::VALID_CONFIG_KEYS.each do |key|
    public_send("#{key}=", merged_options[key])
  end
end

Instance Method Details

#auth(username, password) ⇒ Object

Public: Authenticate member


50
51
52
53
# File 'lib/aladtec/client.rb', line 50

def auth(username, password)
  response = request(:authenticateMember, memun: username, mempw: password)
  Authentication.parse(response.body)
end

#denormalize_ranges(ranges, klass = RangeDenormalizer) ⇒ Object


82
83
84
# File 'lib/aladtec/client.rb', line 82

def denormalize_ranges(ranges, klass = RangeDenormalizer)
  klass.new(schedules: schedules, members: members).denormalize(ranges)
end

#events(options = {}) ⇒ Object

Public: Get a list of events for a date or range of dates

options - The Hash options used to refine the selection (default: {}):

:begin_date - The begin date to return events for (required).
:end_date   - The end date to return events for (optional).

28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aladtec/client.rb', line 28

def events(options = {})
  bd = options.fetch(:begin_date) { raise "You must supply a :begin_date option!"}
  ed = options.fetch(:end_date, nil)
  bd = bd.is_a?(Date) ? bd.iso8601 : Date.parse(bd).iso8601
  if ed
    ed = ed.is_a?(Date) ? ed.iso8601 : Date.parse(ed).iso8601
  end
  response = request(:getEvents, bd: bd, ed: ed)
  Event.parse(response.body)
rescue LibXML::XML::Error
  Event.parse(Kconv.toutf8(response.body))
end

#membersObject

Public: Get a list of members


43
44
45
46
# File 'lib/aladtec/client.rb', line 43

def members
  response = request(:getMembers, ia: 'all')
  Member.parse(response.body)
end

#scheduled_nowObject

Public: Get list of members scheduled now


63
64
65
66
# File 'lib/aladtec/client.rb', line 63

def scheduled_now
  response = request(:getScheduledTimeNow, isp: 1)
  Schedule.parse(response.body)
end

#scheduled_range(options = {}) ⇒ Object

Public: Get list of members scheduled in a time range

options - The Hash options used to refine the selection (default: {}):

:begin_time - The begin time to return events for (required).
:end_time   - The end time to return events for (required).

73
74
75
76
77
78
79
80
# File 'lib/aladtec/client.rb', line 73

def scheduled_range(options = {})
  bt = options.fetch(:begin_time) { raise "You must supply a :begin_time!"}
  et = options.fetch(:end_time) { raise "You must supply an :end_time!"}
  bt = bt.is_a?(Time) ? bt.clone.utc.iso8601 : Time.parse(bt).utc.iso8601
  et = et.is_a?(Time) ? et.clone.utc.iso8601 : Time.parse(et).utc.iso8601
  response = request(:getScheduledTimeRanges, bt: bt, et: et, isp: 1)
  denormalize_ranges(Range.parse(response.body))
end

#schedulesObject

Public: Get a list of schedules


57
58
59
60
# File 'lib/aladtec/client.rb', line 57

def schedules
  response = request(:getSchedules, isp: 1)
  Schedule.parse(response.body)
end