Skip to content

Instantly share code, notes, and snippets.

@ElliotSanchez
Forked from bryanmytko/request-responses.md
Last active February 18, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElliotSanchez/e07529005ed9d7d7b8c2bdd9323f7488 to your computer and use it in GitHub Desktop.
Save ElliotSanchez/e07529005ed9d7d7b8c2bdd9323f7488 to your computer and use it in GitHub Desktop.
Assessment V2

GET v2/assessments/get_assessments

Returns all assessments. Currently onboarding is only version, but passing a title parameter with "onboarding" will future proof the call.

Parameters:

To get the onboarding assessment use ?title=onboarding

Request Body:

None, n/a for GET request

Response:

{
    "assessments": [
        {
            "assessment": {
                "assessmentV2Id": "1bc9bbc9-1f99-4116-856e-02b6df2b0842",
                "totalScore": 100,
                "title": "onboarding",
                "pillars": [
                    {
                        "id": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
                        "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
                        "categoryId": "832729b7-af94-4bf9-b609-ef3aefd28f96",
                        "name": "green pillar",
                        "version": 0,
                        "createdAt": "2020-02-12T19:04:29.381Z",
                        "updatedAt": "2020-02-12T19:04:29.381Z",
                        "questions": [
                            {
                                "id": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                "assessmentPillarId": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
                                "label": "how much is now?",
                                "imageUrl": "c",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": [
                                    {
                                        "id": "2dc29cef-279a-40c0-b6b5-f0b131fc5c0e",
                                        "assessmentPillarQuestionId": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                        "label": "not a lot",
                                        "value": 2,
                                        "version": 0,
                                        "createdAt": "2020-02-12T19:20:05.128Z",
                                        "updatedAt": "2020-02-12T19:20:05.128Z"
                                    },
                                    {
                                        "id": "51f91533-23c3-4425-9680-8d24abe266c7",
                                        "assessmentPillarQuestionId": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                        "label": "very much",
                                        "value": 5,
                                        "version": 0,
                                        "createdAt": "2020-02-12T19:20:05.128Z",
                                        "updatedAt": "2020-02-12T19:20:05.128Z"
                                    },
                                    {
                                        "id": "58467063-072e-4b90-a004-ea22907b10d2",
                                        "assessmentPillarQuestionId": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                        "label": "middle",
                                        "value": 3,
                                        "version": 0,
                                        "createdAt": "2020-02-12T19:20:05.128Z",
                                        "updatedAt": "2020-02-12T19:20:05.128Z"
                                    },
                                    {
                                        "id": "69494d48-4ae5-422d-b473-e21dc9156e84",
                                        "assessmentPillarQuestionId": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                        "label": "none",
                                        "value": 1,
                                        "version": 0,
                                        "createdAt": "2020-02-12T19:20:05.128Z",
                                        "updatedAt": "2020-02-12T19:20:05.128Z"
                                    },
                                    {
                                        "id": "c2b365eb-10bb-43f3-b201-0dfc3136af8e",
                                        "assessmentPillarQuestionId": "0fb641db-1862-4894-9851-c790e4ff7de1",
                                        "label": "a little",
                                        "value": 4,
                                        "version": 0,
                                        "createdAt": "2020-02-12T19:20:05.128Z",
                                        "updatedAt": "2020-02-12T19:20:05.128Z"
                                    }
                                ]
                            },
                            {
                                "id": "cfad25bd-49f7-4681-9a24-f61997aeb75e",
                                "assessmentPillarId": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
                                "label": "do you like orange?",
                                "imageUrl": "b",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": []
                            },
                            {
                                "id": "f087d6d3-fddd-43e8-af42-5d004a1fce6d",
                                "assessmentPillarId": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
                                "label": "do you like apple?",
                                "imageUrl": "a",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": []
                            }
                        ]
                    },
                    {
                        "id": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
                        "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
                        "categoryId": "0d601571-7b2d-4e07-a0ee-db1545d1d143",
                        "name": "red pillar",
                        "version": 0,
                        "createdAt": "2020-02-12T19:04:29.381Z",
                        "updatedAt": "2020-02-12T19:04:29.381Z",
                        "questions": [
                            {
                                "id": "7c31224f-4ff1-4348-8fab-ba7de0ade03a",
                                "assessmentPillarId": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
                                "label": "what is this?",
                                "imageUrl": "c",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": []
                            },
                            {
                                "id": "e155bec9-377b-4736-ac52-b1b3761da5ce",
                                "assessmentPillarId": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
                                "label": "how tall are you ?",
                                "imageUrl": "b",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": []
                            },
                            {
                                "id": "f7e0b881-0fb7-4ee3-9f3e-1f9413fc4b06",
                                "assessmentPillarId": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
                                "label": "what time is it?",
                                "imageUrl": "a",
                                "version": 0,
                                "createdAt": "2020-02-12T19:08:29.312Z",
                                "updatedAt": "2020-02-12T19:08:29.312Z",
                                "answers": []
                            }
                        ]
                    },
                    {
                        "id": "7a645cd9-e47c-43a2-886e-f330572ba046",
                        "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
                        "categoryId": "cab269e6-708b-417e-87a8-3577dca801d9",
                        "name": "yellow pillar",
                        "version": 0,
                        "createdAt": "2020-02-12T19:04:29.381Z",
                        "updatedAt": "2020-02-12T19:04:29.381Z",
                        "questions": []
                    },
                    {
                        "id": "d1ff4afc-4aca-4bb4-97f5-7ba14fb57be3",
                        "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
                        "categoryId": "b4b9f647-5ed0-4166-8053-05764da4a75c",
                        "name": "blue pillar",
                        "version": 0,
                        "createdAt": "2020-02-12T19:04:29.381Z",
                        "updatedAt": "2020-02-12T19:04:29.381Z",
                        "questions": []
                    }
                ]
            }
        }
    ]
}

