Class: Projects::Parser::MilestonesParser
- Inherits:
-
Object
- Object
- Projects::Parser::MilestonesParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/MilestonesParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getMilestone(response) ⇒ Object
-
Parse the JSON response and make it into Milestone object.
-
-
#getMilestones(response) ⇒ Object
-
Parse the JSON response and make it into List of Milestone object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#jsonToMilestone(jsonObject) ⇒ Object
-
Parse the JSONObject into Milestone object.
-
Instance Method Details
#getMilestone(response) ⇒ Object
-
Parse the JSON response and make it into Milestone object.
Parameters
- response
-
This JSON response contains the details of a milestone.
-
Returns
-
Milestone object.
42 43 44 45 46 |
# File 'lib/projects/parser/MilestonesParser.rb', line 42 def getMilestone(response) milestones_json = JSON.parse response milestones_array = milestones_json["milestones"] return jsonToMilestone(milestones_array[0]) end |
#getMilestones(response) ⇒ Object
-
Parse the JSON response and make it into List of Milestone object.
Parameters
- response
-
This JSON response contains the details of milestones.
-
Returns
-
List of Milestone object.
22 23 24 25 26 27 28 29 30 |
# File 'lib/projects/parser/MilestonesParser.rb', line 22 def getMilestones(response) milestones_all_json = JSON.parse response milestones_all_array = milestones_all_json["milestones"] milestones_class_array = Array.new for i in 0...milestones_all_array.length milestones_class_array.push(jsonToMilestone(milestones_all_array[i])) end return milestones_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.
122 123 124 125 126 |
# File 'lib/projects/parser/MilestonesParser.rb', line 122 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#jsonToMilestone(jsonObject) ⇒ Object
-
Parse the JSONObject into Milestone object.
Parameters
- jsonObject
-
JSONObject contains the details of a milestone.
-
Returns
-
Milestone object.
58 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 109 110 |
# File 'lib/projects/parser/MilestonesParser.rb', line 58 def jsonToMilestone(jsonObject) milestone = Milestone.new if jsonObject.has_key?("id") milestone.setId(jsonObject["id"]) end if jsonObject.has_key?("name") milestone.setName(jsonObject["name"]) end if jsonObject.has_key?("start_date") milestone.setStartDate(jsonObject["start_date"]) end if jsonObject.has_key?("start_date_format") milestone.setStartDateFormat(jsonObject["start_date_format"]) end if jsonObject.has_key?("start_date_long") milestone.setStartDateLong(jsonObject["start_date_long"]) end if jsonObject.has_key?("end_date") milestone.setEndDate(jsonObject["end_date"]) end if jsonObject.has_key?("end_date_format") milestone.setEndDateFormat(jsonObject["end_date_format"]) end if jsonObject.has_key?("end_date_long") milestone.setEndDateLong(jsonObject["end_date_long"]) end if jsonObject.has_key?("status") milestone.setStatus(jsonObject["status"]) end if jsonObject.has_key?("flag") milestone.setFlag(jsonObject["flag"]) end if jsonObject.has_key?("owner_id") milestone.setOwnerId(jsonObject["owner_id"]) end if jsonObject.has_key?("owner_name") milestone.setOwnerName(jsonObject["owner_name"]) end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") milestone.setURL(link["self"]["url"]) end if link.has_key?("status") milestone.setStatusURL(link["status"]["url"]) end end return milestone end |