Class: Learndot::Events
- Inherits:
-
Object
- Object
- Learndot::Events
- Defined in:
- lib/learndot/events.rb
Instance Method Summary collapse
- #enrolled(class_id) ⇒ Object
- #enrollment_count(class_id) ⇒ Object
-
#initialize(api) ⇒ Events
constructor
A new instance of Events.
- #retrieve(conditions, options = {orderBy: 'startTime', asc: true}) ⇒ Object
- #update_notes(class_id, notes) ⇒ Object
Constructor Details
#initialize(api) ⇒ Events
Returns a new instance of Events.
2 3 4 |
# File 'lib/learndot/events.rb', line 2 def initialize(api) @api = api end |
Instance Method Details
#enrolled(class_id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/learndot/events.rb', line 51 def enrolled(class_id) sessions = @api.search(:course_session, { 'eventId' => [class_id] }) return [] if sessions.empty? conditions = { 'id' => sessions.collect { | k, cs | cs['enrolmentId'] }, 'status' => ['TENTATIVE', 'APPROVED', 'CONFIRMED'] } enrollments = @api.search(:enrolment, conditions) return [] if enrollments.empty? conditions = { 'id' => enrollments.collect { | k, cs | cs['contactId'] }, } contacts = @api.search(:contact, conditions) contacts.collect do | k, cs | { :id => cs['id'], :name => cs['_displayName_'], :email => cs['email'] } end end |
#enrollment_count(class_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/learndot/events.rb', line 36 def enrollment_count(class_id) sessions = @api.search(:course_session, { 'eventId' => [class_id] }) if ! sessions.empty? enrolment_ids = sessions.collect { | k, cs | cs['enrolmentId'] } enrollment_conditions = { 'id' => enrolment_ids, 'status' => ['TENTATIVE', 'APPROVED', 'CONFIRMED'] } count = @api.count('enrolment', enrollment_conditions) end return count || 0 end |
#retrieve(conditions, options = {orderBy: 'startTime', asc: true}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/learndot/events.rb', line 6 def retrieve(conditions, = {orderBy: 'startTime', asc: true}) classes = @api.search(:course_event, conditions, ) return [] if classes.empty? course_ids = classes.collect { | k, c | c['courseId'] }.uniq location_ids = classes.collect { | k, c | c['locationId'] }.uniq organizer_ids = classes.collect { | k, c | c['organizerId'] }.uniq courses = @api.search(:course, { 'id' => course_ids }) locations = @api.search(:location, { 'id' => location_ids }) organizers = @api.search(:contact, { 'id' => organizer_ids }) classes.collect do | class_id, klass | location = locations[klass['locationId']] klass[:learndot_id] = klass['id'] # for consistency klass[:city] = location['online'] ? location['name'] : location['address']['city'] klass[:course_name] = courses[klass['courseId']]['name'] klass[:organizer] = organizers[klass['organizerId']] ? organizers[klass['organizerId']]['_displayName_'] : '' klass[:enrollment_count] = enrollment_count(class_id) klass[:start_time] = Date.parse(klass['startTime']) klass[:end_time] = Date.parse(klass['finalEndTime']) klass[:notes] = klass['notes'] klass[:session_url] = klass['sessionUrl'] klass end end |
#update_notes(class_id, notes) ⇒ Object
72 73 74 75 |
# File 'lib/learndot/events.rb', line 72 def update_notes(class_id, notes) conditions = { 'notes' => notes } @api.update(:course_event, conditions, class_id) end |