Class: Projects::Parser::ProjectParser

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

Overview

  • Parse the JSON response into respective objects.

Instance Method Summary collapse

Instance Method Details

#getActivities(response) ⇒ Object

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

Parameters

  • response
    • This JSON response contains the details of a activities.

Returns

  • List of Activity object.



178
179
180
181
182
183
184
185
186
# File 'lib/projects/parser/ProjectParser.rb', line 178

def getActivities(response)
  activities_all_json = JSON.parse response
  activities_all_array = activities_all_json["activities"]
  activity_class_array = Array.new
  for i in 0...activities_all_array.length
    activity_class_array.push(jsonToActivity(activities_all_array[i]))
  end
  return activity_class_array
end

#getProject(project) ⇒ Object

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

Parameters

  • response
    • This JSON response contains the details of a Project.

Returns

  • Project object.



44
45
46
47
48
# File 'lib/projects/parser/ProjectParser.rb', line 44

def getProject(project)
  project_json = JSON.parse project
  project_array = project_json["projects"]
  return jsonToProject(project_array[0])
end

#getProjects(response) ⇒ Object

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

Parameters

  • response
    • This JSON response contains the details of Projects.

Returns

  • List of Project object.



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

def getProjects(response)
  projects_all_json = JSON.parse response
  projects_all_array = projects_all_json["projects"]
  projects_class_array = Array.new
  for i in 0...projects_all_array.length
    projects_class_array.push(jsonToProject(projects_all_array[i]))
  end
  return projects_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.



310
311
312
313
314
# File 'lib/projects/parser/ProjectParser.rb', line 310

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

#getStatus(response) ⇒ Object

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

Parameters

  • response
    • This JSON response contains the details of a status.

  • Status object.



258
259
260
261
262
# File 'lib/projects/parser/ProjectParser.rb', line 258

def getStatus(response)
  status_json = JSON.parse response
  status_array = status_json["statuses"]
  return jsonToStatus(status_array[0])
end

#getStatuses(response) ⇒ Object

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

Parameters

  • response
    • This JSON response contains the details of a statuses.

Returns

  • List of Status object.



240
241
242
243
244
245
246
247
248
# File 'lib/projects/parser/ProjectParser.rb', line 240

def getStatuses(response)
  statuses_all_json = JSON.parse response
  statuses_all_array = statuses_all_json["statuses"]
  statuses_class_array = Array.new
  for i in 0...statuses_all_array.length
    statuses_class_array.push(jsonToStatus(statuses_all_array[i]))
  end
  return statuses_class_array
end

#jsonToActivity(jsonObject) ⇒ Object

  • Parse the JSONObject into Activity object.

Parameters

  • jsonObject
    • JSONObject contains the details of a activity.

Returns

  • Activity object.



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

def jsonToActivity(jsonObject)
  activity = Activity.new
  
  if jsonObject.has_key?("id")
    activity.setId(jsonObject["id"])
  end
  if jsonObject.has_key?("name")
    activity.setName(jsonObject["name"])
  end
  if jsonObject.has_key?("state")
    activity.setState(jsonObject["state"])
  end
  if jsonObject.has_key?("activity_by")
    activity.setActivityBy(jsonObject["activity_by"])
  end
  if jsonObject.has_key?("time_long")
    activity.setTimeLong(jsonObject["time_long"])
  end
  if jsonObject.has_key?("display_time")
    activity.setDisplayTime(jsonObject["display_time"])
  end
  if jsonObject.has_key?("time")
    activity.setTime(jsonObject["time"])
  end
  if jsonObject.has_key?("activity_for")
    activity.setActivityFor(jsonObject["activity_for"])
  end
    
  return activity
  
end

#jsonToProject(jsonObject) ⇒ Object

  • Parse the JSONObject into Project object.

Parameters

  • jsonObject
    • JSONObject contains the details of a project.

Returns

  • Project 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
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
# File 'lib/projects/parser/ProjectParser.rb', line 60