iOS Parsing Code:

func convertAssessmentQuestions(withResponseObject responseObject: Any?) -> [AssessmentQuestionModel]? {
        guard let dataDictionary = responseObject as? JSONDict,
            let assessmentsArray = dataDictionary["assessments"] as? [JSONDict],
            let firstAssessment = assessmentsArray.first,
            let assessmentObject = firstAssessment["assessment"] as? JSONDict,
            let pillarsObjects = assessmentObject["pillars"] as? [JSONDict] else {
                return nil
        }
        
        let questions: [AssessmentQuestionModel] = pillarsObjects.compactMap({
            // [pillar JSON] -> [[questions JSON]]
            return  $0["questions"] as? [JSONDict]
        }).reduce([JSONDict](), { prior, new in
            // [[questions JSON]] -> combined [questions JSON]
            let combined = prior + new
            return combined
        }).compactMap({
            // [questions JSON] -> [AssessmentQuestionModel]
            FancyLogger.info("Attempting decode of questionJSON: \($0)")
            return AssessmentQuestionModel.modelObject(fromJSON: $0)
        })
        
        // Alternate form without higher-order functions
//        var questionsJSON = [JSONDict]()
//        for pillar in pillarsObjects {
//            if let pillarQuestions = pillar["questions"] as? [JSONDict] {
//                questionsJSON.append(contentsOf: pillarQuestions)
//            }
//        }
//        var questions: [AssessmentQuestionModel] = [AssessmentQuestionModel]()
//        for questionJSON in questionsJSON {
//            FancyLogger.info("Attempting decode of questionJSON: \(questionJSON)")
//
//            if let question = AssessmentQuestionModel.modelObject(fromJSON: questionJSON) {
//                questions.append(question)
//            }
//        }
        
        if questions.isEmpty {
            FancyLogger.error("Onboarding assessment contained no questions")
            return nil
        } else {
            return questions
        }
    }

GET v2/assessments/get_assessment

Not used for onboarding assessment

POST v2/assessments/create_assessment_result

Parameters:

None

Request Body:

{
    "results": [
        {
            "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
            "userId": "7c887ddb-86d5-42a6-9546-4e4497ae4e84",
            "pillarResults": [
                {
                    "assessmentPillarId": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
                    "results": [
                        1,
                        2,
                        3
                    ]
                },
                {
                    "assessmentPillarId": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
                    "results": [
                        4,
                        5,
                        1
                    ]
                },
                {
                    "assessmentPillarId": "d1ff4afc-4aca-4bb4-97f5-7ba14fb57be3",
                    "results": [
                        1,
                        2,
                        1
                    ]
                },
                {
                    "assessmentPillarId": "7a645cd9-e47c-43a2-886e-f330572ba046",
                    "results": [
                        5,
                        5,
                        5
                    ]
                }
            ]
        }
    ]
}

Response:

