Class: Projects::Parser::FolderParser
- Inherits:
-
Object
- Object
- Projects::Parser::FolderParser
- Includes:
- Model
- Defined in:
- lib/projects/parser/FolderParser.rb
Overview
-
Parse the JSON response into respective objects.
Instance Method Summary collapse
-
#getFolder(response) ⇒ Object
-
Parse the JSON response and make it into Folder object.
-
-
#getFolders(response) ⇒ Object
-
Parse the JSON response and make it into List of Folder object.
-
-
#getResult(response) ⇒ Object
-
Parse the JSON response and get the success message.
-
-
#jsonToFolder(jsonObject) ⇒ Object
-
Parse the JSONObject into Folder object.
-
Instance Method Details
#getFolder(response) ⇒ Object
-
Parse the JSON response and make it into Folder object.
Parameters
- response
-
This JSON response contains the details of a folder.
-
Returns
-
Folder object.
42 43 44 45 46 |
# File 'lib/projects/parser/FolderParser.rb', line 42 def getFolder(response) folder_json = JSON.parse response folder_array = folder_json["folders"] return jsonToFolder(folder_array[0]) end |
#getFolders(response) ⇒ Object
-
Parse the JSON response and make it into List of Folder object.
Parameters
- response
-
This JSON response contains the details of folders.
-
Returns
-
List of Folder object.
22 23 24 25 26 27 28 29 30 |
# File 'lib/projects/parser/FolderParser.rb', line 22 def getFolders(response) folders_all_json = JSON.parse response folders_all_array = folders_all_json["folders"] folders_class_array = Array.new for i in 0...folders_all_array.length folders_class_array.push(jsonToFolder(folders_all_array[i])) end return folders_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.
92 93 94 95 96 |
# File 'lib/projects/parser/FolderParser.rb', line 92 def getResult(response) jsonObject = JSON.parse response result = jsonObject["response"] return result end |
#jsonToFolder(jsonObject) ⇒ Object
-
Parse the JSONObject into Folder object.
Parameters
- jsonObject
-
JSONObject contains the details of a folder.
-
Returns
-
Folder object.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/projects/parser/FolderParser.rb', line 58 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 |