def jsonToProject(jsonObject)
  project = Project.new  
  
  if jsonObject.has_key?("id")
    project.setId(jsonObject["id"])
  end
  if jsonObject.has_key?("name")
    project.setName(jsonObject["name"])
  end
  if jsonObject.has_key?("status")
    project.setStatus(jsonObject["status"])
  end
  if jsonObject.has_key?("created_date")
    project.setCreatedDate(jsonObject["created_date"])
  end
  if jsonObject.has_key?("created_date_format")
    project.setCreatedDateFormat(jsonObject["created_date_format"])
  end
  if jsonObject.has_key?("created_date_long")
    project.setCreatedDateLong(jsonObject["created_date_long"])
  end
  if jsonObject.has_key?("description")
    project.setDescription(jsonObject["description"])
  end
  if jsonObject.has_key?("owner_name")
    project.setOwnerName(jsonObject["owner_name"])
  end
  if jsonObject.has_key?("owner_id")
    project.setOwnerId(jsonObject["owner_id"])
  end
  
  if jsonObject.has_key?("task_count")
    taskCount = jsonObject["task_count"]
    if taskCount.has_key?("open")
      project.setOpenTaskCount(taskCount["open"])
    end
    if taskCount.has_key?("closed")
      project.setClosedTaskCount(taskCount["closed"])
    end
  end
  
  if jsonObject.has_key?("milestone_count")
    milestoneCount = jsonObject["milestone_count"]
    if milestoneCount.has_key?("open")
      project.setOpenMilestoneCount(milestoneCount["open"])
    end
    if milestoneCount.has_key?("closed")
      project.setClosedMilestoneCount(milestoneCount["closed"])
    end
  end

  if jsonObject.has_key?("bug_count")
    bugCount = jsonObject["bug_count"]
    if bugCount.has_key?("open")
      project.setOpenBugCount(bugCount["open"])
    end
    if bugCount.has_key?("closed")
      project.setClosedBugCount(bugCount["closed"])
    end
  end
  
  if jsonObject.has_key?("link")
    link = jsonObject["link"]
    
    if link.has_key?("self")
      project.setURL(link["self"]["url"])
    end
    if link.has_key?("activity")
      project.setActivityURL(link["activity"]["url"])
    end
    if link.has_key?("milestone")
      project.setMilestoneURL(link["milestone"]["url"])
    end
    if link.has_key?("tasklist")
      project.setTasklistURL(link["tasklist"]["url"])
    end
    if link.has_key?("task")
      project.setTaskURL(link["task"]["url"])
    end
    if link.has_key?("bug")
      project.setBugURL(link["bug"]["url"])
    end
    if link.has_key?("timesheet")
      project.setTimesheetURL(link["timesheet"]["url"])
    end
    if link.has_key?("status")
      project.setStatusURL(link["status"]["url"])
    end
    if link.has_key?("event")
      project.setEventURL(link["event"]["url"])
    end
    if link.has_key?("document")
      project.setDocumentURL(link["document"]["url"])
    end
    if link.has_key?("folder")
      project.setFolderURL(link["folder"]["url"])
    end
    if link.has_key?("forum")
      project.setForumURL(link["forum"]["url"])
    end
    if link.has_key?("user")
      project.setUserURL(link["user"]["url"])
    end
  end
  
  return project
end

#jsonToStatus(jsonObject) ⇒ Object

Returns

  • Status object.



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

def jsonToStatus(jsonObject)
  status = Status.new

  if jsonObject.has_key?("id")
    status.setId(jsonObject["id"])
  end
  if jsonObject.has_key?("content")
    status.setContent(jsonObject["content"])
  end
  if jsonObject.has_key?("posted_by")
    status.setPostedBy(jsonObject["posted_by"])
  end
  if jsonObject.has_key?("posted_person")
    status.setPostedPerson(jsonObject["posted_person"])
  end
  if jsonObject.has_key?("posted_time")
    status.setPostedTime(jsonObject["posted_time"])
  end
  if jsonObject.has_key?("posted_time_long")
    status.setPostedTimeLong(jsonObject["posted_time_long"])
  end
  if jsonObject.has_key?("posted_time_format")
    status.setPostedTimeFormat(jsonObject["posted_time_format"])
  end
  
  return status;
end