Class: Projects::Parser::TaskParser
- Inherits:
-
Object
- Object
- Projects::Parser::TaskParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/TaskParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
- #getComment(response) ⇒ Object
-
#getComments(response) ⇒ Object
-
Parse the JSON response and make it into list of Comment object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#getTask(response) ⇒ Object
-
Parse the JSON response and make it into Task object.
-
-
#getTasks(response) ⇒ Object
-
Parse the JSON response and make it into List of Task object.
-
-
#jsonToComment(jsonObject) ⇒ Object
-
Parse the JSONObject into Comment object.
-
-
#jsonToOwner(jsonObject) ⇒ Object
-
Parse the JSONObject into Owner object.
-
-
#jsonToTask(jsonObject) ⇒ Object
-
Parse the JSONObject into Task object.
-
-
#jsonToTasklist(jsonObject) ⇒ Object
-
Parse the JSONObject into Tasklist object.
-
Instance Method Details
#getComment(response) ⇒ Object
262 263 264 265 266 267 268 269 270 |
# File 'lib/projects/parser/TaskParser.rb', line 262 def getComment(response) jsonObject = JSON.parse response comments = jsonObject["comments"] return jsonToComment(comments[0]) end |
#getComments(response) ⇒ Object
-
Parse the JSON response and make it into list of Comment object.
Parameters
- response
-
JSON response contains the details of the task comments.
-
Returns
-
Returns List of Comment object.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/projects/parser/TaskParser.rb', line 229 def getComments(response) jsonObject = JSON.parse response commentsList = Array.new if jsonObject.has_key?("comments") comments = jsonObject["comments"] for i in 0...comments.length commentsList.push(jsonToComment(comments[i])) end end return commentsList 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.
347 348 349 350 351 |
# File 'lib/projects/parser/TaskParser.rb', line 347 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#getTask(response) ⇒ Object
-
Parse the JSON response and make it into Task object.
Parameters
- response
-
This JSON response contains the details of a task.
-
Returns
-
Task object.
45 46 47 48 49 |
# File 'lib/projects/parser/TaskParser.rb', line 45 def getTask(response) tasks_json = JSON.parse response tasks_array = tasks_json["tasks"] return jsonToTask(tasks_array[0]) end |
#getTasks(response) ⇒ Object
-
Parse the JSON response and make it into List of Task object.
Parameters
- response
-
This JSON response contains the details of tasks.
-
Returns
-
List of Task object.
25 26 27 28 29 30 31 32 33 |
# File 'lib/projects/parser/TaskParser.rb', line 25 def getTasks(response) tasks_all_json = JSON.parse response tasks_all_array = tasks_all_json["tasks"] tasks_class_array = Array.new for i in 0...tasks_all_array.length tasks_class_array.push(jsonToTask(tasks_all_array[i])) end return tasks_class_array end |
#jsonToComment(jsonObject) ⇒ Object
-
Parse the JSONObject into Comment object.
Parameters
- jsonObject
-
JSONObject contains the details of a comment.
-
Returns
-
Comment object.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/projects/parser/TaskParser.rb', line 284 def jsonToComment(jsonObject) comment = Comment.new if jsonObject.has_key?("id") comment.setId(jsonObject["id"]) end if jsonObject.has_key?("content") comment.setContent(jsonObject["content"]) end if jsonObject.has_key?("created_time") comment.setCreatedTime(jsonObject["created_time"]) end if jsonObject.has_key?("created_time_format") comment.setCreatedTimeFormat(jsonObject["created_time_format"]) end if jsonObject.has_key?("created_time_long") comment.setCreatedTimeLong(jsonObject["created_time_long"]) end if jsonObject.has_key?("added_by") comment.setAddedBy(jsonObject["added_by"]) end if jsonObject.has_key?("added_person") comment.setAddedPerson(jsonObject["added_person"]) end if jsonObject.has_key?("updated_by") comment.setUpdatedBy(jsonObject["updated_by"]) end return comment end |
#jsonToOwner(jsonObject) ⇒ Object
-
Parse the JSONObject into Owner object.
Parameters
- jsonObject
-
JSONObject contains the details of a owner.
-
Returns
-
Owner object.
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/projects/parser/TaskParser.rb', line 207 def jsonToOwner(jsonObject) owner = Owner.new if jsonObject.has_key?("id") owner.setId(jsonObject["id"]) end if jsonObject.has_key?("name") owner.setName(jsonObject["name"]) end return owner end |
#jsonToTask(jsonObject) ⇒ Object
-
Parse the JSONObject into Task object.
Parameters
- jsonObject
-
JSONObject contains the details of a task.
-
Returns
-
Task object.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/projects/parser/TaskParser.rb', line 61 def jsonToTask(jsonObject) task = Task.new if jsonObject.has_key?("id") task.setId(jsonObject["id"]) end if jsonObject.has_key?("name") task.setName(jsonObject["name"]) end if jsonObject.has_key?("completed") task.setCompleted(jsonObject["completed"]) end if jsonObject.has_key?("created_by") task.setCreatedBy(jsonObject["created_by"]) end if jsonObject.has_key?("created_person") task.setCreatedPerson(jsonObject["created_person"]) end if jsonObject.has_key?("priority") task.setPriority(jsonObject["priority"]) end if jsonObject.has_key?("percent_complete") task.setPercentComplete(jsonObject["percent_complete"]) end if jsonObject.has_key?("start_date") task.setStartDate(jsonObject["start_date"]) end if jsonObject.has_key?("start_date_format") task.setStartDateFormat(jsonObject["start_date_format"]) end if jsonObject.has_key?("start_date_long") task.setStartDateLong(jsonObject["start_date_long"]) end if jsonObject.has_key?("end_date") task.setEndDate(jsonObject["end_date"]) end if jsonObject.has_key?("end_date_format") task.setEndDateFormat(jsonObject["end_date_format"]) end if jsonObject.has_key?("end_date_long") task.setEndDateLong(jsonObject["end_date_long"]) end if jsonObject.has_key?("duration") task.setDuration(jsonObject["duration"]) end if jsonObject.has_key?("details") details = jsonObject["details"] if details.has_key?("owners") owners = details["owners"] ownerList = Array.new for i in 0...owners.length owner = owners[i] ownerList.push(jsonToOwner(owner)) end task.setOwners(ownerList) end if details.has_key?("comments") comments = details["comments"] commentList = Array.new for j in 0...comments.length comment = comments[j] commentList.push(jsonToComment(comment)) end task.setComments(commentList) end if details.has_key?("documents") documents = details["documents"] documentIds = Array.new for l in 0...documents.length documentIds[l] = String(documents[l]["id"]) end task.setAssociateDocumentIds(documentIds) end if details.has_key?("forums") forums = details["forums"] forumIds = Array.new for m in 0...forums.length forumIds[m] = String(forums[m]["id"]) end task.setAssociateForumIds(forumIds) end end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") task.setURL(link["self"]["url"]) end if link.has_key?("subtask") task.setSubtaskUrl(link["subtask"]["url"]) end if link.has_key?("timesheet") task.setTimesheetURL(link["timesheet"]["url"]) end end if jsonObject.has_key?("subtasks") #subtasks = jsonObject["subtasks"] #tasks = Array.new #for k in 0...subtasks.length # taskObj = subtasks[k] # tasks.push(jsonToTask(taskObj)) #end task.setSubtasks(jsonObject["subtasks"]) end if jsonObject.has_key?("tasklist") tasklist = jsonObject["tasklist"] task.setTasklist(jsonToTasklist(tasklist)) end return task end |
#jsonToTasklist(jsonObject) ⇒ Object
-
Parse the JSONObject into Tasklist object.
Parameters
- jsonObject
-
JSONObject contains the details of a task list.
-
Returns
-
Tasklist object.
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/projects/parser/TaskParser.rb', line 324 def jsonToTasklist(jsonObject) tasklist = Tasklist.new if jsonObject.has_key?("id") tasklist.setId(jsonObject["id"]) end if jsonObject.has_key?("name") tasklist.setName(jsonObject["name"]) end return tasklist end |