Class: Projects::Parser::PortalParser
- Inherits:
-
Object
- Object
- Projects::Parser::PortalParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/PortalParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getPortal(jsonObject) ⇒ Object
-
Parse the JSONObject into Portal object.
-
-
#getPortals(response) ⇒ Object
-
Parse the JSON response and make it into List of Portal object.
-
Instance Method Details
#getPortal(jsonObject) ⇒ Object
-
Parse the JSONObject into Portal object.
Parameters
- jsonObject
-
JSONObject contains the details of a Portal.
-
Returns
-
Portal object.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 |
# File 'lib/projects/parser/PortalParser.rb', line 42 def getPortal(jsonObject) portal = Projects::Model::Portal.new if jsonObject.has_key?("id") portal.setId(jsonObject["id"]) end if jsonObject.has_key?("name") portal.setName(jsonObject["name"]) end if jsonObject.has_key?("default") portal.setDefault(jsonObject["default"]) end if jsonObject.has_key?("gmt_time_zone") portal.setGmtTimeZone(jsonObject["gmt_time_zone"]) end if jsonObject.has_key?("role") portal.setRole(jsonObject["role"]) end if jsonObject.has_key?("settings") settings = jsonObject["settings"] if settings.has_key?("company_name") portal.setCompanyName(settings["company_name"]) end if settings.has_key?("website_url") portal.setWebsiteURL(settings["website_url"]) end if settings.has_key?("time_zone") portal.setTimeZone(settings["time_zone"]) end if settings.has_key?("date_format") portal.setDateFormat(settings["date_format"]) end end if jsonObject.has_key?("locale") locale = jsonObject["locale"] if locale.has_key?("code") portal.setCode(locale["code"]) end if locale.has_key?("language") portal.setLanguage(locale["language"]) end if locale.has_key?("country") portal.setCountry(locale["country"]) end end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("projects") project = link["project"] if project.has_key?("url") portal.setProjectURL(project["url"]) end end end return portal end |
#getPortals(response) ⇒ Object
-
Parse the JSON response and make it into List of Portal object.
Parameters
- response
-
This JSON response contains the details of portals.
-
Returns
-
List of Portal object.
22 23 24 25 26 27 28 29 30 |
# File 'lib/projects/parser/PortalParser.rb', line 22 def getPortals(response) portals_all_json = JSON.parse response portals_all_array = portals_all_json["portals"] portal_class_array = Array.new for i in 0...portals_all_array.length portal_class_array.push(getPortal(portals_all_array[i])) end return portal_class_array end |