Class: Projects::Parser::TimesheetParser
- Inherits:
-
Object
- Object
- Projects::Parser::TimesheetParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/TimesheetParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getBuglog(response) ⇒ Object
-
Parse the JSON response and make it into the Buglog object.
-
-
#getGenerallog(response) ⇒ Object
-
Parse the JSON response and make it into the Generallog object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#getTasklog(response) ⇒ Object
-
Parse the JSON response and make it into Tasklog object.
-
-
#getTimeLogs(response) ⇒ Object
-
Parse the JSON response and make it into TimelogList object.
-
-
#jsonToBuglog(jsonObject) ⇒ Object
-
Parse the JSONObject into Buglog object.
-
-
#jsonToGenerallog(jsonObject) ⇒ Object
-
Parse the JSONObject into Generallog object.
-
-
#jsonToTasklog(jsonObject) ⇒ Object
-
Parse the JSONObject into Tasklog object.
-
-
#jsonToTimelogList(jsonObject) ⇒ Object
-
Parse the JSONObject into timlogList object.
-
Instance Method Details
#getBuglog(response) ⇒ Object
-
Parse the JSON response and make it into the Buglog object.
Parameters
- response
-
This JSON response contains the details of bug log.
-
Returns
-
Buglog object.
59 60 61 62 63 |
# File 'lib/projects/parser/TimesheetParser.rb', line 59 def getBuglog(response) timeLogs_json = JSON.parse response buglogs_array = timeLogs_json["timelogs"]["buglogs"] return jsonToBuglog(buglogs_array[0]) end |
#getGenerallog(response) ⇒ Object
-
Parse the JSON response and make it into the Generallog object.
Parameters
- response
-
This JSON response contains the details of a general log.
-
Returns
-
Generallog object.
75 76 77 78 79 |
# File 'lib/projects/parser/TimesheetParser.rb', line 75 def getGenerallog(response) timeLogs_json = JSON.parse response generallogs_array = timeLogs_json["timelogs"]["generallogs"] return jsonToGenerallog(generallogs_array[0]) 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.
382 383 384 385 386 |
# File 'lib/projects/parser/TimesheetParser.rb', line 382 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#getTasklog(response) ⇒ Object
-
Parse the JSON response and make it into Tasklog object.
Parameters
- response
-
This JSON response contains the details of a task log.
-
Returns
-
Tasklog object.
43 44 45 46 47 |
# File 'lib/projects/parser/TimesheetParser.rb', line 43 def getTasklog(response) timeLogs_json = JSON.parse response tasklogs_array = timeLogs_json["timelogs"]["tasklogs"] return jsonToTasklog(tasklogs_array[0]) end |
#getTimeLogs(response) ⇒ Object
-
Parse the JSON response and make it into TimelogList object.
Parameters
- response
-
This JSON response contains the details of time logs.
-
Returns
-
TimelogList object.
27 28 29 30 31 |
# File 'lib/projects/parser/TimesheetParser.rb', line 27 def getTimeLogs(response) timeLogs_json = JSON.parse response timeLogs_array = timeLogs_json["timelogs"] return jsonToTimelogList(timeLogs_array) end |
#jsonToBuglog(jsonObject) ⇒ Object
-
Parse the JSONObject into Buglog object.
Parameters
- jsonObject
-
JSONObject contains the details of a bug log.
-
Returns
-
Buglog object.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/projects/parser/TimesheetParser.rb', line 176 def jsonToBuglog(jsonObject) buglog = Buglog.new if jsonObject.has_key?("id") buglog.setId(jsonObject["id"]) end if jsonObject.has_key?("notes") buglog.setNotes(jsonObject["notes"]) end if jsonObject.has_key?("log_date") buglog.setLogDate(jsonObject["log_date"]) end if jsonObject.has_key?("log_date_long") buglog.setLogDateLong(jsonObject["log_date_long"]) end if jsonObject.has_key?("hours") buglog.setHours(jsonObject["hours"]) end if jsonObject.has_key?("minutes") buglog.setMinutes(jsonObject["minutes"]) end if jsonObject.has_key?("hours_display") buglog.setHoursDisplay(jsonObject["hours_display"]) end if jsonObject.has_key?("total_minutes") buglog.setTotalMinutes(jsonObject["total_minutes"]) end if jsonObject.has_key?("owner_id") buglog.setOwnerId(jsonObject["owner_id"]) end if jsonObject.has_key?("owner_name") buglog.setOwnerName(jsonObject["owner_name"]) end if jsonObject.has_key?("bill_status") buglog.setBillStatus(jsonObject["bill_status"]) end if jsonObject.has_key?("bug") bug = jsonObject["bug"] if bug.has_key?("id") buglog.setBugId(bug["id"]) end if bug.has_key?("title") buglog.setTitle(bug["title"]) end end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") buglog.setURL(link["self"]["url"]) end end return buglog end |
#jsonToGenerallog(jsonObject) ⇒ Object
-
Parse the JSONObject into Generallog object.
Parameters
- jsonObject
-
JSONObject contains the details of a general log.
-
Returns
-
Generallog object.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/projects/parser/TimesheetParser.rb', line 317 def jsonToGenerallog(jsonObject) generallog = Generallog.new if jsonObject.has_key?("id") generallog.setId(jsonObject["id"]) end if jsonObject.has_key?("name") generallog.setName(jsonObject["name"]) end if jsonObject.has_key?("notes") generallog.setNotes(jsonObject["notes"]) end if jsonObject.has_key?("log_date") generallog.setLogDate(jsonObject["log_date"]) end if jsonObject.has_key?("log_date_format") generallog.setLogDateFormat(jsonObject["log_date_format"]) end if jsonObject.has_key?("log_date_long") generallog.setLogDateLong(jsonObject["log_date_long"]) end if jsonObject.has_key?("hours") generallog.setHours(jsonObject["hours"]) end if jsonObject.has_key?("minutes") generallog.setMinutes(jsonObject["minutes"]) end if jsonObject.has_key?("hours_display") generallog.setHoursDisplay(jsonObject["hours_display"]) end if jsonObject.has_key?("total_minutes") generallog.setTotalMinutes(jsonObject["total_minutes"]) end if jsonObject.has_key?("owner_id") generallog.setOwnerId(jsonObject["owner_id"]) end if jsonObject.has_key?("owner_name") generallog.setOwnerName(jsonObject["owner_name"]) end if jsonObject.has_key?("bill_status") generallog.setBillStatus(jsonObject["bill_status"]) end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") generallog.setURL(link["self"]["url"]) end end return generallog end |
#jsonToTasklog(jsonObject) ⇒ Object
-
Parse the JSONObject into Tasklog object.
Parameters
- jsonObject
-
JSONObject contains the details of a task log.
-
Returns
-
Tasklog object.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/projects/parser/TimesheetParser.rb', line 245 def jsonToTasklog(jsonObject) tasklog = Tasklog.new if jsonObject.has_key?("id") tasklog.setId(jsonObject["id"]) end if jsonObject.has_key?("notes") tasklog.setNotes(jsonObject["notes"]) end if jsonObject.has_key?("log_date") tasklog.setLogDate(jsonObject["log_date"]) end if jsonObject.has_key?("log_date_format") tasklog.setLogDateFormat(jsonObject["log_date_format"]) end if jsonObject.has_key?("log_date_long") tasklog.setLogDateLong(jsonObject["log_date_long"]) end if jsonObject.has_key?("hours") tasklog.setHours(jsonObject["hours"]) end if jsonObject.has_key?("minutes") tasklog.setMinutes(jsonObject["minutes"]) end if jsonObject.has_key?("hours_display") tasklog.setHoursDisplay(jsonObject["hours_display"]) end if jsonObject.has_key?("total_minutes") tasklog.setTotalMinutes(jsonObject["total_minutes"]) end if jsonObject.has_key?("owner_id") tasklog.setOwnerId(jsonObject["owner_id"]) end if jsonObject.has_key?("owner_name") tasklog.setOwnerName(jsonObject["owner_name"]) end if jsonObject.has_key?("bill_status") tasklog.setBillStatus(jsonObject["bill_status"]) end if jsonObject.has_key?("task") task = jsonObject["task"] if task.has_key?("id") tasklog.setTaskId(task["id"]) end if task.has_key?("name") tasklog.setTaskName(task["name"]) end end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") tasklog.setURL(link["self"]["url"]) end end return tasklog end |
#jsonToTimelogList(jsonObject) ⇒ Object
-
Parse the JSONObject into timlogList object.
Parameters
- jsonObject
-
JSONObject contains the details of a time logs.
-
Returns
-
TimelogList object.
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 |
# File 'lib/projects/parser/TimesheetParser.rb', line 91 def jsonToTimelogList(jsonObject) timelogList = TimelogList.new if jsonObject.has_key?("grandtotal") timelogList.setGrandtotal(jsonObject["grandtotal"]) end if jsonObject.has_key?("role") timelogList.setRole(jsonObject["role"]) end if jsonObject.has_key?("date") date = jsonObject["date"] timelogObj = Timelog.new for i in 0...date.length dateObj = date[i] if dateObj.has_key?("date_long") timelogObj.setDateLong(dateObj["date_long"]) end if dateObj.has_key?("display_format") timelogObj.setDisplayFormat(dateObj["display_format"]) end if dateObj.has_key?("total_hours") timelogObj.setTotalHours(dateObj["total_hours"]) end if dateObj.has_key?("buglogs") buglogs = dateObj["buglogs"] buglogList = Array.new for j in 0...buglogs.length buglog = buglogs[j] buglogList.push(jsonToBuglog(buglog)) end timelogObj.setBuglogs(buglogList) end if dateObj.has_key?("tasklogs") tasklogs = dateObj["tasklogs"] tasklogList = Array.new for k in 0...tasklogs.length tasklog = tasklogs[k] tasklogList.push(jsonToTasklog(tasklog)) end timelogObj.setTasklogs(tasklogList) end if dateObj.has_key?("generallogs") generallogs = dateObj["generallogs"] generallogList = Array.new for l in 0...generallogs.length generallog = generallogs[l] generallogList.push(jsonToGenerallog(generallog)) end timelogObj.setGenerallogs(generallogList) end timelogList.push(timelogObj) end end return timelogList end |