Class: Projects::Parser::EventParser
- Inherits:
-
Object
- Object
- Projects::Parser::EventParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/EventParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getEvent(response) ⇒ Object
-
Parse the JSON response and make it into Event object.
-
-
#getEvents(response) ⇒ Object
-
Parse the JSON response and make it into List of Event object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#jsonToEvent(jsonObject) ⇒ Object
-
Parse the JSONObject into Event object.
-
-
#jsonToParticipant(jsonObject) ⇒ Object
-
Parse the JSONObject into Participant object.
-
Instance Method Details
#getEvent(response) ⇒ Object
-
Parse the JSON response and make it into Event object.
Parameters
- response
-
This JSON response contains the details of an event.
-
Returns
-
Event object.
44 45 46 47 48 |
# File 'lib/projects/parser/EventParser.rb', line 44 def getEvent(response) event_json = JSON.parse response event_array = event_json["events"] return jsonToEvent(event_array[0]) end |
#getEvents(response) ⇒ Object
-
Parse the JSON response and make it into List of Event object.
Parameters
- response
-
This JSON response contains the details of events.
-
Returns
-
List of Event object.
24 25 26 27 28 29 30 31 32 |
# File 'lib/projects/parser/EventParser.rb', line 24 def getEvents(response) events_all_json = JSON.parse response events_all_array = events_all_json["events"] events_class_array = Array.new for i in 0...events_all_array.length events_class_array.push(jsonToEvent(events_all_array[i])) end return events_class_array end |
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
Parameters
- response
-
This JSON response contains the success message.
-
Returns
-
String object.
148 149 150 151 152 |
# File 'lib/projects/parser/EventParser.rb', line 148 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#jsonToEvent(jsonObject) ⇒ Object
-
Parse the JSONObject into Event object.
Parameters
- jsonObject
-
JSONObject contains the details of an event.
-
Returns
-
Event object.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/projects/parser/EventParser.rb', line 60 def jsonToEvent(jsonObject) event = Event.new if jsonObject.has_key?("id") event.setId(jsonObject["id"]) end if jsonObject.has_key?("title") event.setTitle(jsonObject["title"]) end if jsonObject.has_key?("location") event.setLocation(jsonObject["location"]) end if jsonObject.has_key?("scheduled_on") event.setScheduledOn(jsonObject["scheduled_on"]) end if jsonObject.has_key?("scheduled_on_long") event.setScheduledOnLong(jsonObject["scheduled_on_long"]) end if jsonObject.has_key?("reminder") event.setReminder(jsonObject["reminder"]) end if jsonObject.has_key?("repeat") event.setRepeat(jsonObject["repeat"]) end if jsonObject.has_key?("occurrence(s)") event.setOccurrences(jsonObject["occurrence(s)"]) end if jsonObject.has_key?("occurred") event.setOccurred(jsonObject["occurred"]) end if jsonObject.has_key?("duration_hour") event.setDurationHours(jsonObject["duration_hour"]) end if jsonObject.has_key?("duration_minutes") event.setDurationMinutes(jsonObject["duration_minutes"]) end if jsonObject.has_key?("participants") participants = jsonObject["participants"] participantList = Array.new for j in 0...participants.length participant = participants[j] participantList.push(jsonToParticipant(participant)) end event.setParticipants(participantList) end return event end |
#jsonToParticipant(jsonObject) ⇒ Object
-
Parse the JSONObject into Participant object.
Parameters
- jsonObject
-
JSONObject contains the details of a participant.
-
Returns
-
Participant object.
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/projects/parser/EventParser.rb', line 124 def jsonToParticipant(jsonObject) participant = Participant.new if jsonObject.has_key?("participant_id") participant.setParticipantId(jsonObject["participant_id"]) end if jsonObject.has_key?("participant_person") participant.setParticipantPerson(jsonObject["participant_person"]) end return participant end |