Class: Projects::Parser::DocumentParser
- Inherits:
-
Object
- Object
- Projects::Parser::DocumentParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/DocumentParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getDocument(response) ⇒ Object
-
Parse the JSON response and make it into Document object.
-
-
#getDocuments(response) ⇒ Object
-
Parse the JSON response and make it into List of Document object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#jsonToDocument(jsonObject) ⇒ Object
-
Parse the JSONObject into Document object.
-
-
#jsonToFolder(jsonObject) ⇒ Object
-
Parse the JSONObject into Folder object.
-
-
#jsonToVersion(jsonObject) ⇒ Object
-
Parse the JSONObject into Version object.
-
Instance Method Details
#getDocument(response) ⇒ Object
-
Parse the JSON response and make it into Document object.
Parameters
- response
-
This JSON response contains the details of a document.
-
Returns
-
Document object.
44 45 46 47 48 |
# File 'lib/projects/parser/DocumentParser.rb', line 44 def getDocument(response) document_json = JSON.parse response document_array = document_json["documents"] return jsonToDocument(document_array[0]) end |
#getDocuments(response) ⇒ Object
-
Parse the JSON response and make it into List of Document object.
Parameters
- response
-
This JSON response contains the details of a documents.
-
Returns
-
List of Document object.
24 25 26 27 28 29 30 31 32 |
# File 'lib/projects/parser/DocumentParser.rb', line 24 def getDocuments(response) documents_all_json = JSON.parse response documents_all_array = documents_all_json["documents"] documents_class_array = Array.new for i in 0...documents_all_array.length documents_class_array.push(jsonToDocument(documents_all_array[i])) end return documents_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.
190 191 192 193 194 |
# File 'lib/projects/parser/DocumentParser.rb', line 190 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#jsonToDocument(jsonObject) ⇒ Object
-
Parse the JSONObject into Document object.
Parameters
- jsonObject
-
JSONObject contains the details of the document.
-
Returns
-
Document 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 |
# File 'lib/projects/parser/DocumentParser.rb', line 60 def jsonToDocument(jsonObject) document = Document.new if jsonObject.has_key?("id") document.setId(jsonObject["id"]) end if jsonObject.has_key?("file_name") document.setFilename(jsonObject["file_name"]) end if jsonObject.has_key?("content_type") document.setContenttype(jsonObject["content_type"]) end if jsonObject.has_key?("versions") versions = jsonObject["versions"] versionList = Array.new for i in 0...versions.length version = versions[i] versionList.push(jsonToVersion(version)) end document.setVersions(versionList) end if jsonObject.has_key?("folder") folder = jsonObject["folder"] document.setFolder(jsonToFolder(folder)) end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") document.setURL(link["self"]["url"]) end end return document end |
#jsonToFolder(jsonObject) ⇒ Object
-
Parse the JSONObject into Folder object.
Parameters
- jsonObject
-
JSONObject contains the details of a folder.
-
Returns
-
Folder object.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/projects/parser/DocumentParser.rb', line 156 def jsonToFolder(jsonObject) folder = Folder.new if jsonObject.has_key?("id") folder.setId(jsonObject["id"]) end if jsonObject.has_key?("name") folder.setName(jsonObject["name"]) end if jsonObject.has_key?("is_discussion") folder.setIsDicussion(jsonObject["is_discussion"]) end if jsonObject.has_key?("link") link = jsonObject["link"] if link.has_key?("self") folder.setURL(link["self"]["url"]) end end return folder end |
#jsonToVersion(jsonObject) ⇒ Object
-
Parse the JSONObject into Version object.
Parameters
- jsonObject
-
JSONObject contains the details of a version.
-
Returns
-
Version object.
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 |
# File 'lib/projects/parser/DocumentParser.rb', line 112 def jsonToVersion(jsonObject) version = Version.new if jsonObject.has_key?("id") version.setId(jsonObject["id"]) end if jsonObject.has_key?("uploaded_by") version.setUploadedBy(jsonObject["uploaded_by"]) end if jsonObject.has_key?("description") version.setDescription(jsonObject["description"]) end if jsonObject.has_key?("version") version.setVersion(jsonObject["version"]) end if jsonObject.has_key?("uploaded_on") version.setUploadedOn(jsonObject["uploaded_on"]) end if jsonObject.has_key?("file_size") version.setFileSize(jsonObject["file_size"]) end if jsonObject.has_key?("uploaded_date") version.setUploadedDate(jsonObject["uploaded_date"]) end if jsonObject.has_key?("uploaded_date_format") version.setUploadedDateFormat(jsonObject["uploaded_date_format"]) end if jsonObject.has_key?("uploaded_date_long") version.setUploadedDateLong(jsonObject["uploaded_date_long"]) end return version end |