Class: Projects::Parser::TasklistParser

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/projects/parser/TasklistParser.rb

Overview

  • Parse the JSON response into respective objects.

Instance Method Summary collapse

Instance Method Details

#getResult(response) ⇒ Object

  • Parse the JSON response and get the success message.

Parameters

  • response
    • This JSON response contains the success message.

Returns

  • String object.



120
121
122
123
124
# File 'lib/projects/parser/TasklistParser.rb', line 120

def getResult(response)
  jsonObject = JSON.parse response
  result = jsonObject["response"]
  return result
end

#getTasklist(response) ⇒ Object

  • Parse the JSON response and make it into Tasklist object.

Parameters

  • response
    • This JSON response contains the details of a task list.

Returns

  • Tasklist object.



43
44
45
46
47
# File 'lib/projects/parser/TasklistParser.rb', line 43

def getTasklist(response)
  tasklists_json = JSON.parse response
  tasklists_array = tasklists_json["tasklists"]
  return jsonToTasklist(tasklists_array[0])
end

#getTasklists(response) ⇒ Object

  • Parse the JSON response and make it into List of Tasklist object.

Parameters

  • response
    • This JSON response contains the details of task lists.

Returns

  • List of TaskList object.



23
24
25
26
27
28
29
30
31
# File 'lib/projects/parser/TasklistParser.rb', line 23

def getTasklists(response)
  tasklists_all_json = JSON.parse response
  tasklists_all_array = tasklists_all_json["tasklists"]
  tasklists_class_array = Array.new
  for i in 0...tasklists_all_array.length
    tasklists_class_array.push(jsonToTasklist(tasklists_all_array[i]))
  end
  return tasklists_class_array
end

#jsonToTasklist(jsonObject) ⇒ Object

  • Parse the JSONObject into Tasklist object.

Parameters

  • jsonObject
    • JSONObject contains the details of a task list.

Returns

  • Tasklist object.



59
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
# File 'lib/projects/parser/TasklistParser.rb', line 59

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
  if jsonObject.has_key?("completed")
    tasklist.setCompleted(jsonObject["completed"])
  end
  if jsonObject.has_key?("created_time")
    tasklist.setCreatedTime(jsonObject["created_time"])
  end
  if jsonObject.has_key?("created_time_format")
    tasklist.setCreatedTimeFormat(jsonObject["created_time_format"])
  end
  if jsonObject.has_key?("created_time_long")
    tasklist.setCreatedTimeLong(jsonObject["created_time_long"])
  end
  if jsonObject.has_key?("rolled")
    tasklist.setRolled(jsonObject["rolled"])
  end
  if jsonObject.has_key?("sequence")
    tasklist.setSequence(jsonObject["sequence"])
  end
  if jsonObject.has_key?("flag")
    tasklist.setFlag(jsonObject["flag"])
  end
  
  if jsonObject.has_key?("link")
    link = jsonObject["link"]
    
    if link.has_key?("self")
      tasklist.setURL(link["self"]["url"])
    end
    if link.has_key?("task")
      tasklist.setTaskURL(link["task"]["url"])
    end
  end
  

  if jsonObject.has_key?("milestone")
    milestoneParser = MilestonesParser.new
    milestone = jsonObject["milestone"]
    tasklist.setMilestone(milestoneParser.jsonToMilestone(milestone))
  end  
  return tasklist
end