{
    "assessmentResults": {
        "id": "c56f08f9-ec81-4e53-b43a-f5871974aee5",
        "assessmentV2Id": "65db6420-b103-4d1e-9638-4844ef9ffef7",
        "userId": "7c887ddb-86d5-42a6-9546-4e4497ae4e84",
        "score": 35,
        "totalScore": 60,
        "version": 0,
        "createdAt": "2020-02-14T22:31:23.318Z",
        "updatedAt": "2020-02-14T22:31:23.318Z"
    },
    "assessmentPillarResults": [
        {
            "name": "red pillar",
            "category": [
                {
                    "id": "0d601571-7b2d-4e07-a0ee-db1545d1d143",
                    "name": "red",
                    "created_at": "2020-02-12T13:28:31.448351-05:00",
                    "short_name": "red",
                    "updated_at": "2020-02-12T13:28:31.448351-05:00",
                    "wp_category_id": 2
                }
            ],
            "id": "92f5f16f-0bab-4577-96c4-9a13e00c748b",
            "assessmentResultId": "c56f08f9-ec81-4e53-b43a-f5871974aee5",
            "assessmentPillarId": "3bb728e9-ce1a-4b84-9e8d-4444cf7549f9",
            "score": 6,
            "totalScore": 15,
            "version": 0,
            "createdAt": "2020-02-14T22:31:23.328Z",
            "updatedAt": "2020-02-14T22:31:23.328Z"
        },
        {
            "name": "green pillar",
            "category": [
                {
                    "id": "832729b7-af94-4bf9-b609-ef3aefd28f96",
                    "name": "green",
                    "created_at": "2020-02-12T13:28:31.448351-05:00",
                    "short_name": "green",
                    "updated_at": "2020-02-12T13:28:31.448351-05:00",
                    "wp_category_id": 3
                }
            ],
            "id": "0ad77344-891b-4363-9122-845e745c424a",
            "assessmentResultId": "c56f08f9-ec81-4e53-b43a-f5871974aee5",
            "assessmentPillarId": "0474c6a4-42ad-4f90-b49e-ec914e906c67",
            "score": 10,
            "totalScore": 15,
            "version": 0,
            "createdAt": "2020-02-14T22:31:23.328Z",
            "updatedAt": "2020-02-14T22:31:23.328Z"
        },
        {
            "name": "blue pillar",
            "category": [
                {
                    "id": "b4b9f647-5ed0-4166-8053-05764da4a75c",
                    "name": "blue",
                    "created_at": "2020-02-12T13:28:31.448351-05:00",
                    "short_name": "blue",
                    "updated_at": "2020-02-12T13:28:31.448351-05:00",
                    "wp_category_id": 1
                }
            ],
            "id": "f924e490-08ae-43c8-a0aa-7a63224410c9",
            "assessmentResultId": "c56f08f9-ec81-4e53-b43a-f5871974aee5",
            "assessmentPillarId": "d1ff4afc-4aca-4bb4-97f5-7ba14fb57be3",
            "score": 4,
            "totalScore": 15,
            "version": 0,
            "createdAt": "2020-02-14T22:31:23.328Z",
            "updatedAt": "2020-02-14T22:31:23.328Z"
        },
        {
            "name": "yellow pillar",
            "category": [
                {
                    "id": "cab269e6-708b-417e-87a8-3577dca801d9",
                    "name": "yellow",
                    "created_at": "2020-02-12T13:28:31.448351-05:00",
                    "short_name": "yellow",
                    "updated_at": "2020-02-12T13:28:31.448351-05:00",
                    "wp_category_id": 4
                }
            ],
            "id": "2d9e88ca-4dbe-45d8-b5dd-00f6296a5215",
            "assessmentResultId": "c56f08f9-ec81-4e53-b43a-f5871974aee5",
            "assessmentPillarId": "7a645cd9-e47c-43a2-886e-f330572ba046",
            "score": 15,
            "totalScore": 15,
            "version": 0,
            "createdAt": "2020-02-14T22:31:23.328Z",
            "updatedAt": "2020-02-14T22:31:23.328Z"
        }
    ]
}

iOS Parsing Code:

guard let dataDictionary = responseData as? [String:Any],
                    let resultsDataArray = dataDictionary["results"] as? [Any] else {
                        return nil
                }
                
                if resultsDataArray.isEmpty {
                    return nil
                }
                
                guard let mostRecentResults = resultsDataArray.first as? [String:Any],
                    let categoryScoresData = mostRecentResults["categoryScores"] as? [[String:Any]] else {
                        return nil
                }
                
                var userJourneys = [UserJourneyScoreModel]()
                for categoryScore in categoryScoresData {
                    if let journeyDict = categoryScore["category"] as? [String:String],
                        let name = journeyDict["shortName"],
                        let shortDesc = journeyDict["name"],
                        let uuidString = journeyDict["id"],
                        let uuid = UUID(uuidString: uuidString),
                        let score = categoryScore["score"] as? Double,
                        let possible = categoryScore["totalScore"] as? Double {
                        
                        let journey = JourneyType(name: name, uuid: uuid, shortDesc: shortDesc)
                        let userJourney = UserJourneyScoreModel(journey: journey, score: (score/possible), selected: false)
                        userJourneys.append(userJourney)
                    }
                }
                
                return userJourneys

GET v2/assessments/get_assessment_result

Not used for onboarding assessment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment