Exemple #1
0
    def method_parameters(api):
        parameters = []

        # Create request object parameters
        request_object = iOSTemplateMethods.get_api_request_object(api)
        if request_object:
            parameters.extend(
                ObjCParameter.generate_field_parameters(request_object))
            parameters.extend(
                ObjCParameter.generate_relationship_parameters(request_object))

        # Add id parameter if we need it
        id_parameter = ObjCParameter.create_id_parameter(
            api.url_path, request_object)
        if id_parameter:
            parameters.append(id_parameter)

        # Add required RestKit parameters
        parameters.extend([
            ObjCParameter(
                name="success",
                objc_type=
                "void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)"
            ),
            ObjCParameter(
                name="failure",
                objc_type=
                "void (^)(RKObjectRequestOperation *operation, NSError *error)"
            )
        ])

        return ObjectiveCTemplateMethods.create_parameter_signature(parameters)
Exemple #2
0
    def test_get_objc_data_type(self):
        array_field = Field("message", ["string", "array"])
        self.assertEqual(ObjCParameter.get_objc_data_type(array_field),
                         "NSArray*")

        text_field = Field("title", ["string", "optional"])
        self.assertEqual(ObjCParameter.get_objc_data_type(text_field),
                         "NSString*")
    def test_create_objc_id_parameter(self):
        request_object = DataObject("$postRequest", {
            "title": "string"
        })
        self.assertIsNone(ObjCParameter.create_id_parameter("/post/", request_object))
        self.assertIsNotNone(ObjCParameter.create_id_parameter("/post/:id/", request_object))

        request_object = DataObject("$postUpdateRequest", {
            "id": "int,primarykey",
            "title": "string"
        })
        self.assertIsNone(ObjCParameter.create_id_parameter("/post/:id/", request_object))
Exemple #4
0
    def test_create_objc_id_parameter(self):
        request_object = DataObject("$postRequest", {"title": "string"})
        self.assertIsNone(
            ObjCParameter.create_id_parameter("/post/", request_object))
        self.assertIsNotNone(
            ObjCParameter.create_id_parameter("/post/:id/", request_object))

        request_object = DataObject("$postUpdateRequest", {
            "id": "int,primarykey",
            "title": "string"
        })
        self.assertIsNone(
            ObjCParameter.create_id_parameter("/post/:id/", request_object))
 def test_generate_objc_field_parameters(self):
     request_object = DataObject("$postUpdateRequest", {
         "id": "int,primarykey",
         "title": "string",
         "tags": "M2M,$tagRequest"
     })
     parameters = ObjCParameter.generate_field_parameters(request_object)
     self.assertEqual(parameters[0].name, "id")
     self.assertEqual(parameters[0].objc_type, "NSNumber*")
     self.assertEqual(parameters[1].name, "title")
     self.assertEqual(parameters[1].objc_type, "NSString*")
Exemple #6
0
 def test_generate_objc_field_parameters(self):
     request_object = DataObject("$postUpdateRequest", {
         "id": "int,primarykey",
         "title": "string",
         "tags": "M2M,$tagRequest"
     })
     parameters = ObjCParameter.generate_field_parameters(request_object)
     self.assertEqual(parameters[0].name, "id")
     self.assertEqual(parameters[0].objc_type, "NSNumber*")
     self.assertEqual(parameters[1].name, "title")
     self.assertEqual(parameters[1].objc_type, "NSString*")
    def method_parameters(api):
        parameters = []

        # Create request object parameters
        request_object = iOSTemplateMethods.get_api_request_object(api)
        if request_object:
            parameters.extend(ObjCParameter.generate_field_parameters(request_object))
            parameters.extend(ObjCParameter.generate_relationship_parameters(request_object))

        # Add id parameter if we need it
        id_parameter = ObjCParameter.create_id_parameter(api.url_path, request_object)
        if id_parameter:
            parameters.append(id_parameter)

        # Add required RestKit parameters
        parameters.extend([
            ObjCParameter(name="success",
                          objc_type="void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)"),
            ObjCParameter(name="failure",
                          objc_type="void (^)(RKObjectRequestOperation *operation, NSError *error)")
        ])

        return ObjectiveCTemplateMethods.create_parameter_signature(parameters)
 def test_generate_objc_relationship_parameters(self):
     schema = create_dynamic_schema({
         "$userRequest": {
             "username": "******",
             "profile": "O2O,$profileRequest",
             "tags": "M2M,$tagRequest"
         },
         "$profileRequest": {},
         "$tagRequest": {}
     }, [])
     request_object = schema.data_objects['$userRequest']
     parameters = ObjCParameter.generate_relationship_parameters(request_object)
     self.assertEqual(parameters[0].name, "profile")
     self.assertEqual(parameters[0].objc_type, "ProfileRequest")
     self.assertEqual(parameters[1].name, "tags")
     self.assertEqual(parameters[1].objc_type, "NSOrderedSet*")
Exemple #9
0
 def test_generate_objc_relationship_parameters(self):
     schema = create_dynamic_schema(
         {
             "$userRequest": {
                 "username": "******",
                 "profile": "O2O,$profileRequest",
                 "tags": "M2M,$tagRequest"
             },
             "$profileRequest": {},
             "$tagRequest": {}
         }, [])
     request_object = schema.data_objects['$userRequest']
     parameters = ObjCParameter.generate_relationship_parameters(
         request_object)
     self.assertEqual(parameters[0].name, "profile")
     self.assertEqual(parameters[0].objc_type, "ProfileRequest")
     self.assertEqual(parameters[1].name, "tags")
     self.assertEqual(parameters[1].objc_type, "NSOrderedSet*")
    def method_name(api):
        # First create camel cased name from snake case
        method_name_string = ""
        for part in re.split(r'[/_]+', api.url_path):
            if part in [":id", "theID"]:
                continue
            else:
                method_name_string += part.capitalize()

        first_parameter_name = "Success"
        request_object = iOSTemplateMethods.get_api_request_object(api)
        if request_object and len(request_object.properties()) > 0:
            first_field = request_object.properties()[0]
            first_parameter_name = get_proper_name(first_field.name, capitalize_first=True)
        elif ObjCParameter.create_id_parameter(api.url_path, request_object) is not None:
            first_parameter_name = "TheID"
        elif SwiftParameter.create_id_parameter(api.url_path, request_object) is not None:
            first_parameter_name = "TheID"

        return "{}With{}".format(method_name_string, first_parameter_name)
Exemple #11
0
    def method_name(api):
        # First create camel cased name from snake case
        method_name_string = ""
        for part in re.split(r'[/_]+', api.url_path):
            if part in [":id", "theID"]:
                continue
            else:
                method_name_string += part.capitalize()

        first_parameter_name = "Success"
        request_object = iOSTemplateMethods.get_api_request_object(api)
        if request_object and len(request_object.properties()) > 0:
            first_field = request_object.properties()[0]
            first_parameter_name = get_proper_name(first_field.name,
                                                   capitalize_first=True)
        elif ObjCParameter.create_id_parameter(api.url_path,
                                               request_object) is not None:
            first_parameter_name = "TheID"
        elif SwiftParameter.create_id_parameter(api.url_path,
                                                request_object) is not None:
            first_parameter_name = "TheID"

        return "{}With{}".format(method_name_string, first_parameter_name)
    def test_get_objc_data_type(self):
        array_field = Field("message", ["string", "array"])
        self.assertEqual(ObjCParameter.get_objc_data_type(array_field), "NSArray*")

        text_field = Field("title", ["string", "optional"])
        self.assertEqual(ObjCParameter.get_objc_data_type(text_field), "NSString*")